Package org.apache.derby.jdbc
Class BasicEmbeddedDataSource40
- java.lang.Object
-
- org.apache.derby.jdbc.BasicEmbeddedDataSource40
-
- All Implemented Interfaces:
java.io.Serializable,java.sql.Wrapper,javax.sql.CommonDataSource,javax.sql.DataSource,EmbeddedDataSourceInterface
- Direct Known Subclasses:
BasicEmbeddedConnectionPoolDataSource40,BasicEmbeddedXADataSource40,ReferenceableDataSource
public class BasicEmbeddedDataSource40 extends java.lang.Object implements javax.sql.DataSource, java.io.Serializable, EmbeddedDataSourceInterface
This data source is suitable for an application using embedded Derby, running on Java 8 Compact Profile 2 or higher. BasicEmbeddedDataSource40 is similar to EmbeddedDataSource, but does not support JNDI naming, i.e. it does not implementjavax.naming.Referenceable. The standard attributes provided are, cf. e.g. table 9.1 in the JDBC 4.2 specification.- databaseName
- dataSourceName
- description
- password
- user
- networkProtocol
- portNumber
- roleName
- serverName
- loginTimeout @see javax.sql.CommonDataSource set/get
- logWriter @see javax.sql.CommonDataSource set/get
- createDatabase
- connectionAttributes
- shutdownDatabase
- attributesAsPassword
See the specific Derby DataSource implementation for details on their meaning. See also the JDBC specifications for more details.- See Also:
EmbeddedDataSource, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanattributesAsPasswordSet password to be a set of connection attributes.protected java.lang.StringconnectionAttributesDerby specific connection attributes.protected java.lang.StringcreateDatabaseSet to "create" if the database should be created.protected java.lang.StringdatabaseNameprotected java.lang.StringdataSourceNameprotected java.lang.StringdescriptionSet bysetDescription(java.lang.String).protected InternalDriverdriverUnlike a DataSource, the internal driver is shared by all Derby databases in the same JVM.protected java.lang.StringjdbcurlInstance variable that will not be serialized.protected intloginTimeoutSet bysetLoginTimeout(int).private java.lang.StringpasswordSet bysetPassword(java.lang.String).private java.io.PrintWriterprinterInstance variable that will not be serialized.private static longserialVersionUIDprivate java.lang.StringshortDatabaseNameshortDatabaseNamehas attributes ofdatabaseNamestripped off.protected java.lang.StringshutdownDatabaseSet to "shutdown" if the database should be shutdown.private java.lang.StringuserSet bysetUser(java.lang.String).
-
Constructor Summary
Constructors Constructor Description BasicEmbeddedDataSource40()Constructs a basic embedded data source.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object other)(package private) InternalDriverfindDriver()Return a handle to the internal driver, possibly instantiating it first if it hasn't been booted or if it has been shut down.private static java.lang.ObjectfindService(java.lang.String factoryInterface, java.lang.String serviceName)Privileged service lookup.booleangetAttributesAsPassword()Return the value of theattributesAsPasswordproperty, cf.java.sql.ConnectiongetConnection()Attempt to establish a database connection.java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password)Attempt to establish a database connection with the given username and password.(package private) java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password, boolean requestPassword)Get a user connection: minion method.java.lang.StringgetConnectionAttributes()java.lang.StringgetCreateDatabase()java.lang.StringgetDatabaseName()java.lang.StringgetDataSourceName()java.lang.StringgetDescription()intgetLoginTimeout()Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.java.io.PrintWritergetLogWriter()Get the log writer for this data source.private static ModuleFactorygetMonitor()Privileged Monitor lookup.java.util.logging.LoggergetParentLogger()java.lang.StringgetPassword()private java.lang.StringgetShortDatabaseName()Return database name with ant attributes stripped off.java.lang.StringgetShutdownDatabase()java.lang.StringgetUser()inthashCode()booleanisWrapperFor(java.lang.Class<?> interFace)Returns false unlessinterFaceis implemented.voidsetAttributesAsPassword(boolean attributesAsPassword)SetattributeAsPasswordproperty to enable passing connection request attributes in the password argument ofgetConnection(String,String).voidsetConnectionAttributes(java.lang.String prop)Set this property to pass in more Derby specific connection URL attributes.voidsetCreateDatabase(java.lang.String create)Set this property to create a new database.voidsetDatabaseName(java.lang.String databaseName)Set the database name.voidsetDataSourceName(java.lang.String dsn)Set the data source name.voidsetDescription(java.lang.String desc)Set the data source descripton.voidsetLoginTimeout(int seconds)Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.voidsetLogWriter(java.io.PrintWriter out)Set the log writer for this data source.voidsetPassword(java.lang.String password)Set thepasswordproperty for the data source.voidsetShutdownDatabase(java.lang.String shutdown)Set this property if you wish to shutdown the database identified bydatabaseName.protected static ResourceAdaptersetupResourceAdapter(EmbeddedXADataSourceInterface ds, ResourceAdapter ra, java.lang.String user, java.lang.String password, boolean requestPassword)Return a resource adapter.voidsetUser(java.lang.String user)Set theuserproperty for the data source.<T> Tunwrap(java.lang.Class<T> iface)Returnsthisif this class implements the specified interface.protected voidupdate()Updatejdbcurlfrom attributes set.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
description
protected java.lang.String description
Set bysetDescription(java.lang.String).
-
dataSourceName
protected java.lang.String dataSourceName
-
databaseName
protected java.lang.String databaseName
-
connectionAttributes
protected java.lang.String connectionAttributes
Derby specific connection attributes. Set bysetConnectionAttributes(java.lang.String).
-
createDatabase
protected java.lang.String createDatabase
Set to "create" if the database should be created. SeesetCreateDatabase(java.lang.String).
-
shutdownDatabase
protected java.lang.String shutdownDatabase
Set to "shutdown" if the database should be shutdown. SeesetShutdownDatabase(java.lang.String).
-
attributesAsPassword
protected boolean attributesAsPassword
Set password to be a set of connection attributes.
-
shortDatabaseName
private java.lang.String shortDatabaseName
-
password
private java.lang.String password
Set bysetPassword(java.lang.String).
-
user
private java.lang.String user
Set bysetUser(java.lang.String).
-
loginTimeout
protected int loginTimeout
Set bysetLoginTimeout(int).
-
printer
private transient java.io.PrintWriter printer
Instance variable that will not be serialized.
-
jdbcurl
protected transient java.lang.String jdbcurl
Instance variable that will not be serialized.
-
driver
protected transient InternalDriver driver
Unlike a DataSource, the internal driver is shared by all Derby databases in the same JVM.
-
-
Method Detail
-
setDatabaseName
public 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:
setDatabaseNamein interfaceEmbeddedDataSourceInterface- Parameters:
databaseName- the name of the database
-
getDatabaseName
public java.lang.String getDatabaseName()
- Specified by:
getDatabaseNamein interfaceEmbeddedDataSourceInterface- Returns:
- the database name set by
setDatabaseName(java.lang.String).
-
getShortDatabaseName
private java.lang.String getShortDatabaseName()
Return database name with ant attributes stripped off.
-
setDataSourceName
public 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:
setDataSourceNamein interfaceEmbeddedDataSourceInterface- Parameters:
dsn- the name of the data source
-
getDataSourceName
public java.lang.String getDataSourceName()
- Specified by:
getDataSourceNamein interfaceEmbeddedDataSourceInterface- Returns:
- data source name as set in
setDataSourceName(java.lang.String).
-
setDescription
public 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:
setDescriptionin interfaceEmbeddedDataSourceInterface- Parameters:
desc- the description of the data source
-
getDescription
public java.lang.String getDescription()
- Specified by:
getDescriptionin interfaceEmbeddedDataSourceInterface- Returns:
- the description as set in
setDescription(java.lang.String).
-
setUser
public void setUser(java.lang.String user)
Set theuserproperty for the data source. This is user name for any data sourcegetConnection()call that takes no arguments.- Specified by:
setUserin interfaceEmbeddedDataSourceInterface- Parameters:
user- The user
-
getUser
public java.lang.String getUser()
- Specified by:
getUserin interfaceEmbeddedDataSourceInterface- Returns:
- the user name as set by
setUser(java.lang.String).
-
setPassword
public void setPassword(java.lang.String password)
Set thepasswordproperty for the data source. This is user's password for any data sourcegetConnection()call that takes no arguments.- Specified by:
setPasswordin interfaceEmbeddedDataSourceInterface- Parameters:
password- The password in plain text
-
getPassword
public java.lang.String getPassword()
- Specified by:
getPasswordin interfaceEmbeddedDataSourceInterface- Returns:
- the password as set in
setPassword(java.lang.String).
-
getLoginTimeout
public int getLoginTimeout() throws java.sql.SQLExceptionGets 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. SeesetLoginTimeout(int).- Specified by:
getLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
getLoginTimeoutin interfacejavax.sql.DataSource- 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.SQLExceptionSets 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:
setLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
setLoginTimeoutin interfacejavax.sql.DataSource- 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.SQLExceptionGet 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 thejava.sql.Drivermanagerclass. When a data source object is created the log writer is initially null, in other words, logging is disabled.- Specified by:
getLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
getLogWriterin interfacejavax.sql.DataSource- 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.SQLExceptionSet 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 thejava.sql.Drivermanagerclass. When a data source object is created the log writer is initially null, in other words, logging is disabled.- Specified by:
setLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
setLogWriterin interfacejavax.sql.DataSource- 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()
Updatejdbcurlfrom attributes set.
-
setCreateDatabase
public void setCreateDatabase(java.lang.String create)
Set this property to create a new database. If this property is not set, the database (identified bydatabaseName) is assumed to be already existing.- Specified by:
setCreateDatabasein interfaceEmbeddedDataSourceInterface- 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 java.lang.String getCreateDatabase()
- Specified by:
getCreateDatabasein interfaceEmbeddedDataSourceInterface- Returns:
- The string
"create"if create is set, ornullif not
-
findDriver
InternalDriver findDriver() throws java.sql.SQLException
Return a handle to the internal driver, possibly instantiating it first if it hasn't been booted or if it has been shut down.- Returns:
- The internal driver handle
- Throws:
java.sql.SQLException
-
setConnectionAttributes
public 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:
setConnectionAttributesin interfaceEmbeddedDataSourceInterface- 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 java.lang.String getConnectionAttributes()
- Specified by:
getConnectionAttributesin interfaceEmbeddedDataSourceInterface- Returns:
- the Derby specific connection URL attributes, see
setConnectionAttributes(java.lang.String).
-
setShutdownDatabase
public void setShutdownDatabase(java.lang.String shutdown)
Set this property if you wish to shutdown the database identified bydatabaseName.- Specified by:
setShutdownDatabasein interfaceEmbeddedDataSourceInterface- Parameters:
shutdown- if set to the string"shutdown", this data source will shutdown the database if it is running.
-
getShutdownDatabase
public java.lang.String getShutdownDatabase()
- Specified by:
getShutdownDatabasein interfaceEmbeddedDataSourceInterface- Returns:
- the string
"shutdown"if shutdown is set, or null if not, cf.setShutdownDatabase(java.lang.String).
-
setAttributesAsPassword
public void setAttributesAsPassword(boolean attributesAsPassword)
SetattributeAsPasswordproperty to enable passing connection request attributes in the password argument ofgetConnection(String,String). If the property is set totruethen thepasswordargument of thegetConnection(String, String)method call is taken to be a list of connection attributes with the same format as theconnectionAttributesproperty.- Specified by:
setAttributesAsPasswordin interfaceEmbeddedDataSourceInterface- Parameters:
attributesAsPassword- Usetrueto encode password argument as a set of connection attributes in a connection request.
-
getAttributesAsPassword
public boolean getAttributesAsPassword()
Return the value of theattributesAsPasswordproperty, cf.setAttributesAsPassword(boolean).- Specified by:
getAttributesAsPasswordin interfaceEmbeddedDataSourceInterface- Returns:
- the value
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionAttempt to establish a database connection.- Specified by:
getConnectionin interfacejavax.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.SQLExceptionAttempt to establish a database connection with the given username and password. If theattributeAsPasswordproperty is set to true then the password argument is taken to be a list of connection attributes with the same format as theconnectionAttributesproperty.- Specified by:
getConnectionin interfacejavax.sql.DataSource- Parameters:
username- the database user on whose behalf the Connection is being madepassword- 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.SQLExceptionGet a user connection: minion method.- Parameters:
username- the user namepassword- the passwordrequestPassword-trueif the password came from the getConnection() call with user and password arguments..- Returns:
- user connection
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> interFace) throws java.sql.SQLExceptionReturns false unlessinterFaceis implemented.- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Parameters:
interFace- a class defining an interface- Returns:
trueif 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.SQLExceptionReturnsthisif this class implements the specified interface.- Specified by:
unwrapin interfacejava.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
Return a resource adapter. Useraif non-null and active, else get the one for the data base.- Parameters:
ds- The data sourcera- The cached value if anyuser- The user namepassword- The password in clear textrequestPassword- Iftrue, use the supplied user and password to boot the database if required- Returns:
- the resource adapter
- Throws:
java.sql.SQLException- An error occurred
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException- Specified by:
getParentLoggerin interfacejavax.sql.CommonDataSource- Throws:
java.sql.SQLFeatureNotSupportedException
-
getMonitor
private static ModuleFactory getMonitor()
Privileged Monitor lookup. Must be private so that user code can't call this entry point.
-
findService
private static java.lang.Object findService(java.lang.String factoryInterface, java.lang.String serviceName)Privileged service lookup. Must be private so that user code can't call this entry point.
-
-