java.io.Serializable
, java.sql.Wrapper
, javax.sql.CommonDataSource
, javax.sql.DataSource
, EmbeddedDataSourceInterface
BasicEmbeddedConnectionPoolDataSource40
, BasicEmbeddedXADataSource40
, ReferenceableDataSource
public class BasicEmbeddedDataSource40 extends java.lang.Object implements javax.sql.DataSource, java.io.Serializable, EmbeddedDataSourceInterface
javax.naming.Referenceable
.
The standard attributes provided are, cf. e.g. table
9.1 in the JDBC 4.2 specification.
EmbeddedDataSource
,
Serialized FormModifier and Type | Field | Description |
---|---|---|
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 |
Set by
setDescription(java.lang.String) . |
protected InternalDriver |
driver |
Unlike a DataSource, the internal driver is shared by all
Derby databases in the same JVM.
|
protected java.lang.String |
jdbcurl |
Instance variable that will not be serialized.
|
protected int |
loginTimeout |
Set by
setLoginTimeout(int) . |
private java.lang.String |
password |
Set by
setPassword(java.lang.String) . |
private java.io.PrintWriter |
printer |
Instance variable that will not be serialized.
|
private static long |
serialVersionUID |
|
private java.lang.String |
shortDatabaseName |
shortDatabaseName has attributes of databaseName
stripped off. |
protected java.lang.String |
shutdownDatabase |
Set to "shutdown" if the database should be shutdown.
|
private java.lang.String |
user |
Set by
setUser(java.lang.String) . |
Constructor | Description |
---|---|
BasicEmbeddedDataSource40() |
Constructs a basic embedded data source.
|
Modifier and Type | Method | Description |
---|---|---|
boolean |
equals(java.lang.Object other) |
|
(package private) InternalDriver |
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.
|
private static java.lang.Object |
findService(java.lang.String factoryInterface,
java.lang.String serviceName) |
Privileged service lookup.
|
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) |
Get a user connection: minion method.
|
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.
|
private static ModuleFactory |
getMonitor() |
Privileged Monitor lookup.
|
java.util.logging.Logger |
getParentLogger() |
|
java.lang.String |
getPassword() |
|
private java.lang.String |
getShortDatabaseName() |
Return database name with ant attributes stripped off.
|
java.lang.String |
getShutdownDatabase() |
|
java.lang.String |
getUser() |
|
int |
hashCode() |
|
boolean |
isWrapperFor(java.lang.Class<?> interFace) |
Returns false unless
interFace 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) |
Return a resource adapter.
|
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() |
Update
jdbcurl from attributes set. |
private static final long serialVersionUID
protected java.lang.String description
setDescription(java.lang.String)
.protected java.lang.String dataSourceName
protected java.lang.String databaseName
protected java.lang.String connectionAttributes
setConnectionAttributes(java.lang.String)
.protected java.lang.String createDatabase
setCreateDatabase(java.lang.String)
.protected java.lang.String shutdownDatabase
setShutdownDatabase(java.lang.String)
.protected boolean attributesAsPassword
private java.lang.String shortDatabaseName
private java.lang.String password
setPassword(java.lang.String)
.private java.lang.String user
setUser(java.lang.String)
.protected int loginTimeout
setLoginTimeout(int)
.private transient java.io.PrintWriter printer
protected transient java.lang.String jdbcurl
protected transient InternalDriver driver
public BasicEmbeddedDataSource40()
public void setDatabaseName(java.lang.String databaseName)
setDatabaseName
in interface EmbeddedDataSourceInterface
databaseName
- the name of the databasepublic java.lang.String getDatabaseName()
getDatabaseName
in interface EmbeddedDataSourceInterface
setDatabaseName(java.lang.String)
.private java.lang.String getShortDatabaseName()
public void setDataSourceName(java.lang.String dsn)
setDataSourceName
in interface EmbeddedDataSourceInterface
dsn
- the name of the data sourcepublic java.lang.String getDataSourceName()
getDataSourceName
in interface EmbeddedDataSourceInterface
setDataSourceName(java.lang.String)
.public void setDescription(java.lang.String desc)
setDescription
in interface EmbeddedDataSourceInterface
desc
- the description of the data sourcepublic java.lang.String getDescription()
getDescription
in interface EmbeddedDataSourceInterface
setDescription(java.lang.String)
.public void setUser(java.lang.String user)
user
property for the data source.
This is user name for any data source getConnection()
call
that takes no arguments.setUser
in interface EmbeddedDataSourceInterface
user
- The userpublic java.lang.String getUser()
getUser
in interface EmbeddedDataSourceInterface
setUser(java.lang.String)
.public void setPassword(java.lang.String password)
password
property for the data source.
This is user's password for any data source getConnection()
call
that takes no arguments.setPassword
in interface EmbeddedDataSourceInterface
password
- The password in plain textpublic java.lang.String getPassword()
getPassword
in interface EmbeddedDataSourceInterface
setPassword(java.lang.String)
.public int getLoginTimeout() throws java.sql.SQLException
setLoginTimeout(int)
.getLoginTimeout
in interface javax.sql.CommonDataSource
getLoginTimeout
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurs.public void setLoginTimeout(int seconds) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.CommonDataSource
setLoginTimeout
in interface javax.sql.DataSource
seconds
- the data source login time limitjava.sql.SQLException
- if a database access error occurs.public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
java.sql.Drivermanager
class.
When a data source object is created the log writer is
initially null, in other words, logging is disabled.getLogWriter
in interface javax.sql.CommonDataSource
getLogWriter
in interface javax.sql.DataSource
java.sql.SQLException
- if a database-access error occurs.public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
java.sql.Drivermanager
class.
When a data source object is created the log writer is
initially null, in other words, logging is disabled.setLogWriter
in interface javax.sql.CommonDataSource
setLogWriter
in interface javax.sql.DataSource
out
- the new log writer; to disable, set to nulljava.sql.SQLException
- if a database-access error occurs.protected void update()
jdbcurl
from attributes set.public void setCreateDatabase(java.lang.String create)
databaseName
)
is assumed to be already existing.setCreateDatabase
in interface EmbeddedDataSourceInterface
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()
getCreateDatabase
in interface EmbeddedDataSourceInterface
"create"
if create is set, or
null
if notInternalDriver findDriver() throws java.sql.SQLException
java.sql.SQLException
public void setConnectionAttributes(java.lang.String prop)
setConnectionAttributes
in interface EmbeddedDataSourceInterface
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.
public java.lang.String getConnectionAttributes()
getConnectionAttributes
in interface EmbeddedDataSourceInterface
setConnectionAttributes(java.lang.String)
.public void setShutdownDatabase(java.lang.String shutdown)
databaseName
.setShutdownDatabase
in interface EmbeddedDataSourceInterface
shutdown
- if set to the string "shutdown"
, this
data source will shutdown the database if it is running.public java.lang.String getShutdownDatabase()
getShutdownDatabase
in interface EmbeddedDataSourceInterface
"shutdown"
if shutdown is set, or
null if not, cf. setShutdownDatabase(java.lang.String)
.public void setAttributesAsPassword(boolean attributesAsPassword)
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.setAttributesAsPassword
in interface EmbeddedDataSourceInterface
attributesAsPassword
- Use true
to encode password
argument as a set of connection attributes in a connection request.public boolean getAttributesAsPassword()
attributesAsPassword
property, cf.
setAttributesAsPassword(boolean)
.getAttributesAsPassword
in interface EmbeddedDataSourceInterface
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
- if a database-access error occurs.public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
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.getConnection
in interface javax.sql.DataSource
username
- the database user on whose behalf the Connection is
being madepassword
- the user's passwordjava.sql.SQLException
- if a database-access error occurs.final java.sql.Connection getConnection(java.lang.String username, java.lang.String password, boolean requestPassword) throws java.sql.SQLException
username
- the user namepassword
- the passwordrequestPassword
- true
if the password came from the
getConnection() call with user and password arguments..java.sql.SQLException
public boolean isWrapperFor(java.lang.Class<?> interFace) throws java.sql.SQLException
interFace
is implemented.isWrapperFor
in interface java.sql.Wrapper
interFace
- a class defining an interfacetrue
if this implements the interface or directly or
indirectly wraps an object that doesjava.sql.SQLException
- if an error occurs while determining
whether this is a wrapper for an object with the given interfacepublic <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
this
if this class implements the specified interface.unwrap
in interface java.sql.Wrapper
iface
- a class defining an interfacejava.sql.SQLException
- if no object is found that implements the
interfaceprotected static ResourceAdapter setupResourceAdapter(EmbeddedXADataSourceInterface ds, ResourceAdapter ra, java.lang.String user, java.lang.String password, boolean requestPassword) throws java.sql.SQLException
ra
if non-null and active, else
get the one for the data base.ds
- The data sourcera
- The cached value if anyuser
- The user namepassword
- The password in clear textrequestPassword
- If true
, use the supplied user and
password to boot the database if requiredjava.sql.SQLException
- An error occurredpublic java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
getParentLogger
in interface javax.sql.CommonDataSource
java.sql.SQLFeatureNotSupportedException
private static ModuleFactory getMonitor()
private static java.lang.Object findService(java.lang.String factoryInterface, java.lang.String serviceName)
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.