![]() |
Using Cloudscape as a J2EE Resource Manager
|
Reference Manual |
How to Use ThemGetting a DataSourceNormally, you can simply work with the interfaces for javax.sql.DataSource, javax.sql.ConnectionPoolDataSource, and javax.sql.XADataSource, as shown in the following examples. However, you do need to use the Cloudscape class COM.cloudscape.core.DataSourceFactory. import COM.cloudscape.core.DataSourceFactory; javax.sql.ConnectionPoolDataSource cpdf = DataSourceFactory.getConnectionPoolDataSource() javax.sql.DataSource ds = DataSourceFactory.getDataSource(); javax.sql.XADataSource xads = DataSourceFactory.getXADataSource(); Cloudscape provides three methods for a DataSource that are not part of the standard API. These methods are in COM.cloudscape.core.AbstractDataSource. They are:
Shutting Down or Creating a DatabaseIf you need to shut down or create a database, it is easiest just to work with the Cloudscape-specific implementations of interfaces, as shown in the following examples. javax.sql.XADataSource xads = makeXADataSource(mydb, true); // example of setting property directory using Cloudscape's // XaDataSource object import COM.cloudscape.core.DataSourceFactory; import COM.cloudscape.core.XaDataSource; import javax.sql.XADataSource; // dbname is the database name // if create is true, create the database if not already created XADataSource makeXADataSource (String dbname, boolean create) throws Throwable { XaDataSource xads = DataSourceFactory.getXADataSource(); // use Cloudscape's setDatabaseName call xads.setDatabaseName(dbname); if (create) xads.setCreateDatabase("create"); return xads; } import javax.sql.DataSource; import COM.cloudscape.core.DataSourceFactory; DataSource ds = makeCloudscapeSource(mydb); // example of using reflection to set properties // knowledge of COM.cloudcape.core.DataSourceFactory required DataSource makeCloudscapeDataSource (String dbname) throws Throwable { Class[] parameter = new Class[1]; parameter[0] = dbname.getClass(); DataSource ds = DataSourceFactory.getDataSource(); Class c1 = ds.getClass(); Method setName = c1.getMethod("setDatabaseName", parameter); Object[] arg = new Object[1]; arg[0] = dbname; setName.invoke(ds, arg); return ds; } Setting the property does not create or shut down the database. The database is not actually created or shut down until the next connection request. Remote DataSourcesRemote support is provided for DataSources and LocalConnectionPoolDataSources through RmiJdbc. To create remote RmiJdbc data sources, use the method setRemoteDataSourceProtocol on the data source before getting the connection. The string argument to the method must be either: Remote support is also provided for XaDataSources through RmiJdbc; use COM.cloudscape.core.RemoteXaDataSource instead of COM.cloudscape.core.XaDataSource. To create RemoteXaDataSources, use the method setRemoteDataSourceProtocol on it before getting the connection. The string argument to the method must be either: NEW: Support for remote XaDataSources is new in Version 3.6. |
|
![]() Cloudscape Version 3.6 For information about Cloudscape technical support, go to: www.cloudscape.com/support/.Copyright © 1998, 1999, 2000 Informix Software, Inc. All rights reserved. |