Monday, December 25, 2006

BC4J:Various ways to get DBTransactionImpl handle.

DBTransactionImpl has various advantages like proividing the preparedStatements/callableStatements etc very easily to the developers.

Here are few different ways to get the handle to the ADF BC DBTransactionImpl.Different ways suited for different types of applications.

Through ApplicationModule:
Once we get handle to the ApplicationModule(Mostly using COnfiguration), we can easily get a handle to the DBTransaction using

am.getDBTransaction();
This would be the most common way Apps developers would use.

Through Datasource:
At times, we use datasources in our applications.In that scenario, we can still take advantage to DBtransactionImpl.


// Get an initial JNDI context for locating the driver and
// database
Context ctext = new InitialContext();

// Get a DataSource object for the driver and database
// associated with a logical name
DataSource ds =
(DataSource)ctext.lookup("jdbc/logical_name_for_DB");

DBtransactionImpl txn = new DBtransactionImpl(ds);


Through java.sql.Connection:
At times, we use plain JDBC URL to get the connection objects in our applications.In that scenario, we can still take advantage to DBtransactionImpl.


// Get the JDBC connection object
Class.forName ("oracle.jdbc.driver.OracleDriver");

Connection conn =DriverManager.getConnection("jdbc:oracle:thin:@ap618sdb.us.oracle.com:20015:ssfdev","apps","apps");

DBtransactionImpl txn = new DBtransactionImpl(conn);


Through Datasource and java.sql.Connection:


// Get an initial JNDI context for locating the driver and
// database
Context ctext = new InitialContext();

// Get a DataSource object for the driver and database
// associated with a logical name
DataSource ds =
(DataSource)ctext.lookup("jdbc/logical_name_for_DB");

// Now, get the connection
Connection conn = ds.getConnection("username","password");

DBtransactionImpl txn = new DBtransactionImpl(conn);

1 comment:

Boris Malenšek said...

Is there any way to obtain DataSource from Connection?