Home » Developer & Programmer » JDeveloper, Java & XML » BC4J ApplicationModule
BC4J ApplicationModule [message #92012] Wed, 28 January 2004 00:44
Dieter Bogdoll
Messages: 1
Registered: January 2004
Junior Member
Hi,

currently I'm researching if BC4J would be a good tool for one of our customers.
One requirement they have is to access existing Oracle PLSQL-Packages.

JDeveloper creates the necessary SQLJ-Java class. Now I want to access
some of these methods from an bc4j application module. So I add wrappers for this methods
to my application module.

And here starts my problem: The constructor of the generate SQLJ Class wants
either an java.sql.Connection or a sqlj.runtime.ref.DefaultContext.

From within the application module I can retrieve the java.sql.Connection via this
code: getDBTransaction().createStatement(1).getConnection() (looks like a hack but is done
like this on some examples on the otn web site). But how long is this conenction valid.
Do I have to create for each call to the SQLJ Class a new instance for the class or can I simple store
the generate SQLJ Class within my application module? Does it is affected of the release mode of
the application module (stateless, reserved, stateful)?

Here is an small example for my problem
public class PSSQLPackage
{
  // some methods
  public void test (
    String pVar[])
  throws SQLException
  {
    #sql [getConnectionContext()] { CALL COLA.COLP_GLOBAL.TEST(
      :INOUT (pVar[0])) };
  }
  // some other methods
}

// first solution: doesn't create so many object instances of PSSQLPackage
// but when do I release the package
// and can I be sure that the next time I call getPackage() the connection is still safe to use?
public class MyAppModuleImplVersion1 extends ApplicationModuleImpl 
{
	private PSSQLPackage mMypackage;
	
	private synchronized PSSQLPackage getPackage() throws SQLException
	{
		if( mMypackage==null )
		{
			mMypackage = new PSSQLPackage( getDBTransaction().createStatement(1).getConnection() );
		}
	}
	
	public void test( String[] aInOutParam ) throws SQLException
	{
		getPackage().test(aInOutParam);
	}
	
	// but when do I release the package now
}

// second solution: creates for each call a new instance of PSSQLPackage
// but I can be sure, that the connection is every time valid and i do know exactly
// where I have to release the PSSQLPackage
public class MyAppModuleImplVersion2 extends ApplicationModuleImpl 
{
	private PSSQLPackage createPackage() throws SQLException
	{
		return new PSSQLPackage( getDBTransaction().createStatement(1).getConnection() );
	}
	
	public void test( String[] aInOutParam ) throws SQLException
	{
		PSSQLPackage pack = createPackage();
		try
		{
			return pack.test(aInOutParam);
		}
		finally
		{
			pack.release();
		}
	}
}

// are there any other solutions to my problem?


Thanks for reading...

Bye Dieter
Previous Topic: using xmltype with xml
Next Topic: How to pass XMLData type as parameter to Stored procedure from JAVA
Goto Forum:
  


Current Time: Thu Mar 28 17:31:36 CDT 2024