public class OracleDataSource extends Object implements OracleDataSource, oracle.jdbc.replay.internal.OracleDataSource, Serializable, Referenceable, oracle.jdbc.internal.Monitor
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
.
This data Source supports Application Continuity (AC) and
transparent JDBC operation replay upon a failover. To disable
such feature, set "oracle.jdbc.enableACSupport"
to false either
as a Java system property, or as a connection property on this
data source.
The following example illustrates the use of this data source to create a JDBC connection:
oracle.jdbc.datasource.OracleDataSource ods =
new oracle.jdbc.datasource.impl.OracleDataSource();
ods.setURL("jdbc:oracle:thin:@//dbhost:dbport/dbservice");
ods.setUser("User");
ods.setPassword("Passwd");
ods.setConnectionProperty("connProp1", "value1");
ods.setConnectionProperty("connProp2", "value2");
Connection conn = ods.getConnection();
The following example illustrates the use of a connection obtained from this data source for Application Continuity protection:
oracle.jdbc.OracleConnection conn =
(oracle.jdbc.OracleConnection) ods.getConnection();
conn.beginRequest();
...... // JDBC calls protected by AC
conn.endRequest();
CONNECTION_PROPERTIES, DATA_SOURCE_NAME, DATABASE_NAME, DESCRIPTION, EXPLICIT_CACHING_ENABLED, IMPLICIT_CACHING_ENABLED, MAX_STATEMENTS, NETWORK_PROTOCOL, PASSWORD, PORT_NUMBER, ROLE_NAME, SERVER_NAME, URL, USER
Constructor and Description |
---|
OracleDataSource() |
Modifier and Type | Method and Description |
---|---|
protected void |
addRefProperties(Reference ref) |
static void |
cleanup() |
void |
clearDoneDumpOnMemoryPressure() |
void |
clearReplayStatistics()
Clears replay statistics accumulated so far on all connection
created by this data source.
|
OracleConnectionBuilderImpl |
createConnectionBuilder()
Creates a new instance
|
protected void |
debug(Logger logger,
Level level,
Executable method,
String msg)
AC specifc
|
protected Connection |
enableACAndProxifyIfNecessary(Connection conn,
OracleConnectionBuilderImpl connBuilder) |
Connection |
getConnection()
Attempt to establish a database connection.
|
Connection |
getConnection(OracleConnectionBuilderImpl builder) |
protected Connection |
getConnection(String _user,
oracle.jdbc.internal.OpaqueString _passwd)
Attempt to establish a database connection.
|
Connection |
getConnection(String user,
String password)
Attempt to establish a database connection.
|
protected oracle.jdbc.internal.OracleConnection |
getConnectionDuringExceptionHandling() |
oracle.jdbc.replay.internal.ConnectionInitializationCallback |
getConnectionInitializationCallback()
Obtains the registered connection initialization callback, if any.
|
Connection |
getConnectionNoProxy(OracleConnectionBuilderImpl connBuilder) |
Properties |
getConnectionProperties()
Gets the connection properties that are set on this data source object.
|
String |
getConnectionProperty(String propertyName)
Gets the specified connection property that is set on this data source.
|
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 |
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.
|
oracle.jdbc.internal.Monitor.CloseableLock |
getMonitorLock() |
String |
getNetworkProtocol()
Get the network protocol set.
|
Logger |
getParentLogger() |
protected oracle.jdbc.internal.OpaqueString |
getPassword() |
protected Connection |
getPhysicalConnection(Properties prop,
oracle.jdbc.internal.AbstractConnectionBuilder builder)
Get a connection to the database specified by this datasource.
|
int |
getPortNumber()
Get the port number on which server is listening for requests.
|
oracle.jdbc.proxy.ProxyFactory |
getProxyFactory() |
Reference |
getReference() |
ReplayStatistics |
getReplayStatistics()
Obtains replay statistics accumulated so far.
|
String |
getReplayStatisticsString() |
int |
getRequestSizeLimit() |
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.
|
protected static String |
getSystemProperty(String property,
String defaultValue) |
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.
|
protected void |
makeURL() |
void |
registerConnectionInitializationCallback(oracle.jdbc.replay.internal.ConnectionInitializationCallback cbk)
Registers a ConnectionInitializationCallback with the data source.
|
static void |
registerMBean() |
void |
setConnectionProperties(Properties properties)
Sets the Connection Properties for the datasource
|
void |
setConnectionProperty(String name,
String value)
Sets a connection property on the data source.
|
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 |
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 |
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 |
setSingleShardTransactionSupport(boolean allow)
Sets single shard transaction support in auto commit OFF mode.
|
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.
|
protected void |
setupACSpecificProperties(boolean useProxy) |
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) |
void |
unregisterConnectionInitializationCallback(oracle.jdbc.replay.internal.ConnectionInitializationCallback cbk)
Removes the ConnectionInitializationCallback registered with the
data source, if any.
|
static void |
unregisterMBean() |
<T> T |
unwrap(Class<T> iface)
Since this class is not a wrapper, just check to see if this
implements the requested interface.
|
void |
updateReplayStatistics(oracle.jdbc.replay.internal.ReplayStatistics newStats) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setExecutorService
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 Properties connectionProperties
public boolean isOracleDataSource
protected transient oracle.jdbc.driver.OracleDriver driver
protected AtomicBoolean isFirstConnection
protected static final String RECONNECT_DELAY_PROPERTY
protected static final String RECONNECT_RETRIES_PROPERTY
protected int reconnectDelay
protected int reconnectRetries
protected static final String FAILOVER_TYPE_PROPERTY
protected static final int FAILOVER_TYPE_TRANSACTION
protected static final int SESSION_STATE_CONSISTENCY_STATIC
protected static final int FAILOVER_TYPE_AUTO
protected boolean isTransactionReplayEnabled
protected boolean isAutoACEnabled
protected static final String SESSION_STATE_PROPERTY
protected boolean isReplayInDynamicMode
protected static final String FAILOVER_RESTORE_PROPERTY
protected static final int FAILOVER_RESTORE_NONE
protected static final int FAILOVER_RESTORE_LEVEL1
protected static final int FAILOVER_RESTORE_LEVEL2
protected static final int FAILOVER_RESTORE_AUTO
protected oracle.jdbc.replay.internal.ReplayableConnection.StateRestorationType stateRestorationType
protected boolean isStateRestorationAuto
protected static final String INITIATION_TIMEOUT_PROPERTY
protected int replayInitiationTimeout
protected static final String CHECKSUM_PROPERTY
protected final String clientChecksum12x
protected final String clientChecksum11203x
protected static final String IGNORE_AC_CONTEXT_PROPERTY
protected static final String ENABLE_AC_SUPPORT_PROPERTY
protected static final String REQUEST_SIZE_LIMIT_PROPERTY
protected AtomicBoolean doneDumpOnMemoryPressure
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 password) 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.protected Connection getConnection(String _user, oracle.jdbc.internal.OpaqueString _passwd) throws SQLException
Attempt to establish a database connection.
_user
- the database user on whose behalf the Connection is
being made_passwd
- 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, oracle.jdbc.internal.AbstractConnectionBuilder builder) throws SQLException
prop
- Connection properties specified on this datasource.builder
- The builder object used to create the connection.
May be null if a builder was not used to create the connection.SQLException
public int getLoginTimeout()
getLoginTimeout
in interface CommonDataSource
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
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
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
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 oracle.jdbc.internal.OpaqueString 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 makeURL() throws SQLException
SQLException
protected void trace(String s)
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 properties) 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
properties
- a Properties object with the desired connection property names
and values.SQLException
OracleConnection
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
- If any exception occurs while getting the connection
properties.public String getConnectionProperty(String propertyName) throws SQLException
getConnectionProperty
in interface OracleCommonDataSource
propertyName
- The name of the specified connection property.SQLException
- If any exception occurs while getting the connection
property.public void setConnectionProperty(String name, String value) throws SQLException
setConnectionProperty
in interface OracleCommonDataSource
name
- The name of the connection property to be set.value
- The value of the connection property to be set.SQLException
- If any exception occurred while setting the connection
property.setConnectionProperties
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.public void setSingleShardTransactionSupport(boolean allow) throws SQLException
OracleCommonDataSource
setSingleShardTransactionSupport
in interface OracleCommonDataSource
SQLException
protected oracle.jdbc.internal.OracleConnection getConnectionDuringExceptionHandling()
public OracleConnectionBuilderImpl createConnectionBuilder()
createConnectionBuilder
in interface OracleDataSource
public Connection getConnectionNoProxy(OracleConnectionBuilderImpl connBuilder) throws SQLException
SQLException
protected void setupACSpecificProperties(boolean useProxy) throws SQLException
SQLException
protected Connection enableACAndProxifyIfNecessary(Connection conn, OracleConnectionBuilderImpl connBuilder) throws SQLException
SQLException
public void registerConnectionInitializationCallback(oracle.jdbc.replay.internal.ConnectionInitializationCallback cbk) throws SQLException
cbk
- The ConnectionInitializationCallback to be registered.SQLException
- If the argument is null or callback
registration fails.public void unregisterConnectionInitializationCallback(oracle.jdbc.replay.internal.ConnectionInitializationCallback cbk) throws SQLException
cbk
- The ConnectionInitializationCallback
object to be unregistered.SQLException
- If callback removal fails.public oracle.jdbc.replay.internal.ConnectionInitializationCallback getConnectionInitializationCallback()
OracleDataSource
ConnectionInitializationCallback
,
or null if there is no callback registered.public ReplayStatistics getReplayStatistics()
OracleDataSource
public void clearDoneDumpOnMemoryPressure()
public String getReplayStatisticsString()
public void clearReplayStatistics()
OracleDataSource
public void updateReplayStatistics(oracle.jdbc.replay.internal.ReplayStatistics newStats)
public int getRequestSizeLimit() throws SQLException
SQLException
public oracle.jdbc.proxy.ProxyFactory getProxyFactory() throws SQLException
SQLException
public static void registerMBean()
public static void unregisterMBean()
public static void cleanup()
protected void debug(Logger logger, Level level, Executable method, String msg)
public final oracle.jdbc.internal.Monitor.CloseableLock getMonitorLock()
getMonitorLock
in interface oracle.jdbc.internal.Monitor