Class Hierarchy Previous Next Index
java.lang.Object | +----COM.cloudscape.core.AbstractDataSource
This is the base abstract class extended by all DataSources.
A DataSource object is a factory for Connection objects. An object that implements the DataSource interface will typically be registered with a JNDI service provider. A JDBC driver that is accessed via the DataSource API does not automatically register itself with the DriverManager.
This object has 2 purposes:
The following is a list of properties that can be set on a cloudscape DataSource object:
Examples.
This is an example of setting a property directly using cloudscape DataSource object. This code is typically written by a system integrator :
import COM.cloudscape.core.*; // dbname is the database name // if create is true, create the database if necessary javax.sql.DataSource makeDataSource (String dbname, boolean create) throws Throwable { BasicDataSource ds = DataSourceFactory.getDataSource(); ds.setDatabaseName(dbname); if (create) ds.setCreateDatabase("create"); return ds; }
Example of using a DataSource object to connect to a remote machine named alpha, at port number 1099. This code is typically written by a system integrator :
import COM.cloudscape.core.*; javax.sql.DataSource makeRemoteDataSource (String dbname, String machine, int port) throws Throwable { BasicDataSource ds = DataSourceFactory.getDataSource(); ds.setDatabaseName(dbname); ds.setRemoteDataSourceProtocol("rmi://alpha:1099/"); return ds; }
Example of setting properties thru reflection. This code is typically generated by tools or written by a system integrator:
javax.sql.DataSource makeCloudscapeDataSource(String dbname) throws Throwable { Class[] parameter = new Class[1]; parameter[0] = dbname.getClass(); DataSource ds = DataSourceFactory.getDataSource(); Class cl = ds.getClass(); Method setName = cl.getMethod("setDatabaseName", parameter); Object[] arg = new Object[1]; arg[0] = dbname; setName.invoke(ds, arg); return ds; }
Example on how to register a data source object with a JNDI naming service.
DataSource ds = makeCloudscapeDataSource("mydb"); Context ctx = new InitialContext(); ctx.bind("jdbc/MyDB", ds);
Example on how to retrieve a data source object from a JNDI naming service.
Context ctx = new InitialContext(); DataSoruce ds = (DataSource)ctx.lookup("jdbc/MyDB");
Attempt to establish a database connection.
Attempt to establish a database connection.
Get the log writer for this data source.
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
Set the log writer for this data source.
protected static transient java.sql.Driver driver
public javax.naming.Reference getReference() throws javax.naming.NamingException
public boolean equals(java.lang.Object p0)
public void setDatabaseName(java.lang.String dbname)
dbname
- the name of the database
public java.lang.String getDatabaseName()
public void setDataSourceName(java.lang.String dsn)
dsn
- the name of the data source
public java.lang.String getDataSourceName()
public void setDescription(java.lang.String desc)
desc
- the description of the data source
public java.lang.String getDescription()
public void setCreateDatabase(java.lang.String create)
create
- if set to the string "create", this data source will try
to create a new database of databaseName, or boot the database if one
by that name already exists.
public java.lang.String getCreateDatabase()
public void setShutdownDatabase(java.lang.String shutdown)
shutdown
- if set to the string "shutdown", this data source will
shutdown the database if it is running.
public java.lang.String getShutdownDatabase()
public void setCloudscapeProperties(java.lang.String prop)
prop
- set to the list of cloudcape connection
attributes separated by semi-colons. E.g., to specify an encryption
bootPassword of "cloudscape", and set upgrade to true, do the following:
ds.setCloudscapeProperties("bootPassword=cloudscape;upgrade=true");See cloudscape documentation for complete list.
public java.lang.String getCloudscapeProperties()
public void setRemoteDataSourceProtocol(java.lang.String protocol)
protocol
- Remote access protocol, rmi is the only protocol
currently supported. The protocol string is of the form
"rmi[://rmiHostname:port/]".
// to connect to database on the same machine using rmi (for security // reasons maybe) datasource.setRemoteDataSourceProtocol("rmi");// to connect to database on another machine xyz using cloudscape // default port number 1099 datasource.setRemoteDataSourceProtocol("rmi://xyz:1099/");
public java.lang.String getRemoteDataSourceProtocol()
public int getLoginTimeout() throws java.sql.SQLException
public void setLoginTimeout(int seconds) throws java.sql.SQLException
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a data source object is created, the login timeout is initially zero.
seconds
- the data source login time limit
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
Get the log writer for this data source.
The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a data source object is created the log writer is initially null, in other words, logging is disabled.
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
Set the log writer for this data source.
The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a data source object is created the log writer is initially null, in other words, logging is disabled.
out
- the new log writer; to disable, set to null
public java.sql.Connection getDatabaseConnection() throws java.sql.SQLException
Attempt to establish a database connection.
public java.sql.Connection getDatabaseConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
Attempt to establish a database connection.
user
- the database user on whose behalf the Connection is
being made
password
- the user's password
public void populateInfo(java.util.Properties info)
public void setDatabaseProperties(java.util.Properties info)
protected void findDriver(java.lang.String url) throws java.sql.SQLException
public java.lang.String makeURL()
Class Hierarchy Previous Next Index