Class ClientDataSource
- All Implemented Interfaces:
Serializable, Wrapper, Referenceable, CommonDataSource, DataSource
- Direct Known Subclasses:
ClientConnectionPoolDataSource, ClientXADataSource
The example below registers a DNC data source object with a JNDI naming service.
org.apache.derby.client.ClientDataSource dataSource = new org.apache.derby.client.ClientDataSource ();
dataSource.setServerName ("my_derby_database_server");
dataSource.setDatabaseName ("my_derby_database_name");
javax.naming.Context context = new javax.naming.InitialContext();
context.bind ("jdbc/my_datasource_name", dataSource);
The first line of code in the example creates a data source object.
The next two lines initialize the data source's
properties. Then a Java object that references the initial JNDI naming
context is created by calling the
InitialContext() constructor, which is provided by JNDI.
System properties (not shown) are used to tell JNDI the
service provider to use. The JNDI name space is hierarchical,
similar to the directory structure of many file
systems. The data source object is bound to a logical JNDI name
by calling Context.bind(). In this case the JNDI name
identifies a subcontext, "jdbc", of the root naming context
and a logical name, "my_datasource_name", within the jdbc
subcontext. This is all of the code required to deploy
a data source object within JNDI. This example is provided
mainly for illustrative purposes. We expect that developers
or system administrators will normally use a GUI tool to
deploy a data source object.
Once a data source has been registered with JNDI,
it can then be used by a JDBC application, as is shown in the
following example.
javax.naming.Context context = new javax.naming.InitialContext ();
javax.sql.DataSource dataSource = (javax.sql.DataSource) context.lookup ("jdbc/my_datasource_name");
java.sql.Connection connection = dataSource.getConnection ("user", "password");
The first line in the example creates a Java object
that references the initial JNDI naming context. Next, the
initial naming context is used to do a lookup operation
using the logical name of the data source. The
Context.lookup() method returns a reference to a Java Object,
which is narrowed to a javax.sql.DataSource object. In
the last line, the DataSource.getConnection() method
is called to produce a database connection.
This simple data source subclass of BasicClientDataSource40 maintains
it's own private password property.
The specified password, along with the user, is validated by DERBY.
This property can be overwritten by specifying
the password parameter on the DataSource.getConnection() method call.
This password property is not declared transient, and therefore
may be serialized to a file in clear-text, or stored
to a JNDI server in clear-text when the data source is saved.
Care must taken by the user to prevent security
breaches.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final shortSee documentation atUSER_ONLY_SECURITYstatic final shortSee documentation atUSER_ONLY_SECURITYstatic final shortSee documentation atUSER_ONLY_SECURITYstatic final intstatic final booleanstatic final shortDefault security mechanism is USER_ONLY_SECURITY.static final Stringstatic final booleanstatic final intSee documentation atTRACE_NONE.static final Stringstatic final intThe constant indicating that SSL encryption will be used.static final intThe constant indicating that SSL encryption won't be used.static final intThe constant indicating that SSL encryption with peer authentication will be used.static final shortSee documentation atUSER_ONLY_SECURITYstatic final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final intThe client server protocol can be traced.static final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final intSee documentation atTRACE_NONE.static final shortThe source security mechanism to use when connecting to a client data source. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a simple DERBY data source with default property values for a non-pooling, non-distributed environment. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.derby.client.am.LogWritercomputeDncLogWriterForNewConnection(PrintWriter logWriter, String traceDirectory, String traceFile, boolean traceFileAppend, int traceLevel, String logWriterInUseSuffix, int traceFileSuffixIndex) static intgetClientSSLMode(Properties properties) Returns the SSL mode specified by the property object.Attempt to establish a database connection in a non-pooling, non-distributed environment.getConnection(String user, String password) Attempt to establish a database connection in a non-pooling, non-distributed environment.int/////////////////////////////////////////////////////////////////static StringgetPassword(Properties properties) intstatic PropertiesgetProperties(org.apache.derby.client.BasicClientDataSource ths) booleanstatic booleangetRetrieveMessageText(Properties properties) shortReturn the security mechanism.shortgetSecurityMechanism(String password) Return the security mechanism for this datasource object.static shortgetSecurityMechanism(Properties properties) Return security mechanism if it is set, else upgrade the security mechanism if possible and return the upgraded security mechanismgetSsl()Returns the SSL encryption mode specified for the data source.static intParses the string and returns the corresponding constant for the SSL mode denoted.static StringgetTraceDirectory(Properties properties) Check if derby.client.traceDirectory is provided as a JVM property.static StringgetTraceFile(Properties properties) booleanstatic booleangetTraceFileAppend(Properties properties) intstatic intgetTraceLevel(Properties properties) Check if derby.client.traceLevel is provided as a JVM property.getUser()static StringgetUser(Properties properties) booleanisWrapperFor(Class<?> iface) Check whether this instance wraps an object that implements the interface specified byiface.intReturns the maximum number of JDBC prepared statements a connection is allowed to cache.voidSet this property to pass in more Derby specific connection URL attributes.voidsetCreateDatabase(String create) Set this property to create a new database.voidsetDatabaseName(String databaseName) voidsetDataSourceName(String dataSourceName) voidsetDescription(String description) voidsetLoginTimeout(int seconds) voidsetLogWriter(PrintWriter logWriter) voidsetPassword(String password) voidsetPortNumber(int portNumber) voidsetRetrieveMessageText(boolean retrieveMessageText) voidsetSecurityMechanism(short securityMechanism) Sets the security mechanism.voidsetServerName(String serverName) voidsetShutdownDatabase(String shutdown) Set this property if one wishes to shutdown the database identified by databaseName.voidSpecifies the SSL encryption mode to use.voidsetTraceDirectory(String traceDirectory) voidsetTraceFile(String traceFile) voidsetTraceFileAppend(boolean traceFileAppend) voidsetTraceLevel(int traceLevel) voidstatic PropertiestokenizeAttributes(String attributeString, Properties properties) <T> TReturnsthisif this class implements the specified interface.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CommonDataSource
createShardingKeyBuilderMethods inherited from interface DataSource
createConnectionBuilder
-
Field Details
-
className__
- See Also:
-
TRACE_NONE
public static final int TRACE_NONEThe 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:
-
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
-
propertyDefault_traceLevel
-
USER_ONLY_SECURITY
public static final short USER_ONLY_SECURITYThe 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
If the application specifies a security mechanism then it will be the only one attempted. If the specified security mechanism is not supported by the conversation then an exception will be thrown and there will be no additional retries.
Both user and password need to be set for all security mechanism except USER_ONLY_SECURITY.
- See Also:
-
CLEAR_TEXT_PASSWORD_SECURITY
public static final short CLEAR_TEXT_PASSWORD_SECURITYSee documentation atUSER_ONLY_SECURITY- See Also:
-
ENCRYPTED_PASSWORD_SECURITY
public static final short ENCRYPTED_PASSWORD_SECURITYSee documentation atUSER_ONLY_SECURITY- See Also:
-
ENCRYPTED_USER_AND_PASSWORD_SECURITY
public static final short ENCRYPTED_USER_AND_PASSWORD_SECURITYSee documentation atUSER_ONLY_SECURITY- See Also:
-
STRONG_PASSWORD_SUBSTITUTE_SECURITY
public static final short STRONG_PASSWORD_SUBSTITUTE_SECURITYSee documentation atUSER_ONLY_SECURITY- See Also:
-
SSL_OFF
public static final int SSL_OFFThe constant indicating that SSL encryption won't be used.- See Also:
-
SSL_BASIC
public static final int SSL_BASICThe constant indicating that SSL encryption will be used.- See Also:
-
SSL_PEER_AUTHENTICATION
public static final int SSL_PEER_AUTHENTICATIONThe constant indicating that SSL encryption with peer authentication will be used.- See Also:
-
propertyDefault_portNumber
static final int propertyDefault_portNumber- See Also:
-
propertyDefault_serverName
- See Also:
-
propertyDefault_user
- See Also:
-
propertyDefault_retrieveMessageText
static final boolean propertyDefault_retrieveMessageText- See Also:
-
propertyDefault_securityMechanism
static final short propertyDefault_securityMechanismDefault security mechanism is USER_ONLY_SECURITY.- See Also:
-
propertyDefault_traceFileAppend
static final boolean propertyDefault_traceFileAppend- See Also:
-
-
Constructor Details
-
ClientDataSource
public ClientDataSource()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 Details
-
getReference
- Specified by:
getReferencein interfaceReferenceable- Throws:
NamingException
-
setLoginTimeout
public void setLoginTimeout(int seconds) - Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource
-
getLoginTimeout
public int getLoginTimeout()- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource
-
getLogWriter
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource
-
getSSLModeFromString
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_OFFis 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_OFFif 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
-
getSecurityMechanism
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
-
getTraceFile
-
getTraceDirectory
Check if derby.client.traceDirectory is provided as a JVM property. If yes, then we use that value. If not, then we look for traceDirectory in the the properties parameter.- Parameters:
properties- jdbc url properties- Returns:
- value of traceDirectory property
-
getTraceFileAppend
-
getPassword
-
setPassword
-
getPassword
-
computeDncLogWriterForNewConnection
public static org.apache.derby.client.am.LogWriter computeDncLogWriterForNewConnection(PrintWriter logWriter, String traceDirectory, String traceFile, boolean traceFileAppend, int traceLevel, String logWriterInUseSuffix, int traceFileSuffixIndex) throws org.apache.derby.client.am.SqlException - Throws:
org.apache.derby.client.am.SqlException
-
tokenizeAttributes
public static Properties tokenizeAttributes(String attributeString, Properties properties) throws org.apache.derby.client.am.SqlException - Throws:
org.apache.derby.client.am.SqlException
-
setDatabaseName
-
getDatabaseName
-
setDataSourceName
-
getDataSourceName
-
setDescription
-
getDescription
-
setPortNumber
public void setPortNumber(int portNumber) -
getPortNumber
public int getPortNumber() -
setServerName
-
getServerName
-
setUser
-
getUser
-
setRetrieveMessageText
public void setRetrieveMessageText(boolean retrieveMessageText) -
getRetrieveMessageText
public boolean getRetrieveMessageText() -
setSecurityMechanism
public void setSecurityMechanism(short securityMechanism) Sets the security mechanism.- 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.- Returns:
- the security mechanism
- See Also:
-
getSecurityMechanism
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.- Parameters:
password- password of user- Returns:
- the security mechanism
- See Also:
-
setSsl
Specifies the SSL encryption mode to use.Valid values are off, basic and peerAuthentication.
- 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
Returns the SSL encryption mode specified for the data source.- Returns:
- off, basic or peerAuthentication.
-
setCreateDatabase
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.- 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
- Returns:
- "create" if create is set, or null if not
-
setShutdownDatabase
Set this property if one wishes to shutdown the database identified by databaseName.- Parameters:
shutdown- if set to the string "shutdown", this data source will shutdown the database if it is running.
-
getShutdownDatabase
- Returns:
- "shutdown" if shutdown is set, or null if not
-
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 connectionAttributes. Conflicting settings in connectionAttributes and properties of the DataSource will lead to unexpected behaviour.- 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
- Returns:
- Derby specific connection URL attributes
-
getTraceLevel
Check if derby.client.traceLevel is provided as a JVM property. If yes, then we use that value. If not, then we look for traceLevel in the the properties parameter.- Parameters:
properties- jdbc url properties- Returns:
- value of traceLevel property
-
setTraceLevel
public void setTraceLevel(int traceLevel) -
getTraceLevel
public int getTraceLevel() -
setTraceFile
-
getTraceFile
-
setTraceDirectory
-
getTraceDirectory
-
setTraceFileAppend
public void setTraceFileAppend(boolean traceFileAppend) -
getTraceFileAppend
public boolean getTraceFileAppend() -
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
0if caching is disabled (default).
-
getConnection
Attempt to establish a database connection in a non-pooling, non-distributed environment.- Specified by:
getConnectionin interfaceDataSource- Returns:
- a Connection to the database
- Throws:
SQLException- if a database-access error occurs.
-
getConnection
Attempt to establish a database connection in a non-pooling, non-distributed environment.- Specified by:
getConnectionin 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
Check whether this instance wraps an object that implements the interface specified byiface.- Specified by:
isWrapperForin interfaceWrapper- Parameters:
iface- a class defining an interface- Returns:
trueif this instance implementsiface, orfalseotherwise- Throws:
SQLException- if an error occurs while determining if this instance implementsiface
-
unwrap
Returnsthisif this class implements the specified interface.- Specified by:
unwrapin 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
/////////////////////////////////////////////////////////////////- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
getProperties
-