Database Connections in JDeveloper 11
JDeveloper 11 Technology Preview (build 4524) introduces a new way
to create and manage database connections. Database connections can
be defined for an application (called an Application Resource connection),
or ala 10.1.3.x, for the IDE as a whole (called a Resource Palette /
Database Navigator connection). When you create objects based on an
underlying database connection, such as JPA entities or ADF Business
Components, the wizard for those objects will prompt you to specify
the database connection:
You can choose to create/use an application connection by selecting
Application Resources, or create a globally defined connection by selecting
Resource Palette/Database Navigator. In the case where you are using
multiple connections for multiple applications (for example, switching
between development, testing, and/or production database schemas), you
could create global resources for these database connection details
in the resource palette or database navigator, and choose the appropriate
connection as you are creating new objects. If you do not already have
these global connections created, you can create a 'locally-scoped'
or application, connnection.
Defining connections in JDeveloper 11 Technology Preview
Defining database connections for an application
When you create objects based on an underlying database schema, and
you choose to use or create an Application Resource connection, the
connection information is stored within the application itself. You
can find the connections listed in the Application Resources accordion
under the Connections folder. Also, connection information is represented
in the <workspace
folder>.adf\META-INF\connections.xml file (this location
is created for design time use, even if you are not taking advantage
of any part of the ADF framework).
Example connections.xml:
<References
xmlns="http://xmlns.oracle.com/adf/jndi">
<Reference name="HRConn" className="oracle.jdeveloper.db.adapter.DatabaseProvider"
credentialStoreKey="HRConn" xmlns="">
<Factory className="oracle.jdeveloper.db.adapter.DatabaseProviderFactory"/>
<RefAddresses>
<StringRefAddr addrType="sid">
<Contents>ORCL</Contents>
</StringRefAddr>
<StringRefAddr addrType="subtype">
<Contents>oraJDBC</Contents>
</StringRefAddr>
<StringRefAddr addrType="user">
<Contents>hr</Contents>
</StringRefAddr>
<StringRefAddr addrType="port">
<Contents>1521</Contents>
</StringRefAddr>
<StringRefAddr addrType="hostname">
<Contents>localhost</Contents>
</StringRefAddr>
<SecureRefAddr addrType="password"/>
<StringRefAddr addrType="DeployPassword">
<Contents>false</Contents>
</StringRefAddr>
<StringRefAddr addrType="oraDriverType">
<Contents>thin</Contents>
</StringRefAddr>
</RefAddresses>
</Reference>
</References> |
This file is used internally by JDeveloper, and a technology-appropriate
connection descriptor is created when running or deploying an application
(see the last section of this document for further information).
Defining database connections for the IDE
To define database connections for the IDE, perform one of the following:
- Choose View | Database Navigator from the main menu, then right-click
Connections and choose New Connection
- Choose View | Resource Palette, then select the New folder icon
and choose New Connection > Database
Either method will create database connection information in: <JDEV_HOME>\system11.1.1.0.18.45.24\o.jdevimpl.rescat2\connections\connections.xml.
You can copy this database connection to an application in order
to use it within an application (and effectively copy the connection
to a new application resource connection) in the following ways:
Using IDE connections for JPA entities:
- To create new JPA entities that utilize an IDE connection, choose
Resource Palette / Database Navigator on the database connection
dialog of the JPA wizard, and use the dropdown list to specify
the connection defined in the Resource Palette:

- To change the database connection used for existing JPA entities
to an IDE connection, ensure the application is open in the Applications
Navigator. Then right click the connection in the Resource Palette
and choose Add to Application:

Additionally, you can copy offline database objects from a global
connection to an existing project. Right click the connection in
the Database Navigator and choose Copy to Project. Complete the
wizard to choose the database objects to create, alter, or replace
as offline database objects in an application's project.
Using IDE connections for ADF Business Components:
- To create new ADF Business Components that utilize an IDE connection,
ensure the application is open in the Applications Navigator.
Then right click the connection in the Resource Palette and choose
Add to Application:

This step ensures that when you create new ADF Business Components,
the Initialize Business Components dialog will display a dropdown
list of IDE connections.
- To change the database connection used for existing ADF Business
Components to an IDE connection, follow step 1 above to add the
connection to the application. Then double click the business
components project to open project properties, and in the Business
Components node, select the connection name from the dropdown
list:

Because the act of specifying an IDE connection for a given project
implicitly copies the connection to an Application Resource connection,
you can also view and edit the properties of these connections in
the Application Resources accordion of the Application Navigator,
under the Connections folder.
Deploying database connections
What happens with database connections when you right click and
choose Run to run an application
When you run an application in JDeveloper, you are implicitly deploying
that application to the embedded OC4J server that is included within
JDeveloper. If you have defined a database connection at the application
scope, an <Application_Name>-data-sources.xml
is created and re-generated each time you run the application. This
file is used to define the connection details for deployment, and
the specific data source that's used for the application is defined
in <Application_Name>-oc4j-app.xml.
Example <Application_Name>-data-sources.xml:
<?xml version
= '1.0' encoding = 'windows-1252'?>
<data-sources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/data-sources-10_1.xsd"
xmlns="http://xmlns.oracle.com/oracleas/schema">
<connection-pool name="jdev-connection-pool-HRConn">
<connection-factory factory-class="oracle.jdbc.pool.OracleDataSource"
user="hr" password="->DataBase_User_Oo4CLye38oc_3qJKEs1qNFF0wXyqOyHQ"
url="jdbc:oracle:thin:@localhost:1521:ORCL"/>
</connection-pool>
<managed-data-source name="jdev-connection-managed-HRConn"
jndi-name="jdbc/HRConnDS" connection-pool-name="jdev-connection-pool-HRConn"/>
<native-data-source name="jdev-connection-native-HRConn"
jndi-name="jdbc/HRConnCoreDS" user="hr" password="->DataBase_User_Nl95lRrx8WMZuCtOyMTQoS5PzeF1-qNj"
data-source-class="oracle.jdbc.pool.OracleDataSource"
url="jdbc:oracle:thin:@localhost:1521:ORCL"/>
</data-sources> |
Example <Application_Name>-oc4j-app.xml:
<?xml version
= '1.0' encoding = 'windows-1252'?>
<orion-application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-application-10_0.xsd"
default-data-source="jdbc/HRConnDS">
...
<data-sources path="<Application_Name>-data-sources.xml"/>
</orion-application>
|
What happens with database connections when you create deployment
profiles
When you create a deployment profile in JDeveloper, the generated
profiles will include the database connection descriptors by default.
When deploying a application's deployment profile, the database connections
are handled automatically. Specifically, if connections are defined
for the application, but a data-sources.xml has not been created,
the data-sources.xml will be generated and include only the application
resource connections.
Editing embedded OC4J data sources
The embedded OC4J server maintains global connections for the server,
located in <JDEV_HOME>\system11.1.1.0.xx.xx.xx\o.j2ee\embedded-oc4j\config\data-sources.xml.
You typically will not need to modify this file, as application data-sources
are used when running an application in the embedded OC4J server.
However, if you want to customize how the IDE connections are added
to the embedded OC4J server, choose Tools | Embedded OC4J Server Preferences
from the main menu. In the Data Sources node, specify whether IDE
connections should be added and/or updated to the embedded OC4J server's
connections.
Additionally, you can synchronize and/or add data sources for an
application deployed to the embedded OC4J server. Choose Tools | Embedded
OC4J Server Preferences from the main menu. Expand Current Workspace
and in the Data Sources node, specify how connections should be synchronized
and/or add a new data source for the application.
Final Thoughts
JDeveloper 11g Technology Preview and the Embedded OC4J server keep
track of connections that you define for applications. IDE-level connections
(also known as Resource Connections) are helpful for maintaining various
connections in JDeveloper, and are easily copied to applications. In
almost all cases, you will not have to manually modify the .xml files
referred to in this document. The locations and names of database descriptor
files are provided for reference and understanding only.
Additional References:
JDeveloper
11g Technology Preview Release Notes
|