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);

Tuesday, December 12, 2006

RDBMS:Tablespace Size revisited

At times, we encounter issues around tablespace size. Here are few handy queries using which we can do a first hand analysis of the tablespace size and other related information.

Sample error message related to tablespace, while uploading huge data comes as below..


ORA-01653: unable to extend table [TABLE_NAME] by 128 in tablespace [TABLESPACE_NAME]


To know the size of a tablespace.

select sum(bytes)/1024/1024 tbspace_size from dba_data_files where
tablespace_name=
'[TABLESPACE_NAME]';

To know the free space size of a tablespace.

select sum(bytes)/1024/1024 from dba_free_space where
tablespace_name=
'[TABLESPACE_NAME]';

Identify the Temp Tablespace size used for sorting,hashing etc

select decode(count(1),0,'Empty Temp Tablespace',sum(bytes)) Temp_Table_Space_Size_In_Bytes
from dba_temp_files where status =
'[TABLESPACE_NAME]';

Oracle Reports:Convert a rdf to XML for extracting information

At times, we may need to extract information from an oracle report (i.e an .rdf file). Its not easy to read the contents of the .rep and parse because of its nature of plain text.

$ORACLE_HOME/bin/rwconverter scott/tiger@sid stype=rdffile source=MYRDF.rdf dtype=xmlfile dest=MYRDF.xml batch=yes overwrite=yes

After then, either apply an XSL to the XMl to present the data in an HTML format
or parse the XML file to extract the required information and print/store.

Tuesday, December 05, 2006

RDBMS:Oracle:Know physical size of DB objects

This is the query through which we can know the physical space occupied by the DB objects in Oracle for a schema. This returns the size in MB.

select segment_name,sum(bytes)/1024/1024 "SIZE in MB"
from dba_extents
where owner = 'OWNER_NAME'
group by segment_name

UnitTesting:JTestcase and Jetif

JTestcase is an open source software which takes the Testdata in an XML format and generates the testcases automatically. It have a no of simple APIs which we need to use to extract the testdata from the XML file and use them in the Testcase file.
Once testcase gets created, then without changing the Testcase java file, we can keep adding the Testdata in the XML file. So this separates the Testdata and the Testcase java file.


Jetif is a higher level open source software which requires very little code to be written as compared to Junit and JTestcase.

Below table shows the feature difference between Jetif and JUnit + JTestCase.

Feature Jetif JUnit + JTestCase
Sepearate test code and data Supported by Handler Supported by JTestCase or other mechanism
Parameters & Return Value Supported by Handler No
Logging Yes Supported by extension
DataTypes Limited built-in supported, extendable by user Limited supported
Client/Server Testing Yes Supported by extension

Code Comparison

You can create more straightforward test code with Jetif, because the parameters and return value in test method are supported by Jetif. For example, a test method can be writtern as below with Jetif:

public boolean testSomething(float param1, String[] param2, Integer param3){
// Test something with the param1, param2, param3
return true;
}

While a test method can only be writtern as below with JUnit + JTestCase:

public void testSomething() {
// get the test cases from XML
Vector testCases = _jtestcase.getNameOfTestCases("testSomething");
// for each test case execute
With Jetif, you can define the parameters and expected return value in spec file, and then just use them as parameters and return a value what you want in test code, it's more simple and more clear than JUnit.

http://jetif.sourceforge.net/docs/comparison.html
http://jetif.sourceforge.net/