org.apache.derby.jdbc
Class EmbeddedBaseDataSource

java.lang.Object
  extended by org.apache.derby.jdbc.EmbeddedBaseDataSource
All Implemented Interfaces:
java.io.Serializable, java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource, EmbeddedDataSourceInterface
Direct Known Subclasses:
BasicEmbeddedDataSource40, ReferenceableDataSource

public abstract class EmbeddedBaseDataSource
extends java.lang.Object
implements java.io.Serializable, EmbeddedDataSourceInterface

Derby embedded data source implementation base class.

See Also:
Serialized Form

Field Summary
protected  boolean attributesAsPassword
          Set password to be a set of connection attributes.
protected  java.lang.String connectionAttributes
          Derby specific connection attributes.
protected  java.lang.String createDatabase
          Set to "create" if the database should be created.
protected  java.lang.String databaseName
           
protected  java.lang.String dataSourceName
           
protected  java.lang.String description
           
protected  InternalDriver driver
           
protected  java.lang.String jdbcurl
           
protected  int loginTimeout
           
private  java.lang.String password
           
private  java.io.PrintWriter printer
          instance variables that will not be serialized
private static long serialVersionUID
           
private  java.lang.String shortDatabaseName
          shortDatabaseName has attributes of databaseName stripped
protected  java.lang.String shutdownDatabase
          Set to "shutdown" if the database should be shutdown.
private  java.lang.String user
           
 
Constructor Summary
EmbeddedBaseDataSource()
          No-arg constructor.
 
Method Summary
 boolean equals(java.lang.Object p0)
           
(package private)  InternalDriver findDriver()
           
 boolean getAttributesAsPassword()
          Return the value of the attributesAsPassword property, cf.
 java.sql.Connection getConnection()
          Attempt to establish a database connection.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Attempt to establish a database connection with the given username and password.
(package private)  java.sql.Connection getConnection(java.lang.String username, java.lang.String password, boolean requestPassword)
           
 java.lang.String getConnectionAttributes()
           
 java.lang.String getCreateDatabase()
           
 java.lang.String getDatabaseName()
           
 java.lang.String getDataSourceName()
           
 java.lang.String getDescription()
           
 int getLoginTimeout()
          Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Get the log writer for this data source.
 java.lang.String getPassword()
           
protected  java.lang.String getShortDatabaseName()
           
 java.lang.String getShutdownDatabase()
           
 java.lang.String getUser()
           
 boolean isWrapperFor(java.lang.Class<?> iface)
          Returns false unless interfaces is implemented.
 void setAttributesAsPassword(boolean attributesAsPassword)
          Set attributeAsPassword property to enable passing connection request attributes in the password argument of getConnection(String,String).
 void setConnectionAttributes(java.lang.String prop)
          Set this property to pass in more Derby specific connection URL attributes.
 void setCreateDatabase(java.lang.String create)
          Set this property to create a new database.
 void setDatabaseName(java.lang.String databaseName)
          Set the database name.
 void setDataSourceName(java.lang.String dsn)
          Set the data source name.
 void setDescription(java.lang.String desc)
          Set the data source descripton.
 void setLoginTimeout(int seconds)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter out)
          Set the log writer for this data source.
 void setPassword(java.lang.String password)
          Set the password property for the data source.
 void setShutdownDatabase(java.lang.String shutdown)
          Set this property if you wish to shutdown the database identified by databaseName.
protected static ResourceAdapter setupResourceAdapter(EmbeddedXADataSourceInterface ds, ResourceAdapter ra, java.lang.String user, java.lang.String password, boolean requestPassword)
           
 void setUser(java.lang.String user)
          Set the user property for the data source.
<T> T
unwrap(java.lang.Class<T> iface)
          Returns this if this class implements the specified interface.
protected  void update()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

description

protected java.lang.String description

dataSourceName

protected java.lang.String dataSourceName

databaseName

protected java.lang.String databaseName

connectionAttributes

protected java.lang.String connectionAttributes
Derby specific connection attributes.


createDatabase

protected java.lang.String createDatabase
Set to "create" if the database should be created.


shutdownDatabase

protected java.lang.String shutdownDatabase
Set to "shutdown" if the database should be shutdown.


attributesAsPassword

protected boolean attributesAsPassword
Set password to be a set of connection attributes.


shortDatabaseName

private java.lang.String shortDatabaseName
shortDatabaseName has attributes of databaseName stripped


password

private java.lang.String password

user

private java.lang.String user

loginTimeout

protected int loginTimeout

printer

private transient java.io.PrintWriter printer
instance variables that will not be serialized


jdbcurl

protected transient java.lang.String jdbcurl

driver

protected transient InternalDriver driver
Constructor Detail

EmbeddedBaseDataSource

public EmbeddedBaseDataSource()
No-arg constructor.

Method Detail

setDatabaseName

public final void setDatabaseName(java.lang.String databaseName)
Set the database name. Setting this property is mandatory. If a database named wombat at g:/db needs to be accessed, database name should be set to "g:/db/wombat". The database will be booted if it is not already running in the system.

Specified by:
setDatabaseName in interface EmbeddedDataSourceInterface
Parameters:
databaseName - the name of the database

getDatabaseName

public java.lang.String getDatabaseName()
Specified by:
getDatabaseName in interface EmbeddedDataSourceInterface
Returns:
the database name set by setDatabaseName(java.lang.String).

getShortDatabaseName

protected java.lang.String getShortDatabaseName()
Returns:
database name with ant attributes stripped off.

setDataSourceName

public final void setDataSourceName(java.lang.String dsn)
Set the data source name. The property is not mandatory. It is used for informational purposes only.

Specified by:
setDataSourceName in interface EmbeddedDataSourceInterface
Parameters:
dsn - the name of the data source

getDataSourceName

public final java.lang.String getDataSourceName()
Specified by:
getDataSourceName in interface EmbeddedDataSourceInterface
Returns:
data source name as set in setDataSourceName(java.lang.String).

setDescription

public final void setDescription(java.lang.String desc)
Set the data source descripton. This property is not mandatory. It is used for informational purposes only.

Specified by:
setDescription in interface EmbeddedDataSourceInterface
Parameters:
desc - the description of the data source

getDescription

public final java.lang.String getDescription()
Specified by:
getDescription in interface EmbeddedDataSourceInterface
Returns:
the description as set in setDescription(java.lang.String).

setUser

public final void setUser(java.lang.String user)
Set the user property for the data source.

This is user name for any data source getConnection() call that takes no arguments.

Specified by:
setUser in interface EmbeddedDataSourceInterface

getUser

public final java.lang.String getUser()
Specified by:
getUser in interface EmbeddedDataSourceInterface
Returns:
the user name as set by setUser(java.lang.String).

setPassword

public final void setPassword(java.lang.String password)
Set the password property for the data source.

This is user's password for any data source getConnection() call that takes no arguments.

Specified by:
setPassword in interface EmbeddedDataSourceInterface

getPassword

public final java.lang.String getPassword()
Specified by:
getPassword in interface EmbeddedDataSourceInterface
Returns:
the password as set in setPassword(java.lang.String).

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise it means that there is no timeout. When a data source object is created, the login timeout is initially zero. See setLoginTimeout(int).

Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Returns:
the data source login time limit
Throws:
java.sql.SQLException - if a database access error occurs.

setLoginTimeout

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.

Derby currently ignores this property.

Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Parameters:
seconds - the data source login time limit
Throws:
java.sql.SQLException - if a database access error occurs.

getLogWriter

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.

Specified by:
getLogWriter in interface javax.sql.CommonDataSource
Returns:
the log writer for this data source, null if disabled
Throws:
java.sql.SQLException - if a database-access error occurs.

setLogWriter

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.

Specified by:
setLogWriter in interface javax.sql.CommonDataSource
Parameters:
out - the new log writer; to disable, set to null
Throws:
java.sql.SQLException - if a database-access error occurs.

update

protected void update()

setCreateDatabase

public final void setCreateDatabase(java.lang.String create)
Set this property to create a new database. If this property is not set, the database (identified by databaseName) is assumed to be already existing.

Specified by:
setCreateDatabase in interface EmbeddedDataSourceInterface
Parameters:
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.

getCreateDatabase

public final java.lang.String getCreateDatabase()
Specified by:
getCreateDatabase in interface EmbeddedDataSourceInterface
Returns:
The string "create" if create is set, or null if not

findDriver

InternalDriver findDriver()
                    throws java.sql.SQLException
Throws:
java.sql.SQLException

setConnectionAttributes

public final void setConnectionAttributes(java.lang.String prop)
Set this property to pass in more Derby specific connection URL attributes.
Any attributes that can be set using a property of this DataSource implementation (e.g user, password) should not be set in connection attributes. Conflicting settings in connection attributes and properties of the DataSource will lead to unexpected behaviour.

Specified by:
setConnectionAttributes in interface EmbeddedDataSourceInterface
Parameters:
prop - set to the list of Derby connection attributes separated by semi-colons. E.g., to specify an encryption bootPassword of "x8hhk2adf", and set upgrade to true, do the following:
     ds.setConnectionAttributes("bootPassword=x8hhk2adf;upgrade=true");
 
See the Derby documentation for complete list.

getConnectionAttributes

public final java.lang.String getConnectionAttributes()
Specified by:
getConnectionAttributes in interface EmbeddedDataSourceInterface
Returns:
the Derby specific connection URL attributes, see setConnectionAttributes(java.lang.String).

setShutdownDatabase

public final void setShutdownDatabase(java.lang.String shutdown)
Set this property if you wish to shutdown the database identified by databaseName.

Specified by:
setShutdownDatabase in interface EmbeddedDataSourceInterface
Parameters:
shutdown - if set to the string "shutdown", this data source will shutdown the database if it is running.

getShutdownDatabase

public final java.lang.String getShutdownDatabase()
Specified by:
getShutdownDatabase in interface EmbeddedDataSourceInterface
Returns:
the string "shutdown" if shutdown is set, or null if not, cf. setShutdownDatabase(java.lang.String).

setAttributesAsPassword

public final void setAttributesAsPassword(boolean attributesAsPassword)
Set attributeAsPassword property to enable passing connection request attributes in the password argument of getConnection(String,String). If the property is set to true then the password argument of the getConnection(String, String) method call is taken to be a list of connection attributes with the same format as the connectionAttributes property.

Specified by:
setAttributesAsPassword in interface EmbeddedDataSourceInterface
Parameters:
attributesAsPassword - Use true to encode password argument as a set of connection attributes in a connection request.

getAttributesAsPassword

public final boolean getAttributesAsPassword()
Return the value of the attributesAsPassword property, cf. setAttributesAsPassword(boolean).

Specified by:
getAttributesAsPassword in interface EmbeddedDataSourceInterface

equals

public boolean equals(java.lang.Object p0)
Overrides:
equals in class java.lang.Object

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Attempt to establish a database connection.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
a Connection to the database
Throws:
java.sql.SQLException - if a database-access error occurs.

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Attempt to establish a database connection with the given username and password. If the attributeAsPassword property is set to true then the password argument is taken to be a list of connection attributes with the same format as the connectionAttributes property.

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
username - the database user on whose behalf the Connection is being made
password - the user's password
Returns:
a Connection to the database
Throws:
java.sql.SQLException - if a database-access error occurs.

getConnection

final java.sql.Connection getConnection(java.lang.String username,
                                        java.lang.String password,
                                        boolean requestPassword)
                                 throws java.sql.SQLException
Parameters:
requestPassword - Use true if the password came from the getConnection() call.
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Returns false unless interfaces is implemented.

Specified by:
isWrapperFor in interface java.sql.Wrapper
Parameters:
iface - a class defining an interface
Returns:
true if this implements the interface or directly or indirectly wraps an object that does
Throws:
java.sql.SQLException - if an error occurs while determining whether this is a wrapper for an object with the given interface

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Returns this if this class implements the specified interface.

Specified by:
unwrap in interface java.sql.Wrapper
Parameters:
iface - a class defining an interface
Returns:
an object that implements the interface
Throws:
java.sql.SQLException - if no object is found that implements the interface

setupResourceAdapter

protected static ResourceAdapter setupResourceAdapter(EmbeddedXADataSourceInterface ds,
                                                      ResourceAdapter ra,
                                                      java.lang.String user,
                                                      java.lang.String password,
                                                      boolean requestPassword)
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

Built on Wed 2013-06-12 15:21:56+0000, from revision ???

Apache Derby V10.10 Internals - Copyright © 2004,2013 The Apache Software Foundation. All Rights Reserved.