Wednesday, December 28, 2011

some syntax to create user in Oracle Database


***********************************************************************************************************************
--To find the default tablespace in DB:
SELECT PROPERTY_VALUE FROM DATABASE_PROPERTIES
WHERE PROPERTY_NAME = 'DEFAULT_PERMANENT_TABLESPACE';
-- this gives the output "USERS" in my case

--create user: here i am using user name "sdb" password "password"
CREATE USER sdb IDENTIFIED BY password
DEFAULT TABLESPACE USERS       
TEMPORARY TABLESPACE temp ;     

--Default object tablespace
-- Assign space for table and index segments
--If a user creates an object (such as a table or an index) without explicitely specifying the tablespace in which it goes, Oracle will place the object in the default object tablespace.
--Default temporary tablespace
-- Assign sort space
--If a user needs a temporary segment for an operation (such as a sort), Oracle will place the data in his default temporary tablespace.

--to give the user some space quota on its tablespaces:
ALTER USER sdb QUOTA UNLIMITED ON Users;

--grant CREATE SESSION privilege necessary to login, this is the right to connect to the database
GRANT CONNECT, RESOURCE TO sdb;
-- Make user a DB Administrator
GRANT DBA TO sdb;

-- lock a user account
ALTER USER sdb ACCOUNT LOCK   
-- unlocks a locked users account
ALTER USER sdb ACCOUNT UNLOCK;

-- Force user to choose a new password
ALTER USER sdb PASSWORD EXPIRE; 
-- choose new password
ALTER USER sdb IDENTIFIED BY password1

-- Remove user
DROP USER sdb CASCADE;

***********************************************************************************************************************

some concepts:
Users in Oracle                 
In Oracle terminology, a user is someone who can connect to a database (if granted enough privileges) and optionally (again, if granted the appropriate privileges) can own objects (such as tables) in the database.
The objects a user owns are collectively called >schema. A schema, on its part, is always bound to exactly one user. Because there is obviously a 1 to 1 relationship between a user and a schema, these two terms are often used interchangeable.
In order to find out what users are created on the database, one can use dba_users

A user's schema consists of all objects that belong to this user.

Oracle database objects                              
Oracle distinguishes between the following «object»:
    Tables
    Views
    Indexes
    Clusters
    Synonyms
    Sequences
    Procedures
    Functions
    Packages
    Triggers
    ...

All objects that belong to the same user are said to be this user's schema.

***********************************************************************************************************************

find commands in Linux


Find  a Word for a particular word in files present in multiple subdirectories
find . -type f -exec grep "dvc88601" {} \; -print

find ./ -type f -exec grep -i -H 'aaa' {} \;

if there is a escape character like “-” then use “\” for example for finding “–aaa”
find ./* -exec grep -i -H '\-aaa' {} \;

finding the occurrence in a particular format of a file: for example here we are finding it only in “.txt” files
find ./ -iname \*.txt\* -exec grep -i -H 'bbb' {} \;

Find and Replace:
this is meeting the requirement for me :
$ perl -e "s/pepsi/coke/g;" -pi $(find /home/oracle/vishal/test -type f)
syntax:
$ perl -e "s/FIND/REPLACE/g;" -pi $(find path/to/DIRECTORY -type f)

Ex:
findreplaceExurl.sh
perl -e "s/Vivek/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Pratheep/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Prateek/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Tom/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Jimmy/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Ramanujam/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Naveen/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Jophy/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)
perl -e "s/Krishna/vishal/g;" -pi $(find /home/oracle/vishal/test -type f)


Find and Replace:
find ./ -type f -exec sed -i ’s/string1/string2/’ {} \;

Find and Delete:
find ./* -type f -exec sed -i 's/index.html//g' {} \;

Find a file
========
The Linux 'find' command will list files and directories that match the arguments to the command and pass specified tests. For example, to find all 'txt' files in the home directory, the following command can be used:

find ~ -name *.txt

The '~' means start at the user's home directory and the -name is a test which means list only files with that particular name. Find has many tests but some of the most useful for finding files that have been updated recently are the -mtime and -mmin tests.


Find All Files Modified in the Last 90 Minutes
==================================

find . -mmin -90

It looks as if the 'find' command has listed files and directories. If we only want to see the files, add the -type test to the command to specify files only.

find . -type f -mmin -90

The sample output would then become

       
                /home/linux/dns/mysql-outfile/dnsx.txt
                /home/linux/dns/mysql-outfile/dnsx.doc
       
      
Adding Xargs to Find
=============================
Xargs' power lies in the fact that it can take the output of one command, in this case find, and use that output as arguments to another command. So, using the basic find command above, let us pass the output of find to xargs and get xargs to issue multiple 'ls -l' commands.

find ~ -type f -mmin -90 | xargs ls -l

The sample output would then become

       
                -rw-rw-r--    1 linux    lunux    10209032 Jun 30 13:28 /home/linux/dns/mysql-outfile/dnsx.doc
                -rw-rw-rw-    1 mysql    mysql    10209032 Jun 30 12:53 /home/linux/dns/mysql-outfile/dnsx.txt
       
      
Find All Files Modified More Than 5 Years Ago
=====================================
In this example of the find and xargs command, we will use a positive time and the mtime test. The operand value to mtime is the number of 24 hour periods. It is not the number of days and the reason why will become apparent if you read 'man find'. So, to see files over 5 years old will will use +1825 as the value for mtime. We have ignored leap years in calculating 5 years as 5*365 days. The command issued is

find ~ -type f -mtime +1825 |xargs ls -l

Tell xargs when to Quit
==================
One problem with the above approach is that a complete listing of the current directory will occur if the find command does not find any files! Xargs sees a list of zero files, but still issues the 'ls -l' command. To overcome this, simply use the xargs option '-r' which means "If the standard input does not contain any nonblanks, do not run the command." So, our command now becomes:

find ~ -type f -mtime +1825 |xargs -r ls -l

Note that the '-r' is an xargs option and therefore comes after the xargs command name but before the command to be issued - in this case 'ls -l'.

Friday, July 1, 2011

Error message in ESB Console and nothing appears in Tracking tab

Sometimes we face very strange issue in ESB console. Nothing appears in the tracking tab of the ESB Console and the error message comes as:

Unable to build the instance relationship, as the required metadata is not available.

First check the size of the log files. sometimes if the log size is very large then the server doesnt behave as expected.
go to  <oracleHome>/opmn/logs/
type ls -lh to find the size of the log files.
If the size of the log file is very big then we need to empty the file.
first stop the server (go to /opmn/bin/  then type ./opmnctl shutdown)
take the backup of the log file.
cp SOA_GROUP~oc4j_soa~SOA_GROUP~1.log backup_SOA_GROUP~oc4j_soa~SOA_GROUP~1.log
empty the log file.
cp /dev/null SOA_GROUP~oc4j_soa~SOA_GROUP~1.log

Then start the server (go to /opmn/bin/  then type ./opmnctl startall)

This is how my issue got resolved. Not sure if reducing the size realy helped or bouncing the server.
If anyone has a bettor solution then please share.

Configuring Database Adaptor

Configuring Database Adaptor in Application server

Creating Connection Pool


Login to em console ->cluster toplogy->oc4j_soa->Administration->JDBC Resources
connection pools->
create Name - filedbconn
Connection Factory Class oracle.jdbc.pool.OracleDataSource
URL : jdbc:oracle:thin:@//localhost:1521/xe
Username : system
Password : oracle

Creating Datasource connections

login in to em console ->cluster toplogy->oc4j_soa->Administration->JDBC Resources
Datasources->create ->select Manage Datasource -> continue

Application Name : default
JNDI Location : jdbc/localdbtest
Type : Manage Datasource
Connection Pool : filedbconn(select existing connection pool name)
Transaction Level : Global & Local Transactions
Name : LocalDBDatasource

Configuring Database Adaptor

go to em console ->cluster toplogy->oc4j_soa->Applications->default ->DBAdaptor
Connection Factory Interface - javax.resource.cci.ConnectionFactory
JNDI Location - eis/apps/LocalDatabase
xADataSourceName - jdbc/localdbtest (is the name of JNDI Location in Datasource)

Wednesday, June 22, 2011

Erroor : "Could not create the Java virtual machine" in Jdeveloper 11g

While starting Integrated Weblogic Server of Jdeveloper 11g sometimes we get Error message as:

Could not reserve enough space for object heapCould not create the Java virtual machine.

To solve this issue we need to add one environment varible.

Right click on My Computer, go to properties->Advanced->Environment Variables.
In user Variables add a New variables with below details:
Variable name: EXTRA_JAVA_PROPERTIES
Variable Valute: -Xms256m -Xmx256m

Now try starting the Integrated weblogic server.
In my case it worked fine after addig Environment variable.

Monday, April 18, 2011

Steps to deploy ADF 11g Application with ADF security enabled on weblogic server

In this post i will explain to deploy a secured ADF Application on weblogic server.
Here one thing to note is that i am using Jdeveloper11.1.1.4 so our task has become very easy.
till Jdeveloper11.1.1.2 we needed to migrate ADF security policies manually to weblogic server, but from Jdeveloper11.1.1.3 the policies gets migrated to weblogic server at the time of deployment.

I have created a simple login page and enabled ADF security.
I have created a user as ADF/adfcoder1
an Application role as developer
an an Enterprise role as employee
and associated the user and application role to the enterprise role we created as shown in the below screenshots:














Now we will deploy this application as an .ear file to the weblogic server.
Go to Applicatio -> Application Properties -> Deployment

make sure that the check box Auto Generate and Synchronize weblogic-jdbc.xml Descriptors during Deloyment is unchecked. And next three checkbox are selected.

Now go to Application -> Deploy -> LoginProject_application1(name of your application)

This will generate an EAR file in the back end folder structure inside deploy folder of the Application as shown below:


We will deploy this ear file in weblogic server through em console. we can also use Admin console to deploy applications.

click on Weblogic_Domain dropdown of your domain and go to Application Deployment -> Deploy

browse to the ear file which is present in deploy folder of your project.

click Next.
select the target server in which you want to deploy your application.

click Next.
set the Appplication Name and Context Root as per your convenience. Context Root will appear in the URL of the deployed project.


Now click next and click on "Configure Application Security"

select Append for both Application polict migration and Application credential migration.

click on Apply and then Deploy.

Here we have deployed the application on the weblogic server.

But we need to create user in the Application server.
go to Admin console: http://localhost:7001/console
Then go to Security Realms which is present in Domain Structure and click on myrealm.
click on Users And Groups tab and then Groups.


create a new group and give it the same name as the Enterprise role of your application.
In my case it is employee.


now go to users tab and create a user and give it the same name as there in ADF application.
in my case it is ADF.
Now click on the user you have just created and go to Groups for that user and shuttle the group associated with this user(employee) to the right side as shown in the below screenshot:


click on save.
So we have created a user and associated this user to a group which is same as a user and Enterprise role of our project.
Now go back of the em console. click on the application you have just deployed.
click on the Application Deployment dropdown and go to Security -> Application Role

double click on the Role name green button. this will list the Application role and Enterprise role of your project.


we will add the user we created in Admin console of weblogic server to this application.
click on the role name, then click on Add user. select the user we created in Admin console and move it to the selected area. click ok.


Now we are ready to run the application.
click on the application present in Application deployments. click on the test point link present inside Entry points-> web module.
A new window will open, in the url append /faces/(name of the page of your application)
In my case it is:
http://localhost:7001/Login/faces/LoginPage.jspx
enter the credentials, Login will be successful and it will lead you to the next page.



Thursday, April 14, 2011

Connection name xyz is not defined

some times the error comes as:

The description of the error in log appears something like:


<LifecycleImpl> <_handleException> ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase RENDER_RESPONSE 6
oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.ConfigException, msg=JBO-33003: Connection name 11g is not defined.
    at oracle.jbo.common.ampool.PoolMgr.findPool(PoolMgr.java:529)
    at oracle.adf.model.bc4j.DCJboDataControl.findApplicationPool(DCJboDataControl.java:565)
    at oracle.adf.model.bc4j.DCJboDataControl.initializeSessionCookie(DCJboDataControl.java:389)
    at oracle.adf.model.bc4j.DCJboDataControl.initializeJboSession(DCJboDataControl.java:303)
    at oracle.adf.model.bc4j.DataControlFactoryImpl.createSessionInternal(DataControlFactoryImpl.java:199)
    at oracle.adf.model.bc4j.DataControlFactoryImpl.createSession(DataControlFactoryImpl.java:123)
    at oracle.adf.model.binding.DCDataControlReference.getDataControl(DCDataControlReference.java:167)
    at oracle.adf.model.BindingContext.instantiateDataControl(BindingContext.java:1024)


This error generally comes while migrating the code from one environment to the other.
especially when you have changed the database connection and then trying to deploy.
I have produced this error by developing the code with database connection name "11g" and then changing the database connection and giving some other connection name say "abc".

To solve this issue right click on Application Module and go to configuration...





here you can see that though we have changed the database connection from "11g" to "abc", but here it is still showing 11g details.



click on the Edit button and then press OK.
you will notice that now the connection details has been changed to "abc" which is the desired one.



Now run your Application.
It should give the desired output. :)














Thursday, March 10, 2011

How to solve "Port Conflict Detected"

Sometimes while starting Integrated weblogic Server from Jdeveloper11g we encounter the error as :



One solution for this issue is to log out from the system and login again, which i have seen many developer follow.

To solve this issue go to Task manager and locate all Java related instances.
In my case when i earlier closed Jdeveloper without stopping Weblogic server, this Java.exe kept on running.
so this is creating conflict while again starting the weblogic server.
select Java.exe and end the process.



Now start the Integrated Weblogic Server as:



It will start successfully.






I have reproduced this error by directly colsing Jdeveloper without stopping Integrated Weblogic Console:






BEA WebLogic 7 Server Administration









Sunday, March 6, 2011

Steps to create Login Page in ADF11g

I was following Andrejus's blog to create a login page in ADF 11g. and i successfully created it in Jdev11.1.1.3.
but the issue came when i tried to create the Login Page in Jdev11.1.1.4.
In this blog i will explain the issue i faced while creating Login page in Jdev11.1.1.4 and how to solve that issue.

when we will follow the steps of Jdev11.1.1.3 then on running the Application the login.jspx page will never come up and there will be no error on the Log files. we will end up with a screen like:



Though everything seems to be fine and same as that of Jdev11.1.1.3 there is one improvement made in Jdev11.1.1.4.
As explained in Andrejus's blog that in Jdev11.1.1.3 we need to explicitly grant anonymous-role permission to the login page.
In Jdev11.1.1.4 whenever a login page is created it is automatically granted the anonymous-role permission.
so when we open the jazan-data.xml and go to Resource Grants tab we will see that it is automatically  granted

but actually when we open the jadan-data.xml file and click on the "+" sign on Granted To Role column for login page we will see that we are still getting anonymous-role option

so in the jazan-data.xml it is appearing that it already has public permission but for Add Grantee it is still giving option to add anonymous-role.
so this was causing the problem.
for me it seems as in Jdev11.1.1.3 Login page was not public by default, so in Jdev11.1.1.1.4 it has been made public by default. but in the backend it is still not updated for our application.

so to solve this issue after configuring the ADF Security go to the source of jazan-data.xml and delete all the code from there.
come back to the overview tab of jadan-data.xml.
now you will see that the automatic grant to anonymous-role for Login page has dissapered and on clicking the "+" sign we are getting only 1 option of anonymous-role.

Now follow the same steps to add Application roles and grant Resources.
now when you will run the code you will get the Login screen.:)











Thursday, February 10, 2011

Displaying different Images in ADF table based on some condition Part-II

In my last blog Displaying different Images in ADF table based on some condition Part-I  I have explained how to use Switcher component to select some conditions.
af:Switcher component is very useful for conditional operations.
One example where Switcher component can be used is :
Suppose in the below table we want to add one column in the starting with checkbox in it. Now we want this checkbox to visible only when there is any Error or  when Status is "E". In this case we can use Switcher component in the same way as explained in my last blog and just keep Rendered = true for Error(initially set Rendered = false). I quoted the  above scenario because i personally like using af:Switcher component in different scenario.


I was wondering if we can achieve displaying Images in ADF tables based on some condition, with lesser effort and without using af:Switcher component and i found a very interesting trick.

we are getting "S" or "E" in the statrus column. so what i will do, i will rename the two images success.gif and failure .gif to S.gif and E.gif respectively.

Now in place of using af:Switcher component we will directly use af:image component.
but the trick lies in selecting the image based on its name.
In #{row.StatusFlag} we will get "S" or "E" as values. so in image source in place of directly writing the name of the image we will write the value of StatusFlag and append.gif. so now the image will be decided at runtime based on the value of the StatusFlag.
Below is the source code of the column:


<af:column sortProperty="StatusFlag" sortable="true"
                   headerText="#{bindings.SerachResultVO1.hints.StatusFlag.label}"
                   id="c2" align="center" width="100">
                   <af:image source="/images/#{row.StatusFlag}.gif" id="i1"/>
</af:column>

we will get the same result as we got in our earlier example:


Oracle JDeveloper 11g Handbook: A Guide to Fusion Web Development (Osborne ORACLE Press Series)





Wednesday, February 9, 2011

Displaying different Images in ADF table based on some condition Part-I

If we want to display different image inside table then we can achieve that using af:switcher component.

Suppose we have a table in which we have a column as Status.
Let's say this table is the result table of any search Query.
After the search, in the Status column the values gets populated as "S" or "E".
S represents Success and E represents Error.
Below is the result table with the column Status having values "S" and "E":

We want to replace this "S" by a success logo and "E" by an error logo.
the final screen will look like this:


If we look into the code of the Status Column, it looks like this:

<af:column sortProperty="StatusFlag" sortable="true"
headerText="#{bindings.SerachResultVO1.hints.StatusFlag.label}"
id="c2">
<af:outputText value="#{row.StatusFlag}" id="ot8"/>
</af:column>

We need to use af:switcher to test the condition. so I have added Switcher and assigned  the value of StatusFlag into facetName. The switcher will render the facet matching "facetName".

<af:column sortProperty="StatusFlag" sortable="true"
headerText="#{bindings.SerachResultVO1.hints.StatusFlag.label}"
id="c2">
<af:switcher id="s11" facetName="#{row.StatusFlag}">
<f:facet name="S">
<af:image source="/images/success.gif" id="i1"/>
</f:facet>
<f:facet name="E">
<af:image source="/images/failure.gif" id="i2"/>
</f:facet>
</af:switcher>
</af:column>

Now when we run the code, images appears on the screen in place of S and E. :)

I would like to tell something about Tag af:switcher
The switcher component dynamically decides which facet component should be rendered. It has two properties. The switcher will render the facet matching "facetName"; however, if no such facet exists (or "facetName" is null), and "defaultFacet" has been set, then that facet will be used instead. (It's possible to achieve this same functionality by using a panelGroup and binding the "rendered" property of each child, but this component can be simpler. Ordinary children of the switcher component are not rendered at all.)
The switcher is a purely logical server-side component. It does not generate any content itself and has no client-side representation (no client component). Hence switching which facet of the switcher renders requires a server round-trip.