Package org.apache.derby.jdbc
Class BasicClientDataSource40
- java.lang.Object
-
- org.apache.derby.jdbc.BasicClientDataSource40
-
- All Implemented Interfaces:
Serializable
,Wrapper
,CommonDataSource
,DataSource
,org.apache.derby.jdbc.ClientDataSourceInterface
- Direct Known Subclasses:
BasicClientConnectionPoolDataSource40
,BasicClientXADataSource40
,ClientDataSource
public class BasicClientDataSource40 extends Object implements DataSource, org.apache.derby.jdbc.ClientDataSourceInterface, Serializable
This data source is suitable for client/server use of Derby, running on Java 8 Compact Profile 2 or higher. BasicClientDataSource40 is similar to ClientDataSource except it can not be used with JNDI, 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
- roleName
- loginTimeout @see javax.sql.CommonDataSource set/get
- logWriter @see javax.sql.CommonDataSource set/get
- createDatabase
- connectionAttributes
- shutdownDatabase
- attributesAsPassword
- retrieveMessageText
- securityMechanism
- traceDirectory
- traceFile
- traceFileAppend
- traceLevel
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
className__
static short
CLEAR_TEXT_PASSWORD_SECURITY
See documentation atUSER_ONLY_SECURITY
static short
ENCRYPTED_PASSWORD_SECURITY
See documentation atUSER_ONLY_SECURITY
static short
ENCRYPTED_USER_AND_PASSWORD_SECURITY
See documentation atUSER_ONLY_SECURITY
static int
propertyDefault_traceLevel
See documentation atTRACE_NONE
.static int
SSL_BASIC
The constant indicating that SSL encryption will be used.static int
SSL_OFF
The constant indicating that SSL encryption won't be used.static int
SSL_PEER_AUTHENTICATION
The constant indicating that SSL encryption with peer authentication will be used.static short
STRONG_PASSWORD_SUBSTITUTE_SECURITY
See documentation atUSER_ONLY_SECURITY
static int
TRACE_ALL
See documentation atTRACE_NONE
.static int
TRACE_CONNECTION_CALLS
See documentation atTRACE_NONE
.static int
TRACE_CONNECTS
See documentation atTRACE_NONE
.static int
TRACE_DIAGNOSTICS
See documentation atTRACE_NONE
.static int
TRACE_DRIVER_CONFIGURATION
See documentation atTRACE_NONE
.static int
TRACE_NONE
The client server protocol can be traced.static int
TRACE_PARAMETER_META_DATA
See documentation atTRACE_NONE
.static int
TRACE_PROTOCOL_FLOWS
See documentation atTRACE_NONE
.static int
TRACE_RESULT_SET_CALLS
See documentation atTRACE_NONE
.static int
TRACE_RESULT_SET_META_DATA
See documentation atTRACE_NONE
.static int
TRACE_STATEMENT_CALLS
See documentation atTRACE_NONE
.static int
TRACE_XA_CALLS
See documentation atTRACE_NONE
.static short
USER_ONLY_SECURITY
The source security mechanism to use when connecting to a client data source.
-
Constructor Summary
Constructors Constructor Description BasicClientDataSource40()
Creates a simple DERBY data source with default property values for a non-pooling, non-distributed environment.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int
getClientSSLMode(Properties properties)
Returns the SSL mode specified by the property object.Connection
getConnection()
Attempt to establish a database connection in a non-pooling, non-distributed environment.Connection
getConnection(String user, String password)
Attempt to establish a database connection in a non-pooling, non-distributed environment.String
getConnectionAttributes()
String
getCreateDatabase()
String
getDatabaseName()
String
getDataSourceName()
String
getDescription()
int
getLoginTimeout()
PrintWriter
getLogWriter()
Logger
getParentLogger()
String
getPassword()
static String
getPassword(Properties properties)
int
getPortNumber()
static Properties
getProperties(BasicClientDataSource40 ths)
boolean
getRetrieveMessageText()
static boolean
getRetrieveMessageText(Properties properties)
short
getSecurityMechanism()
Return the security mechanism.short
getSecurityMechanism(String password)
Return the security mechanism for this datasource object.static short
getSecurityMechanism(Properties properties)
Return security mechanism if it is set, else upgrade the security mechanism if possible and return the upgraded security mechanismString
getServerName()
String
getShutdownDatabase()
String
getSsl()
Returns the SSL encryption mode specified for the data source.static int
getSSLModeFromString(String s)
Parses the string and returns the corresponding constant for the SSL mode denoted.String
getTraceDirectory()
String
getTraceFile()
boolean
getTraceFileAppend()
int
getTraceLevel()
String
getUser()
static String
getUser(Properties properties)
boolean
isWrapperFor(Class<?> iface)
Check whether this instance wraps an object that implements the interface specified byiface
.int
maxStatementsToPool()
Returns the maximum number of JDBC prepared statements a connection is allowed to cache.void
setConnectionAttributes(String prop)
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)
void
setDataSourceName(String dataSourceName)
void
setDescription(String description)
void
setLoginTimeout(int seconds)
void
setLogWriter(PrintWriter logWriter)
void
setPassword(String password)
void
setPortNumber(int portNumber)
void
setRetrieveMessageText(boolean retrieveMessageText)
void
setSecurityMechanism(short securityMechanism)
Sets the security mechanism.void
setServerName(String serverName)
void
setShutdownDatabase(String shutdown)
Set this property if one wishes to shutdown the database identified by databaseName.void
setSsl(String mode)
Specifies the SSL encryption mode to use.void
setTraceDirectory(String traceDirectory)
void
setTraceFile(String traceFile)
void
setTraceFileAppend(boolean traceFileAppend)
void
setTraceLevel(int traceLevel)
void
setUser(String user)
<T> T
unwrap(Class<T> iface)
Returnsthis
if this class implements the specified interface.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
-
-
-
Field Detail
-
className__
public static final String className__
- See Also:
- Constant Field Values
-
TRACE_NONE
public static final int TRACE_NONE
The client server protocol can be traced. The constants below define the tracing level, cf. the documentation section "Network Client Tracing" in the "Derby Server and Administration Guide". Cf. the connection attribute (or data source bean property)traceLevel
.TRACE_NONE TRACE_CONNECTION_CALLS TRACE_STATEMENT_CALLS TRACE_RESULT_SET_CALLS TRACE _DRIVER_CONFIGURATION TRACE_CONNECTS TRACE_PROTOCOL_FLOWS TRACE _RESULT_SET_META_DATA TRACE _PARAMETER_META_DATA TRACE_DIAGNOSTICS TRACE_XA_CALLS TRACE_ALL
- See Also:
- Constant Field Values
-
TRACE_CONNECTION_CALLS
public static final int TRACE_CONNECTION_CALLS
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_STATEMENT_CALLS
public static final int TRACE_STATEMENT_CALLS
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_RESULT_SET_CALLS
public static final int TRACE_RESULT_SET_CALLS
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_DRIVER_CONFIGURATION
public static final int TRACE_DRIVER_CONFIGURATION
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_CONNECTS
public static final int TRACE_CONNECTS
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_PROTOCOL_FLOWS
public static final int TRACE_PROTOCOL_FLOWS
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_RESULT_SET_META_DATA
public static final int TRACE_RESULT_SET_META_DATA
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_PARAMETER_META_DATA
public static final int TRACE_PARAMETER_META_DATA
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_DIAGNOSTICS
public static final int TRACE_DIAGNOSTICS
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_XA_CALLS
public static final int TRACE_XA_CALLS
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
TRACE_ALL
public static final int TRACE_ALL
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
propertyDefault_traceLevel
public static final int propertyDefault_traceLevel
See documentation atTRACE_NONE
.- See Also:
- Constant Field Values
-
USER_ONLY_SECURITY
public static final short USER_ONLY_SECURITY
The source security mechanism to use when connecting to a client data source. Security mechanism options are:- USER_ONLY_SECURITY
- CLEAR_TEXT_PASSWORD_SECURITY
- ENCRYPTED_PASSWORD_SECURITY
- ENCRYPTED_USER_AND_PASSWORD_SECURITY - both password and user are encrypted
- STRONG_PASSWORD_SUBSTITUTE_SECURITY
- See Also:
- Constant Field Values
-
CLEAR_TEXT_PASSWORD_SECURITY
public static final short CLEAR_TEXT_PASSWORD_SECURITY
See documentation atUSER_ONLY_SECURITY
- See Also:
- Constant Field Values
-
ENCRYPTED_PASSWORD_SECURITY
public static final short ENCRYPTED_PASSWORD_SECURITY
See documentation atUSER_ONLY_SECURITY
- See Also:
- Constant Field Values
-
ENCRYPTED_USER_AND_PASSWORD_SECURITY
public static final short ENCRYPTED_USER_AND_PASSWORD_SECURITY
See documentation atUSER_ONLY_SECURITY
- See Also:
- Constant Field Values
-
STRONG_PASSWORD_SUBSTITUTE_SECURITY
public static final short STRONG_PASSWORD_SUBSTITUTE_SECURITY
See documentation atUSER_ONLY_SECURITY
- See Also:
- Constant Field Values
-
SSL_OFF
public static final int SSL_OFF
The constant indicating that SSL encryption won't be used.- See Also:
- Constant Field Values
-
SSL_BASIC
public static final int SSL_BASIC
The constant indicating that SSL encryption will be used.- See Also:
- Constant Field Values
-
SSL_PEER_AUTHENTICATION
public static final int SSL_PEER_AUTHENTICATION
The constant indicating that SSL encryption with peer authentication will be used.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BasicClientDataSource40
public BasicClientDataSource40()
Creates a simple DERBY data source with default property values for a non-pooling, non-distributed environment. No particular DatabaseName or other properties are associated with the data source. Every Java Bean should provide a constructor with no arguments since many beanboxes attempt to instantiate a bean by invoking its no-argument constructor.
-
-
Method Detail
-
setLoginTimeout
public void setLoginTimeout(int seconds)
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
-
getLoginTimeout
public int getLoginTimeout()
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
-
setLogWriter
public void setLogWriter(PrintWriter logWriter)
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
-
getLogWriter
public PrintWriter getLogWriter()
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
-
getSSLModeFromString
public static int getSSLModeFromString(String s) throws org.apache.derby.client.am.SqlException
Parses the string and returns the corresponding constant for the SSL mode denoted.Valid values are off, basic and peerAuthentication.
- Parameters:
s
- string denoting the SSL mode- Returns:
- A constant indicating the SSL mode denoted by the string. If the
string is
null
,SSL_OFF
is returned. - Throws:
org.apache.derby.client.am.SqlException
- if the string has an invalid value
-
getClientSSLMode
public static int getClientSSLMode(Properties properties) throws org.apache.derby.client.am.SqlException
Returns the SSL mode specified by the property object.- Parameters:
properties
- data source properties- Returns:
- A constant indicating the SSL mode to use. Defaults to
SSL_OFF
if the SSL attribute isn't specified. - Throws:
org.apache.derby.client.am.SqlException
- if an invalid value for the SSL mode is specified in the property object
-
getUser
public static String getUser(Properties properties)
-
getSecurityMechanism
public static short getSecurityMechanism(Properties properties)
Return security mechanism if it is set, else upgrade the security mechanism if possible and return the upgraded security mechanism- Parameters:
properties
- Look in the properties if securityMechanism is set or not if set, return this security mechanism- Returns:
- security mechanism
-
getRetrieveMessageText
public static boolean getRetrieveMessageText(Properties properties)
-
getPassword
public static String getPassword(Properties properties)
-
setPassword
public void setPassword(String password)
- Specified by:
setPassword
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getPassword
public String getPassword()
- Specified by:
getPassword
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setDatabaseName
public void setDatabaseName(String databaseName)
- Specified by:
setDatabaseName
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getDatabaseName
public String getDatabaseName()
- Specified by:
getDatabaseName
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setDataSourceName
public void setDataSourceName(String dataSourceName)
- Specified by:
setDataSourceName
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getDataSourceName
public String getDataSourceName()
- Specified by:
getDataSourceName
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setDescription
public void setDescription(String description)
- Specified by:
setDescription
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getDescription
public String getDescription()
- Specified by:
getDescription
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setPortNumber
public void setPortNumber(int portNumber)
- Specified by:
setPortNumber
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getPortNumber
public int getPortNumber()
- Specified by:
getPortNumber
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setServerName
public void setServerName(String serverName)
- Specified by:
setServerName
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getServerName
public String getServerName()
- Specified by:
getServerName
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setUser
public void setUser(String user)
- Specified by:
setUser
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getUser
public String getUser()
- Specified by:
getUser
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setRetrieveMessageText
public void setRetrieveMessageText(boolean retrieveMessageText)
- Specified by:
setRetrieveMessageText
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getRetrieveMessageText
public boolean getRetrieveMessageText()
- Specified by:
getRetrieveMessageText
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setSecurityMechanism
public void setSecurityMechanism(short securityMechanism)
Sets the security mechanism.- Specified by:
setSecurityMechanism
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Parameters:
securityMechanism
- to set
-
getSecurityMechanism
public short getSecurityMechanism()
Return the security mechanism. If security mechanism has not been set explicitly on datasource, then upgrade the security mechanism to a more secure one if possible.- Specified by:
getSecurityMechanism
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Returns:
- the security mechanism
- See Also:
getUpgradedSecurityMechanism(String)
-
getSecurityMechanism
public short getSecurityMechanism(String password)
Return the security mechanism for this datasource object. If security mechanism has not been set explicitly on datasource, then upgrade the security mechanism to a more secure one if possible.- Specified by:
getSecurityMechanism
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Parameters:
password
- password of user- Returns:
- the security mechanism
- See Also:
getUpgradedSecurityMechanism(String)
-
setSsl
public void setSsl(String mode) throws org.apache.derby.client.am.SqlException
Specifies the SSL encryption mode to use.Valid values are off, basic and peerAuthentication.
- Specified by:
setSsl
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Parameters:
mode
- the SSL mode to use (off, basic or peerAuthentication)- Throws:
org.apache.derby.client.am.SqlException
- if the specified mode is invalid
-
getSsl
public String getSsl()
Returns the SSL encryption mode specified for the data source.- Specified by:
getSsl
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Returns:
- off, basic or peerAuthentication.
-
setCreateDatabase
public void setCreateDatabase(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 interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- 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 String getCreateDatabase()
- Specified by:
getCreateDatabase
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Returns:
- "create" if create is set, or null if not
-
setShutdownDatabase
public void setShutdownDatabase(String shutdown)
Set this property if one wishes to shutdown the database identified by databaseName.- Specified by:
setShutdownDatabase
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Parameters:
shutdown
- if set to the string "shutdown", this data source will shutdown the database if it is running.
-
getShutdownDatabase
public String getShutdownDatabase()
- Specified by:
getShutdownDatabase
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Returns:
- "shutdown" if shutdown is set, or null if not
-
setConnectionAttributes
public void setConnectionAttributes(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 connectionAttributes. Conflicting settings in connectionAttributes and properties of the DataSource will lead to unexpected behaviour.- Specified by:
setConnectionAttributes
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- 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 Derby documentation for complete list.
-
getConnectionAttributes
public String getConnectionAttributes()
- Specified by:
getConnectionAttributes
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
- Returns:
- Derby specific connection URL attributes
-
setTraceLevel
public void setTraceLevel(int traceLevel)
- Specified by:
setTraceLevel
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getTraceLevel
public int getTraceLevel()
- Specified by:
getTraceLevel
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setTraceFile
public void setTraceFile(String traceFile)
- Specified by:
setTraceFile
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getTraceFile
public String getTraceFile()
- Specified by:
getTraceFile
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setTraceDirectory
public void setTraceDirectory(String traceDirectory)
- Specified by:
setTraceDirectory
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getTraceDirectory
public String getTraceDirectory()
- Specified by:
getTraceDirectory
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
setTraceFileAppend
public void setTraceFileAppend(boolean traceFileAppend)
- Specified by:
setTraceFileAppend
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
getTraceFileAppend
public boolean getTraceFileAppend()
- Specified by:
getTraceFileAppend
in interfaceorg.apache.derby.jdbc.ClientDataSourceInterface
-
maxStatementsToPool
public int maxStatementsToPool()
Returns the maximum number of JDBC prepared statements a connection is allowed to cache.A basic data source will always return zero. If statement caching is required, use a
ConnectionPoolDataSource
.This method is used internally by Derby to determine if statement pooling is to be enabled or not. Not part of public API, so not present in
ClientDataSourceInterface
.- Returns:
- Maximum number of statements to cache, or
0
if caching is disabled (default).
-
getConnection
public Connection getConnection() throws SQLException
Attempt to establish a database connection in a non-pooling, non-distributed environment.- Specified by:
getConnection
in interfaceDataSource
- Returns:
- a Connection to the database
- Throws:
SQLException
- if a database-access error occurs.
-
getConnection
public Connection getConnection(String user, String password) throws SQLException
Attempt to establish a database connection in a non-pooling, non-distributed environment.- Specified by:
getConnection
in interfaceDataSource
- Parameters:
user
- 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.
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
Check whether this instance wraps an object that implements the interface specified byiface
.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
iface
- a class defining an interface- Returns:
true
if this instance implementsiface
, orfalse
otherwise- Throws:
SQLException
- if an error occurs while determining if this instance implementsiface
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
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
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
getProperties
public static Properties getProperties(BasicClientDataSource40 ths)
-
-