Class OracleDataSource

  • All Implemented Interfaces:
    Serializable, Wrapper, Referenceable, CommonDataSource, DataSource, OracleCommonDataSource, OracleDataSource, oracle.jdbc.internal.Monitor, oracle.jdbc.replay.internal.OracleDataSource, OracleDataSource
    Direct Known Subclasses:
    OracleConnectionPoolDataSource, OracleDataSource, OracleDataSourceImpl

    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();
      
      

    Since:
    20c
    See Also:
    Serialized Form
    • Field Detail

      • loginTimeout

        protected int loginTimeout
      • databaseName

        protected String databaseName
      • serviceName

        protected String serviceName
      • dataSourceName

        protected String dataSourceName
      • description

        protected String description
      • networkProtocol

        protected String networkProtocol
      • portNumber

        protected int portNumber
      • password

        protected oracle.jdbc.internal.OpaqueString password
      • serverName

        protected String serverName
      • driverType

        protected String driverType
      • tnsEntry

        protected String tnsEntry
      • maxStatements

        protected int maxStatements
      • implicitCachingEnabled

        protected boolean implicitCachingEnabled
      • explicitCachingEnabled

        protected boolean explicitCachingEnabled
      • maxStatementsSet

        protected boolean maxStatementsSet
      • implicitCachingEnabledSet

        protected boolean implicitCachingEnabledSet
      • explicitCachingEnabledSet

        protected boolean explicitCachingEnabledSet
      • connectionProperties

        protected Properties connectionProperties
      • isOracleDataSource

        public boolean isOracleDataSource
      • driver

        protected transient oracle.jdbc.driver.OracleDriver driver
      • reconnectDelay

        protected int reconnectDelay
      • reconnectRetries

        protected int reconnectRetries
      • FAILOVER_TYPE_TRANSACTION

        protected static final int FAILOVER_TYPE_TRANSACTION
        See Also:
        Constant Field Values
      • SESSION_STATE_CONSISTENCY_STATIC

        protected static final int SESSION_STATE_CONSISTENCY_STATIC
        See Also:
        Constant Field Values
      • isTransactionReplayEnabled

        protected boolean isTransactionReplayEnabled
      • isAutoACEnabled

        protected boolean isAutoACEnabled
      • isReplayInDynamicMode

        protected boolean isReplayInDynamicMode
      • FAILOVER_RESTORE_NONE

        protected static final int FAILOVER_RESTORE_NONE
        See Also:
        Constant Field Values
      • FAILOVER_RESTORE_LEVEL1

        protected static final int FAILOVER_RESTORE_LEVEL1
        See Also:
        Constant Field Values
      • FAILOVER_RESTORE_LEVEL2

        protected static final int FAILOVER_RESTORE_LEVEL2
        See Also:
        Constant Field Values
      • FAILOVER_RESTORE_AUTO

        protected static final int FAILOVER_RESTORE_AUTO
        See Also:
        Constant Field Values
      • stateRestorationType

        protected oracle.jdbc.replay.internal.ReplayableConnection.StateRestorationType stateRestorationType
      • isStateRestorationAuto

        protected boolean isStateRestorationAuto
      • replayInitiationTimeout

        protected int replayInitiationTimeout
      • clientChecksum12x

        protected final String clientChecksum12x
      • clientChecksum11203x

        protected final String clientChecksum11203x
      • doneDumpOnMemoryPressure

        protected AtomicBoolean doneDumpOnMemoryPressure
    • Method Detail

      • getConnection

        public Connection getConnection​(String user,
                                        String password)
                                 throws SQLException

        Attempt to establish a database connection.

        Specified by:
        getConnection in interface DataSource
        Parameters:
        user - the database user on whose behalf the Connection is being made
        password - the user's password
        Returns:
        a Connection to the database
        Throws:
        SQLException - if a database-access error occurs.
      • getConnection

        protected Connection getConnection​(String _user,
                                           oracle.jdbc.internal.OpaqueString _passwd)
                                    throws SQLException

        Attempt to establish a database connection.

        Parameters:
        _user - the database user on whose behalf the Connection is being made
        _passwd - the user's password
        Returns:
        a Connection to the database
        Throws:
        SQLException - if a database-access error occurs.
      • getConnection

        protected Connection getConnection​(OracleConnectionBuilderImpl builder)
                                    throws SQLException

        Attempt to establish a database connection.

        Parameters:
        builder - Builder which has the required properties set for building the connection
        Returns:
        a Connection to the database
        Throws:
        SQLException - if a database-access error occurs.
      • getPhysicalConnection

        protected Connection getPhysicalConnection​(Properties prop,
                                                   oracle.jdbc.internal.AbstractConnectionBuilder builder)
                                            throws SQLException
        Get a connection to the database specified by this datasource.
        Parameters:
        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.
        Returns:
        A database connection
        Throws:
        SQLException
      • getLoginTimeout

        public int getLoginTimeout()
        Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise it means that there is no timeout. When a DataSource object is created the login timeout is initially zero.
        Specified by:
        getLoginTimeout in interface CommonDataSource
        Specified by:
        getLoginTimeout in interface DataSource
        Returns:
        the data source login time limit
        Throws:
        SQLException - if a database access error occurs.
      • setLoginTimeout

        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.

        Specified by:
        setLoginTimeout in interface CommonDataSource
        Specified by:
        setLoginTimeout in interface DataSource
        Parameters:
        seconds - the data source login time limit
        Throws:
        SQLException - if a database access error occurs.
      • setLogWriter

        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.

        Specified by:
        setLogWriter in interface CommonDataSource
        Specified by:
        setLogWriter in interface DataSource
        Parameters:
        out - the new log writer; to disable, set to null
        Throws:
        SQLException - if a database-access error occurs.
      • getLogWriter

        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.

        Specified by:
        getLogWriter in interface CommonDataSource
        Specified by:
        getLogWriter in interface DataSource
        Returns:
        the log writer for this data source, null if disabled
        Throws:
        SQLException - if a database-access error occurs.
      • setTNSEntryName

        public void setTNSEntryName​(String dbname)
        Set the TNS entry name. Works only for JDBC OCI driver. Assumed that client side Oracle in installed and TNS_ADMIN env variable is set. If URL is set, this property will be ignored.

        Parameters:
        dbname - tns entry name
      • getTNSEntryName

        public String getTNSEntryName()
        Get the TNS entry name for this instance if set. Returns null if not set.
        Returns:
        TNS entry name
      • setDataSourceName

        public void setDataSourceName​(String dsname)
        Set the DataSourceName. Users need not set this as it will be set set automatically depending upon the instance created. Returns OracleDataSource for an OracleDataSource instance. Returns OracleXADataSource for an OracleXADataSource instance.

        Specified by:
        setDataSourceName in interface OracleCommonDataSource
        Parameters:
        dsname - DataSource Name to be set.
      • getDataSourceName

        public String getDataSourceName()
        Get the datasource name for this instance if set. Returns null if not set.
        Specified by:
        getDataSourceName in interface OracleCommonDataSource
        Returns:
        DaraSource name
      • getDatabaseName

        public String getDatabaseName()
        Get the name of the database set on this DataSource instance.
        Specified by:
        getDatabaseName in interface OracleCommonDataSource
        Returns:
        database name set on this instance or null if not set.
      • setDatabaseName

        public void setDatabaseName​(String dbname)
        Set the name of a particular database on a server. In Oracle's jargon this is called SID (System Identifier).

        If URL is set, this property will be ignored.

        Specified by:
        setDatabaseName in interface OracleCommonDataSource
        Parameters:
        dsname - database name to be set.
      • setServiceName

        public void setServiceName​(String svcname)
        Set the service_name of a database on a server. If URL is set, this property will be ignored. To distinguish services from instances, a new URL using service_name is added, existing url with SID will be supported, but deprecated.
        Parameters:
        svcname - service_name to be set.
      • getServiceName

        public 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.
        Returns:
        service_name assiciated with the instance or null if not set.
      • setServerName

        public void setServerName​(String sn)
        Set the name of the Server on which database is running. If URL is set, this property will be ignored.

        Specified by:
        setServerName in interface OracleCommonDataSource
        Parameters:
        sn - server/host name to be set.
      • getServerName

        public String getServerName()
        Get the name of the server on which database is running.
        Specified by:
        getServerName in interface OracleCommonDataSource
        Returns:
        server name set on this instance or null if not set.
      • setURL

        public void setURL​(String url)
        Set the URL from which connections have to be obtained. If URL is set all other properties like databasename, servername, portNumber, network protocol, tnsentry, and driver Type will be ignored.

        Specified by:
        setURL in interface OracleCommonDataSource
        Parameters:
        url - URL to be set.
      • setUser

        public void setUser​(String userName)
        Set the user name with which connections have to be obtained.

        Specified by:
        setUser in interface OracleCommonDataSource
        Parameters:
        user - Username to be set.
      • getUser

        public String getUser()
        Get the user name for this datasource. Will return the default value ("scott") if not set before.
        Specified by:
        getUser in interface OracleCommonDataSource
      • setPassword

        public void setPassword​(String pd)
        Set the password with which connections have to be obtained. The default value is "tiger".

        Specified by:
        setPassword in interface OracleCommonDataSource
        Parameters:
        pd - Passowrd to be set.
      • getPassword

        protected oracle.jdbc.internal.OpaqueString getPassword()
      • getDescription

        public String getDescription()
        Get the Desciption of this data source.
        Specified by:
        getDescription in interface OracleCommonDataSource
        Returns:
        Description that was set or will return null if not set.
      • setDescription

        public void setDescription​(String des)
        Set the Desciption for this data source instance.
        Specified by:
        setDescription in interface OracleCommonDataSource
        Parameters:
        des - Desciption to be set.
      • getDriverType

        public String getDriverType()
        Get the Oracle JDBC driver type set for this datasource instance
        Returns:
        Driver Type that was set or null if not set.
      • setDriverType

        public void setDriverType​(String dt)
        Set the JDBC driver type. Possible values are thin, oci8, and kprb. If URL is set, this property will be ignored.

        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.

        Parameters:
        dt - Driver Type tp be set.
      • setNetworkProtocol

        public void setNetworkProtocol​(String np)
                                throws SQLException
        Set the network protocol for the connections. Default is "tcp". Can be set to all possible protocols Net8 supports. Only needed for JDBC OCI driver.

        Specified by:
        setNetworkProtocol in interface OracleCommonDataSource
        Parameters:
        np - set the network protocol to be used.
        Throws:
        SQLException
      • setPortNumber

        public void setPortNumber​(int pn)
        Set the port number where a server is listening for requests. Not required when URL is set.
        Specified by:
        setPortNumber in interface OracleCommonDataSource
        Parameters:
        pn - port number on which server is listening
      • getPortNumber

        public int getPortNumber()
        Get the port number on which server is listening for requests.
        Specified by:
        getPortNumber in interface OracleCommonDataSource
        Returns:
        port number if set or null if not set.
      • addRefProperties

        protected void addRefProperties​(Reference ref)
      • trace

        protected void trace​(String s)
      • setMaxStatements

        public void setMaxStatements​(int max)
                              throws SQLException
        Deprecated.
        setMaxStatements Specifies the value of the maxStatements property. This will be the size of the application cache (which will be used by both implicit and explicit caching). This value does not apply to the statement cache size of connections created by ImplicitStatementCache for which the cache size is set through java.util.Properties object.
        Specified by:
        setMaxStatements in interface OracleCommonDataSource
        Specified by:
        setMaxStatements in interface OracleDataSource
        Parameters:
        max - Requested size of the cache. If the existing cache size is less than max, statements will be purged to reduce the size.
        Throws:
        SQLException - if max < 0
      • setImplicitCachingEnabled

        public void setImplicitCachingEnabled​(boolean cache)
                                       throws SQLException
        setImplicitCachingEnabled Sets the value of the implicitCachingEnabled property, which enables or disables the implicit cache. Note that this is independent of the cache size, set with setMaxStatements().
        Specified by:
        setImplicitCachingEnabled in interface OracleCommonDataSource
        Specified by:
        setImplicitCachingEnabled in interface OracleDataSource
        Parameters:
        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.
        Throws:
        SQLException
      • setExplicitCachingEnabled

        public void setExplicitCachingEnabled​(boolean cache)
                                       throws SQLException
        setExplicitCachingEnabled Sets the value of the explicitCachingEnabled property, which enables or disables the explicit cache. Note that this is independent of the cache size, set with setMaxStatements().
        Specified by:
        setExplicitCachingEnabled in interface OracleCommonDataSource
        Specified by:
        setExplicitCachingEnabled in interface OracleDataSource
        Parameters:
        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.
        Throws:
        SQLException - if called on a logical connection.
      • setConnectionProperties

        public void setConnectionProperties​(Properties properties)
                                     throws SQLException
        Sets the Connection Properties for the datasource

        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.

        Specified by:
        setConnectionProperties in interface OracleCommonDataSource
        Parameters:
        properties - a Properties object with the desired connection property names and values.
        Throws:
        SQLException
        See Also:
        OracleConnection
      • getConnectionProperties

        public Properties getConnectionProperties()
                                           throws SQLException
        Gets the connection properties that are set on this data source object. These exclude any sensitive property with "password" in its name (case-insensitive); for example, "password", "oracle.net.websocketPassword", etc.
        Specified by:
        getConnectionProperties in interface OracleCommonDataSource
        Returns:
        A java.util.Properties object containing all the connection properties set on this data source object, excluding all sensitive properties described above. Null if there are no such connection properties set.
        Throws:
        SQLException - If any exception occurs while getting the connection properties.
      • getConnectionProperty

        public String getConnectionProperty​(String propertyName)
                                     throws SQLException
        Gets the specified connection property that is set on this data source. Any sensitive property with "password" in its name (case-insensitive, for example, "password", "oracle.net.websocketPassword", etc.) is treated as if that property were not set.
        Specified by:
        getConnectionProperty in interface OracleCommonDataSource
        Parameters:
        propertyName - The name of the specified connection property.
        Returns:
        The String value of the specified connection property. Null if there is no such connection property set, or the specified connection property has "password" in its name.
        Throws:
        SQLException - If any exception occurs while getting the connection property.
      • isWrapperFor

        public boolean isWrapperFor​(Class<?> iface)
                             throws SQLException
        Since this class is not a wrapper, just check to see if this implements the requested interface.
        Specified by:
        isWrapperFor in interface Wrapper
        Parameters:
        iface - requested interface
        Returns:
        true iff this implements the requested interface
        Throws:
        SQLException - if the arg is not an interface
        Since:
        JDBC 4.0
      • unwrap

        public <T> T unwrap​(Class<T> iface)
                     throws SQLException
        Since this class is not a wrapper, just check to see if this implements the requested interface. If it does return this.
        Specified by:
        unwrap in interface Wrapper
        Parameters:
        iface - requested interface
        Returns:
        this iff this implements the requested interface
        Throws:
        SQLException - if this does not implement the arg or the arg is not an interface
        Since:
        JDBC 4.0
      • setSSLContext

        public final void setSSLContext​(SSLContext sslContext)
        Description copied from interface: OracleCommonDataSource
        Specifies a 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.

        Specified by:
        setSSLContext in interface OracleCommonDataSource
        Parameters:
        sslContext - An SSLContext to use as an SSLEngine factory.
      • getConnectionDuringExceptionHandling

        protected oracle.jdbc.internal.OracleConnection getConnectionDuringExceptionHandling()
      • setupACSpecificProperties

        protected void setupACSpecificProperties​(boolean useProxy)
                                          throws SQLException
        Throws:
        SQLException
      • registerConnectionInitializationCallback

        public void registerConnectionInitializationCallback​(oracle.jdbc.replay.internal.ConnectionInitializationCallback cbk)
                                                      throws SQLException
        Registers a ConnectionInitializationCallback with the data source.
        Specified by:
        registerConnectionInitializationCallback in interface OracleDataSource
        Parameters:
        cbk - The ConnectionInitializationCallback to be registered.
        Throws:
        SQLException - If the argument is null or callback registration fails.
      • unregisterConnectionInitializationCallback

        public void unregisterConnectionInitializationCallback​(oracle.jdbc.replay.internal.ConnectionInitializationCallback cbk)
                                                        throws SQLException
        Removes the ConnectionInitializationCallback registered with the data source, if any.
        Specified by:
        unregisterConnectionInitializationCallback in interface OracleDataSource
        Parameters:
        cbk - The ConnectionInitializationCallback object to be unregistered.
        Throws:
        SQLException - If callback removal fails.
      • getConnectionInitializationCallback

        public oracle.jdbc.replay.internal.ConnectionInitializationCallback getConnectionInitializationCallback()
        Description copied from interface: OracleDataSource
        Obtains the registered connection initialization callback, if any.
        Specified by:
        getConnectionInitializationCallback in interface OracleDataSource
        Returns:
        The registered ConnectionInitializationCallback, or null if there is no callback registered.
      • getReplayStatistics

        public ReplayStatistics getReplayStatistics()
        Description copied from interface: OracleDataSource
        Obtains replay statistics accumulated so far. These reflect replay actions across all the connections created by this data source. It is recommended that this call be made when the connections are quiescent and there are few new connections being opened.
        Specified by:
        getReplayStatistics in interface OracleDataSource
        Returns:
        A replay statistics object containing all the metrics.
      • clearDoneDumpOnMemoryPressure

        public void clearDoneDumpOnMemoryPressure()
        Specified by:
        clearDoneDumpOnMemoryPressure in interface oracle.jdbc.replay.internal.OracleDataSource
      • getReplayStatisticsString

        public String getReplayStatisticsString()
        Specified by:
        getReplayStatisticsString in interface oracle.jdbc.replay.internal.OracleDataSource
      • clearReplayStatistics

        public void clearReplayStatistics()
        Description copied from interface: OracleDataSource
        Clears replay statistics accumulated so far on all connection created by this data source. It is recommended that this call be made when the connections are quiescent and there are few new connections being opened.
        Specified by:
        clearReplayStatistics in interface OracleDataSource
      • updateReplayStatistics

        public void updateReplayStatistics​(oracle.jdbc.replay.internal.ReplayStatistics newStats)
        Specified by:
        updateReplayStatistics in interface oracle.jdbc.replay.internal.OracleDataSource
      • getSystemProperty

        protected static String getSystemProperty​(String property,
                                                  String defaultValue)
      • getRequestSizeLimit

        public int getRequestSizeLimit()
                                throws SQLException
        Specified by:
        getRequestSizeLimit in interface oracle.jdbc.replay.internal.OracleDataSource
        Throws:
        SQLException
      • getProxyFactory

        public oracle.jdbc.proxy.ProxyFactory getProxyFactory()
                                                       throws SQLException
        Specified by:
        getProxyFactory in interface oracle.jdbc.replay.internal.OracleDataSource
        Throws:
        SQLException
      • registerMBean

        public static void registerMBean()
      • unregisterMBean

        public static void unregisterMBean()
      • cleanup

        public static void cleanup()
      • getMonitorLock

        public final oracle.jdbc.internal.Monitor.CloseableLock getMonitorLock()
        Specified by:
        getMonitorLock in interface oracle.jdbc.internal.Monitor