Serializable
, Wrapper
, Referenceable
, CommonDataSource
, DataSource
, OracleCommonDataSource
, OracleDataSource
OracleConnectionPoolDataSource
, OracleOCIConnectionPool
public class OracleDataSource extends Object implements OracleDataSource, Serializable, Referenceable
A DataSource object is a factory for Connection objects. An object that implements the DataSource interface will typically be registered with a JNDI service provider. A JDBC driver that is accessed via the DataSource API does not automatically register itself with the DriverManager.
Modifier and Type | Field | Description |
---|---|---|
protected OracleConnectionCacheManager |
cacheManager |
|
protected String |
connCacheName |
|
protected Properties |
connCacheProperties |
|
protected boolean |
connCachingEnabled |
|
protected Properties |
connectionProperties |
|
protected String |
databaseName |
|
protected String |
dataSourceName |
|
protected static String |
DEFAULT_SERVICE_NAME |
|
protected String |
description |
|
protected oracle.jdbc.driver.OracleDriver |
driver |
|
protected String |
driverType |
|
protected static String |
ENABLE_AC_SUPPORT_PROPERTY |
|
protected boolean |
explicitCachingEnabled |
|
protected boolean |
explicitCachingEnabledSet |
|
protected boolean |
fastConnFailover |
|
protected boolean |
implicitCachingEnabled |
|
protected boolean |
implicitCachingEnabledSet |
|
boolean |
isOracleDataSource |
|
protected int |
loginTimeout |
|
protected PrintWriter |
logWriter |
|
protected int |
maxStatements |
|
protected boolean |
maxStatementsSet |
|
protected String |
networkProtocol |
|
protected oracle.jdbc.pool.OracleImplicitConnectionCache |
odsCache |
|
protected String |
onsConfigStr |
|
protected oracle.jdbc.internal.OpaqueString |
password |
|
protected int |
portNumber |
|
protected String |
serverName |
|
protected String |
serviceName |
|
protected String |
tnsEntry |
|
static boolean |
TRACE |
|
protected String |
url |
|
protected String |
user |
Constructor | Description |
---|---|
OracleDataSource() |
Modifier and Type | Method | Description |
---|---|---|
protected void |
addRefProperties(Reference ref) |
|
void |
close() |
Deprecated.
Use Oracle Universal Connection Pool instead.
|
protected void |
copy(OracleDataSource ds) |
|
OracleConnectionBuilderImpl |
createConnectionBuilder() |
Creates a new instance
|
protected void |
debug(Logger logger, Level level, Executable method, String msg) |
|
Connection |
getConnection() |
Attempt to establish a database connection.
|
Connection |
getConnection(String _user, String _passwd) |
Attempt to establish a database connection.
|
Connection |
getConnection(String _user, String _passwd, Properties cachedConnectionAttributes) |
Deprecated.
Use Oracle Universal Connection Pool instead.
|
Connection |
getConnection(Properties cachedConnectionAttributes) |
Deprecated.
Use Oracle Universal Connection Pool instead.
|
Connection |
getConnection(OracleConnectionBuilderImpl builder) |
|
String |
getConnectionCacheName() |
|
Properties |
getConnectionCacheProperties() |
|
boolean |
getConnectionCachingEnabled() |
|
protected oracle.jdbc.internal.OracleConnection |
getConnectionDuringExceptionHandling() |
|
Properties |
getConnectionProperties() |
getConnectionProperties Returns the current Properties set in the datasource.
|
protected String |
getConnectionProperty(String propertyName) |
|
String |
getDatabaseName() |
Get the name of the database set on this DataSource instance.
|
String |
getDataSourceName() |
Get the datasource name for this instance if set.
|
String |
getDescription() |
Get the Desciption of this data source.
|
String |
getDriverType() |
Get the Oracle JDBC driver type set for this datasource instance
|
boolean |
getExplicitCachingEnabled() |
getExplicitCachingEnabled Returns the current value of the explicitCachingEnabled property.
|
boolean |
getFastConnectionFailoverEnabled() |
|
boolean |
getImplicitCachingEnabled() |
getImplicitCachingEnabled Returns the current value of the implicitCachingEnabled property.
|
int |
getLoginTimeout() |
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
|
PrintWriter |
getLogWriter() |
Get the log writer for this data source.
|
int |
getMaxStatements() |
getMaxStatements Returns the current value of the maxStatements property.
|
String |
getNetworkProtocol() |
Get the network protocol set.
|
String |
getONSConfiguration() |
Deprecated.
Use Oracle Universal Connection Pool instead.
|
Logger |
getParentLogger() |
|
protected String |
getPassword() |
|
protected Connection |
getPhysicalConnection(Properties prop, GSSCredential gssCredential, SSLContext sslContext) |
|
int |
getPortNumber() |
Get the port number on which server is listening for requests.
|
Reference |
getReference() |
|
String |
getRoleName() |
Gets the datasource role name.
|
String |
getServerName() |
Get the name of the server on which database is running.
|
String |
getServiceName() |
Get the service_name To distinguish services from instances, a new URL using service_name is added, existing url with SID will be supported, but deprecated.
|
String |
getTNSEntryName() |
Get the TNS entry name for this instance if set.
|
String |
getURL() |
Get the URL for this datasource.
|
String |
getUser() |
Get the user name for this datasource.
|
boolean |
isWrapperFor(Class<?> iface) |
Since this class is not a wrapper, just check to see if this implements the requested interface.
|
void |
setConnectionCacheName(String cacheName) |
|
void |
setConnectionCacheProperties(Properties cp) |
Deprecated.
Use Oracle Universal Connection Pool instead.
|
void |
setConnectionCachingEnabled(boolean flag) |
Deprecated.
Use Oracle Universal Connection Pool instead.
|
void |
setConnectionProperties(Properties value) |
Sets the Connection Properties for the datasource
|
protected void |
setConnectionProperty(String name, String value) |
|
void |
setDatabaseName(String dbname) |
Set the name of a particular database on a server.
|
void |
setDataSourceName(String dsname) |
Set the DataSourceName.
|
void |
setDescription(String des) |
Set the Desciption for this data source instance.
|
void |
setDriverType(String dt) |
Set the JDBC driver type.
|
void |
setExplicitCachingEnabled(boolean cache) |
setExplicitCachingEnabled Sets the value of the explicitCachingEnabled property, which enables or disables the explicit cache.
|
void |
setFastConnectionFailoverEnabled(boolean flag) |
|
void |
setImplicitCachingEnabled(boolean cache) |
setImplicitCachingEnabled Sets the value of the implicitCachingEnabled property, which enables or disables the implicit cache.
|
void |
setLoginTimeout(int timeout) |
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
|
void |
setLogWriter(PrintWriter pw) |
Set the log writer for this data source.
|
void |
setMaxStatements(int max) |
Deprecated.
|
void |
setNetworkProtocol(String np) |
Set the network protocol for the connections.
|
void |
setONSConfiguration(String onsConfigStr) |
Deprecated.
Use Oracle Universal Connection Pool instead.
|
void |
setPassword(String pd) |
Set the password with which connections have to be obtained.
|
void |
setPortNumber(int pn) |
Set the port number where a server is listening for requests.
|
void |
setRoleName(String roleName) |
Sets the datasource role name.
|
void |
setServerName(String sn) |
Set the name of the Server on which database is running.
|
void |
setServiceName(String svcname) |
Set the service_name of a database on a server.
|
void |
setSSLContext(SSLContext sslContext) |
Specifies a
SSLContext to use as a factory for SSLEngine objects that carry out the TLS protocol. |
void |
setTNSEntryName(String dbname) |
Set the TNS entry name.
|
void |
setURL(String url) |
Set the URL from which connections have to be obtained.
|
void |
setUser(String userName) |
Set the user name with which connections have to be obtained.
|
protected void |
trace(String s) |
|
<T> T |
unwrap(Class<T> iface) |
Since this class is not a wrapper, just check to see if this implements the requested interface.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createShardingKeyBuilder
protected static final String DEFAULT_SERVICE_NAME
protected PrintWriter logWriter
protected int loginTimeout
protected String databaseName
protected String serviceName
protected String dataSourceName
protected String description
protected String networkProtocol
protected int portNumber
protected String user
protected oracle.jdbc.internal.OpaqueString password
protected String serverName
protected String url
protected String driverType
protected String tnsEntry
protected int maxStatements
protected boolean implicitCachingEnabled
protected boolean explicitCachingEnabled
protected boolean maxStatementsSet
protected boolean implicitCachingEnabledSet
protected boolean explicitCachingEnabledSet
protected transient oracle.jdbc.pool.OracleImplicitConnectionCache odsCache
protected transient OracleConnectionCacheManager cacheManager
protected String connCacheName
protected Properties connCacheProperties
protected Properties connectionProperties
protected boolean connCachingEnabled
protected boolean fastConnFailover
protected String onsConfigStr
public boolean isOracleDataSource
protected transient oracle.jdbc.driver.OracleDriver driver
protected static final String ENABLE_AC_SUPPORT_PROPERTY
public static final boolean TRACE
public OracleDataSource() throws SQLException
SQLException
public Connection getConnection() throws SQLException
Attempt to establish a database connection.
getConnection
in interface DataSource
SQLException
- if a database-access error occurs.public Connection getConnection(String _user, String _passwd) throws SQLException
Attempt to establish a database connection.
getConnection
in interface DataSource
user
- the database user on whose behalf the Connection is being madepassword
- the user's passwordSQLException
- if a database-access error occurs.public Connection getConnection(OracleConnectionBuilderImpl builder) throws SQLException
builder
- , builder which has the required properties set for building the connectionSQLException
- if a database-access error occurs.protected Connection getPhysicalConnection(Properties prop, GSSCredential gssCredential, SSLContext sslContext) throws SQLException
SQLException
public Connection getConnection(Properties cachedConnectionAttributes) throws SQLException
Attempt to obtain a database connection from the Implicit Connection Cache using Connection Attributes
SQLException
- if a database-access error occurs.public Connection getConnection(String _user, String _passwd, Properties cachedConnectionAttributes) throws SQLException
Attempt to obtain a database connection from the Implicit Connection Cache using user, passwd and Connection Attributes
SQLException
- if a database-access error occurs.public void close() throws SQLException
Close DataSource API. This removes the associated Connection Cache and frees resources. This must be the last method to invoke, after the user is finished using a cache enabled DataSource.
SQLException
public void setConnectionCachingEnabled(boolean flag) throws SQLException
Setter method to enable Implicit Connection Caching
flag
- boolean valueSQLException
public boolean getConnectionCachingEnabled() throws SQLException
SQLException
public void setConnectionCacheName(String cacheName) throws SQLException
SQLException
public String getConnectionCacheName() throws SQLException
SQLException
public void setConnectionCacheProperties(Properties cp) throws SQLException
Setter method to set one or more Implicit Connection Cache properties. If a null value is set, default values will take effect. Below are the list of properties supported. These are the keys (case sensitive) to be used when setting their appropriate values.
cp
- key/value pairs. Description of the supported keys follow.
Sets limit on Minimum number of connections. Defaults to 0.
Sets limit on Maximum number of connections. No default.
Sets limit on the number of initial connections populated, when the cache is first created. Defaults to 0.
Sets the Maximum number of statements that each connection keeps open, for statement caching. Defaults to 0.
Sets the Maximum time, in seconds, a connection in the cache can remain idle (that is not checked out of the cache). Defaults to 0.
Sets that maximum time, in seconds, a checked out connection can remain idle. Defaults to 0.
Sets the maximum time a checked out connection can remain unused (no SQL activity) before the connection is closed and returned to the cache. Defaults to 0.
Specifies the time limit to wait, when a new connection request arrives, and there are no connections to check out. Defaults to 0.
Sets the time interval for the cache daemon thread to enforce the time out limits. Defaults to 900 seconds (15 minutes).
Verifies each connection for validity, before a checked out connection is returned to the caller. Defaults to false.
Causes the connection cache to retrieve the connection with the closest approximation to the specified connection attributes. Defaults to false.
Sets the weight (integer) for each connection attribute. This is used when ClosestConnectionMatch is set to true, and enables retrieval of a connection with the highest combined weight of all its connection attributes. Defaults to a weight of 1.
Sets the lower threshold limit on the cache. This is used for the releaseConnection() cache callback method is registered. Defaults to 20%.
SQLException
public Properties getConnectionCacheProperties() throws SQLException
SQLException
public void setFastConnectionFailoverEnabled(boolean flag) throws SQLException
SQLException
public boolean getFastConnectionFailoverEnabled() throws SQLException
SQLException
public String getONSConfiguration() throws SQLException
Return the ONS configuration string that is used for remote ONS subscription, in the form specified in setONSConfiguration(String). This is used by Fast Connection Failover and Runtime Load Balancing.
SQLException
public void setONSConfiguration(String onsConfigStr) throws SQLException
Set the configuration string used for remote ONS subscription. The parameter string closely resembles the content of the ONS configuration file "ons.config", and contains a list of "<name>=<value>" pairs separated by newline character '\n', where <name> can be one of "nodes", "walletfile", or "walletpassword". The parameter string should at least specify the ONS configuration attribute "nodes", as a list of host:port pairs separated by comma ','. SSL would be used when the "walletfile" attribute is specified as an Oracle wallet file.
An example ONS configuration string:
"nodes=host1:4200,host2:4200\nwalletfile=wfile\nwalletpassword=wpwd"
This is used primarily by Fast Connection Failover and Runtime Load Balancing.
onsConfigStr
- The configuration string for remote ONS subscriptionSQLException
public int getLoginTimeout()
getLoginTimeout
in interface CommonDataSource
getLoginTimeout
in interface DataSource
SQLException
- if a database access error occurs.public void setLoginTimeout(int timeout)
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 DataSource object is created the login timeout is initially zero.
setLoginTimeout
in interface CommonDataSource
setLoginTimeout
in interface DataSource
seconds
- the data source login time limitSQLException
- if a database access error occurs.public void setLogWriter(PrintWriter pw)
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 the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null, in other words, logging is disabled.
setLogWriter
in interface CommonDataSource
setLogWriter
in interface DataSource
out
- the new log writer; to disable, set to nullSQLException
- if a database-access error occurs.public PrintWriter 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 the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null, in other words, logging is disabled.
getLogWriter
in interface CommonDataSource
getLogWriter
in interface DataSource
SQLException
- if a database-access error occurs.public void setTNSEntryName(String dbname)
dbname
- tns entry namepublic String getTNSEntryName()
public void setDataSourceName(String dsname)
setDataSourceName
in interface OracleCommonDataSource
dsname
- DataSource Name to be set.public String getDataSourceName()
getDataSourceName
in interface OracleCommonDataSource
public String getDatabaseName()
getDatabaseName
in interface OracleCommonDataSource
public void setDatabaseName(String dbname)
If URL is set, this property will be ignored.
setDatabaseName
in interface OracleCommonDataSource
dsname
- database name to be set.public void setServiceName(String svcname)
svcname
- service_name to be set.public String getServiceName()
public void setServerName(String sn)
setServerName
in interface OracleCommonDataSource
sn
- server/host name to be set.public String getServerName()
getServerName
in interface OracleCommonDataSource
public void setURL(String url)
setURL
in interface OracleCommonDataSource
url
- URL to be set.public String getURL() throws SQLException
getURL
in interface OracleCommonDataSource
SQLException
public void setUser(String userName)
setUser
in interface OracleCommonDataSource
user
- Username to be set.public String getUser()
getUser
in interface OracleCommonDataSource
public void setPassword(String pd)
setPassword
in interface OracleCommonDataSource
pd
- Passowrd to be set.protected String getPassword()
public String getDescription()
getDescription
in interface OracleCommonDataSource
public void setDescription(String des)
setDescription
in interface OracleCommonDataSource
des
- Desciption to be set.public String getDriverType()
public void setDriverType(String dt)
If set to kprb, nothing else is needed to open a connection. This is meant for Server side JDBC driver when running inside server.
If set to thin, serverName, portNumber and databaseName are need to open a connection.
If set to oci, and network protocol is set to IPC or TNSEntryName is set then nothing else is needed. If not, serverName, portNumber and databaseName have to be provided.
dt
- Driver Type tp be set.public String getNetworkProtocol()
getNetworkProtocol
in interface OracleCommonDataSource
public void setNetworkProtocol(String np) throws SQLException
setNetworkProtocol
in interface OracleCommonDataSource
np
- set the network protocol to be used.SQLException
public void setPortNumber(int pn)
setPortNumber
in interface OracleCommonDataSource
pn
- port number on which server is listeningpublic int getPortNumber()
getPortNumber
in interface OracleCommonDataSource
public Reference getReference() throws NamingException
getReference
in interface Referenceable
NamingException
protected void addRefProperties(Reference ref)
protected void trace(String s)
protected void copy(OracleDataSource ds) throws SQLException
SQLException
public void setMaxStatements(int max) throws SQLException
setMaxStatements
in interface OracleCommonDataSource
max
- Requested size of the cache. If the existing cache size is less than max, statements will be purged to reduce the size.SQLException
- if max < 0public int getMaxStatements() throws SQLException
getMaxStatements
in interface OracleCommonDataSource
SQLException
public void setImplicitCachingEnabled(boolean cache) throws SQLException
setImplicitCachingEnabled
in interface OracleCommonDataSource
cache
- If true, then implicit caching will be enabled. If false, then any existing statements will be purged and the implicit cache will be disabled.SQLException
public boolean getImplicitCachingEnabled() throws SQLException
getImplicitCachingEnabled
in interface OracleCommonDataSource
SQLException
public void setExplicitCachingEnabled(boolean cache) throws SQLException
setExplicitCachingEnabled
in interface OracleCommonDataSource
cache
- If true, then explicit caching will be enabled. If false, then any existing statements will be purged and the explicit cache will be disabled.SQLException
- if called on a logical connection.public boolean getExplicitCachingEnabled() throws SQLException
getExplicitCachingEnabled
in interface OracleCommonDataSource
SQLException
public void setConnectionProperties(Properties value) throws SQLException
The argument to this method is a Properties object. This properties object is used to create the connections returned by the receiver. The keys and values are Strings. The keys, values, and their meanings are defined in oracle.jdbc.OracleConnection.
setConnectionProperties
in interface OracleCommonDataSource
value
- a Properties object with the desired connection property names and values.SQLException
OracleConnection
protected String getConnectionProperty(String propertyName) throws SQLException
SQLException
protected void setConnectionProperty(String name, String value) throws SQLException
SQLException
public void setRoleName(String roleName) throws SQLException
setRoleName
in interface OracleCommonDataSource
roleName
- datasource role name to be set.SQLException
public String getRoleName()
getRoleName
in interface OracleCommonDataSource
public Properties getConnectionProperties() throws SQLException
getConnectionProperties
in interface OracleCommonDataSource
SQLException
public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
in interface Wrapper
iface
- requested interfaceSQLException
- if the arg is not an interfacepublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap
in interface Wrapper
iface
- requested interfaceSQLException
- if this does not implement the arg or the arg is not an interfacepublic Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger
in interface CommonDataSource
SQLFeatureNotSupportedException
public final void setSSLContext(SSLContext sslContext)
OracleCommonDataSource
SSLContext
to use as a factory for SSLEngine objects that carry out the TLS protocol.
The SSLContext must be initialized before establishing a connection to the data source. The certificates specified by that initialization will be used in place of any connection properties that would otherwise have specified certificates, such as key store and trust store property values.
Specifying a null value will clear any non-null value that may have been set previously, causing this data source to behave as if this method had never been called at all.
setSSLContext
in interface OracleCommonDataSource
sslContext
- An SSLContext to use as an SSLEngine factory.protected oracle.jdbc.internal.OracleConnection getConnectionDuringExceptionHandling()
public OracleConnectionBuilderImpl createConnectionBuilder()
createConnectionBuilder
in interface DataSource
createConnectionBuilder
in interface OracleDataSource
protected void debug(Logger logger, Level level, Executable method, String msg)