Starting Shark

Shark can be started from a client application by configuring it first (which can be done in several different manners), and then by getting an instance of it. This is the most common way to use shark from an application:

String confFilePath="c:/Shark.conf";
Shark.configure(confFilePath);
Shark shark=Shark.getInstance();

Everything else can be done through the Shark interface.

Before configuring shark, it must be ensured there is a Data source and TransactionManager accessible to Shark through JNDI.

Shark 2.0 is JTA oriented, and thus when shark works outside container which provides JTA TransactionManager, we have to start one by our own. Also, in shark 2.0 for defining database we work with, we use DataSource which should be registered in JNDI, and thus when working outside container we also need to take care about registering data source in JNDI. For the purpose of stand-alone shark usage we made LocalContextFactory which is implementation of InitialContextFactory interface, and which purpose is to: 1. start TransactionManager 2. provide a JNDI context - register TransactionManager in JNDI context (so we can afterwards obtain TransactionManager and UserTransaction from JNDI) - register DataSource in JNDI context So, when using shark outside container before configuring it with Shark.conf, you need to execute the following command:

LocalContextFactory.setup("sharkdb");

where there must be "sharkdb.properties" file in the class path, and this file should hold your datasource definition, i.e. something like:

jdbc.wrapper=org.enhydra.jdbc.standard.StandardXADataSource
jdbc.minconpool=12
jdbc.maxconpool=180
jdbc.connmaxage=30
jdbc.connchecklevel=1
datasource.description=Shark WfEngine DataSource
jdbc.connteststmt=SELECT 1
datasource.name=sharkdb

datasource.classname=org.hsqldb.jdbcDriver
datasource.url=jdbc:hsqldb:C:/sasaboy/prozonecvs/Shark/output/tws/db/hsql/hsql
datasource.username=sa
datasource.password=

datasource.isolationlevel=0

In the example above, you can see that datasource name is "sharkdb", so on the other side, shark must get the information for DODS how to search the datasource in JNDI, and there is a DODS property for this purpose that is called:

DatabaseManager.DB.sharkdb.Connection.DataSourceName and the default value for this property is

"jndi:java:comp/datasource/sharkdb" This value is appropriate for DODS to search for data source which name is "sharkdb" when we use LocalContextFactory, so we do not need to re-define it in Shark.conf in this case. During shark execution, both Shark kernel and DODS need access to TransactionManager which they are looking for through JNDI. There are also two default properties for Shark kernel and for DODS which are defining the lookup names for TransactionManager, and the default values are set to be adequate for Shark usage in a stand-alone application using LocalContextFactory. These properties are respectively:

SharkTxSynchronizationFactory.XATransactionManagerLookupName

and

DatabaseManager.defaults.XATransactionManagerLookupName and they both have the same default value:

javax.transaction.TransactionManager (NOTE: when we use Shark in some container like Tomcat or JBoss, we need to change the properties mentioned above according to container specification). Finally, the client application must know how to obtain UserTransaction from JNDI so it can perform begin/commit/rollback of the transaction. When using shark outside any container and with LocalContextFactory as described above, the UserTransaction lookup name is:

java:comp/UserTransaction So, the right procedure for starting stand-alone shark application could be:

     LocalContextFactory.setup("sharkdb");
     UserTransaction ut = null;
     try {
        ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
        ut.setTransactionTimeout(15 * 60);
        ut.begin();

        String confFilePath="c:/Shark.conf";
        Shark.configure(confFilePath);
        Shark shark=Shark.getInstance();

        ut.commit();

     } catch (Throwable ex) {
         throw new Error("Something really bad happened",ex);
     }