Package org.apache.derby.jdbc
Class BasicEmbeddedDataSource40
java.lang.Object
org.apache.derby.jdbc.BasicEmbeddedDataSource40
- All Implemented Interfaces:
Serializable
,Wrapper
,CommonDataSource
,DataSource
,EmbeddedDataSourceInterface
- Direct Known Subclasses:
BasicEmbeddedConnectionPoolDataSource40
,BasicEmbeddedXADataSource40
,ReferenceableDataSource
public class BasicEmbeddedDataSource40
extends Object
implements DataSource, 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 implement
See the specific Derby DataSource implementation for details on their meaning. See also the JDBC specifications for more details.
javax.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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Set password to be a set of connection attributes.protected String
Derby specific connection attributes.protected String
Set to "create" if the database should be created.protected String
protected String
protected String
Set bysetDescription(java.lang.String)
.protected InternalDriver
Unlike a DataSource, the internal driver is shared by all Derby databases in the same JVM.protected String
Instance variable that will not be serialized.protected int
Set bysetLoginTimeout(int)
.private String
Set bysetPassword(java.lang.String)
.private PrintWriter
Instance variable that will not be serialized.private static final long
private String
shortDatabaseName
has attributes ofdatabaseName
stripped off.protected String
Set to "shutdown" if the database should be shutdown.private String
Set bysetUser(java.lang.String)
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
(package private) InternalDriver
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 Object
findService
(String factoryInterface, String serviceName) Privileged service lookup.boolean
Return the value of theattributesAsPassword
property, cf.Attempt to establish a database connection.getConnection
(String username, String password) Attempt to establish a database connection with the given username and password.(package private) final Connection
getConnection
(String username, String password, boolean requestPassword) Get a user connection: minion method.int
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.Get the log writer for this data source.private static ModuleFactory
Privileged Monitor lookup.private String
Return database name with ant attributes stripped off.getUser()
int
hashCode()
boolean
isWrapperFor
(Class<?> interFace) Returns false unlessinterFace
is implemented.void
setAttributesAsPassword
(boolean attributesAsPassword) SetattributeAsPassword
property to enable passing connection request attributes in the password argument ofgetConnection(String,String)
.void
Set this property to pass in more Derby specific connection URL attributes.void
setCreateDatabase
(String create) Set this property to create a new database.void
setDatabaseName
(String databaseName) Set the database name.void
setDataSourceName
(String dsn) Set the data source name.void
setDescription
(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
(PrintWriter out) Set the log writer for this data source.void
setPassword
(String password) Set thepassword
property for the data source.void
setShutdownDatabase
(String shutdown) Set this property if you wish to shutdown the database identified bydatabaseName
.protected static ResourceAdapter
setupResourceAdapter
(EmbeddedXADataSourceInterface ds, ResourceAdapter ra, String user, String password, boolean requestPassword) Return a resource adapter.void
Set theuser
property for the data source.<T> T
Returnsthis
if this class implements the specified interface.protected void
update()
Updatejdbcurl
from attributes set.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
description
Set bysetDescription(java.lang.String)
. -
dataSourceName
-
databaseName
-
connectionAttributes
Derby specific connection attributes. Set bysetConnectionAttributes(java.lang.String)
. -
createDatabase
Set to "create" if the database should be created. SeesetCreateDatabase(java.lang.String)
. -
shutdownDatabase
Set to "shutdown" if the database should be shutdown. SeesetShutdownDatabase(java.lang.String)
. -
attributesAsPassword
protected boolean attributesAsPasswordSet password to be a set of connection attributes. -
shortDatabaseName
-
password
Set bysetPassword(java.lang.String)
. -
user
Set bysetUser(java.lang.String)
. -
loginTimeout
protected int loginTimeoutSet bysetLoginTimeout(int)
. -
printer
Instance variable that will not be serialized. -
jdbcurl
Instance variable that will not be serialized. -
driver
Unlike a DataSource, the internal driver is shared by all Derby databases in the same JVM.
-
-
Constructor Details
-
BasicEmbeddedDataSource40
public BasicEmbeddedDataSource40()Constructs a basic embedded data source. See the class Javadoc.
-
-
Method Details
-
setDatabaseName
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 interfaceEmbeddedDataSourceInterface
- Parameters:
databaseName
- the name of the database
-
getDatabaseName
- Specified by:
getDatabaseName
in interfaceEmbeddedDataSourceInterface
- Returns:
- the database name set by
setDatabaseName(java.lang.String)
.
-
getShortDatabaseName
Return database name with ant attributes stripped off. -
setDataSourceName
Set the data source name. The property is not mandatory. It is used for informational purposes only.- Specified by:
setDataSourceName
in interfaceEmbeddedDataSourceInterface
- Parameters:
dsn
- the name of the data source
-
getDataSourceName
- Specified by:
getDataSourceName
in interfaceEmbeddedDataSourceInterface
- Returns:
- data source name as set in
setDataSourceName(java.lang.String)
.
-
setDescription
Set the data source descripton. This property is not mandatory. It is used for informational purposes only.- Specified by:
setDescription
in interfaceEmbeddedDataSourceInterface
- Parameters:
desc
- the description of the data source
-
getDescription
- Specified by:
getDescription
in interfaceEmbeddedDataSourceInterface
- Returns:
- the description as set in
setDescription(java.lang.String)
.
-
setUser
Set theuser
property for the data source. This is user name for any data sourcegetConnection()
call that takes no arguments.- Specified by:
setUser
in interfaceEmbeddedDataSourceInterface
- Parameters:
user
- The user
-
getUser
- Specified by:
getUser
in interfaceEmbeddedDataSourceInterface
- Returns:
- the user name as set by
setUser(java.lang.String)
.
-
setPassword
Set thepassword
property for the data source. This is user's password for any data sourcegetConnection()
call that takes no arguments.- Specified by:
setPassword
in interfaceEmbeddedDataSourceInterface
- Parameters:
password
- The password in plain text
-
getPassword
- Specified by:
getPassword
in interfaceEmbeddedDataSourceInterface
- Returns:
- the password as set in
setPassword(java.lang.String)
.
-
getLoginTimeout
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. SeesetLoginTimeout(int)
.- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Returns:
- the data source login time limit
- Throws:
SQLException
- if a database access error occurs.
-
setLoginTimeout
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 interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Parameters:
seconds
- the data source login time limit- Throws:
SQLException
- if a database access error occurs.
-
getLogWriter
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 thejava.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 interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Returns:
- the log writer for this data source, null if disabled
- Throws:
SQLException
- if a database-access error occurs.
-
setLogWriter
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 thejava.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 interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Parameters:
out
- the new log writer; to disable, set to null- Throws:
SQLException
- if a database-access error occurs.
-
update
protected void update()Updatejdbcurl
from attributes set. -
setCreateDatabase
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:
setCreateDatabase
in 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
- Specified by:
getCreateDatabase
in interfaceEmbeddedDataSourceInterface
- Returns:
- The string
"create"
if create is set, ornull
if not
-
findDriver
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:
SQLException
-
setConnectionAttributes
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 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
- Specified by:
getConnectionAttributes
in interfaceEmbeddedDataSourceInterface
- Returns:
- the Derby specific connection URL attributes, see
setConnectionAttributes(java.lang.String)
.
-
setShutdownDatabase
Set this property if you wish to shutdown the database identified bydatabaseName
.- Specified by:
setShutdownDatabase
in interfaceEmbeddedDataSourceInterface
- Parameters:
shutdown
- if set to the string"shutdown"
, this data source will shutdown the database if it is running.
-
getShutdownDatabase
- Specified by:
getShutdownDatabase
in interfaceEmbeddedDataSourceInterface
- Returns:
- the string
"shutdown"
if shutdown is set, or null if not, cf.setShutdownDatabase(java.lang.String)
.
-
setAttributesAsPassword
public void setAttributesAsPassword(boolean attributesAsPassword) SetattributeAsPassword
property to enable passing connection request attributes in the password argument ofgetConnection(String,String)
. If the property is set totrue
then thepassword
argument of thegetConnection(String, String)
method call is taken to be a list of connection attributes with the same format as theconnectionAttributes
property.- Specified by:
setAttributesAsPassword
in interfaceEmbeddedDataSourceInterface
- Parameters:
attributesAsPassword
- Usetrue
to encode password argument as a set of connection attributes in a connection request.
-
getAttributesAsPassword
public boolean getAttributesAsPassword()Return the value of theattributesAsPassword
property, cf.setAttributesAsPassword(boolean)
.- Specified by:
getAttributesAsPassword
in interfaceEmbeddedDataSourceInterface
- Returns:
- the value
-
equals
-
hashCode
public int hashCode() -
getConnection
Attempt to establish a database connection.- Specified by:
getConnection
in interfaceDataSource
- Returns:
- a Connection to the database
- Throws:
SQLException
- if a database-access error occurs.
-
getConnection
Attempt to establish a database connection with the given username and password. If theattributeAsPassword
property is set to true then the password argument is taken to be a list of connection attributes with the same format as theconnectionAttributes
property.- Specified by:
getConnection
in interfaceDataSource
- Parameters:
username
- the database user on whose behalf the Connection is being madepassword
- the user's password- Returns:
- a Connection to the database
- Throws:
SQLException
- if a database-access error occurs.
-
getConnection
final Connection getConnection(String username, String password, boolean requestPassword) throws SQLException Get a user connection: minion method.- Parameters:
username
- the user namepassword
- the passwordrequestPassword
-true
if the password came from the getConnection() call with user and password arguments..- Returns:
- user connection
- Throws:
SQLException
-
isWrapperFor
Returns false unlessinterFace
is implemented.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
interFace
- a class defining an interface- Returns:
true
if this implements the interface or directly or indirectly wraps an object that does- Throws:
SQLException
- if an error occurs while determining whether this is a wrapper for an object with the given interface
-
unwrap
Returnsthis
if this class implements the specified interface.- Specified by:
unwrap
in interfaceWrapper
- Parameters:
iface
- a class defining an interface- Returns:
- an object that implements the interface
- Throws:
SQLException
- if no object is found that implements the interface
-
setupResourceAdapter
protected static ResourceAdapter setupResourceAdapter(EmbeddedXADataSourceInterface ds, ResourceAdapter ra, String user, String password, boolean requestPassword) throws SQLException Return a resource adapter. Usera
if 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:
SQLException
- An error occurred
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
getMonitor
Privileged Monitor lookup. Must be private so that user code can't call this entry point. -
findService
Privileged service lookup. Must be private so that user code can't call this entry point.
-