By using the data source feature in combination with Java Naming and Directory Interface (JNDI), you do not need to register the JDBC driver class name specified by the vendor, and you can use logical names for URLs and other properties. This ensures that the code used to open database connections can be migrated to other environments.
DataSource interface
JDBC data sources are instances that implement the standard javax.sql.DataSource interface class, for example:
public interface DataSource
{
Connection getConnection() throws SQLException;
Connection getConnection(String username, String password)
throws SQLException;
...
}
OceanBase Database uses the OceanBaseDataSource class in the ocanbase.jdbc.pool software package to implement this interface. The overloaded getConnection method returns a connection to the database.
To use other values, you can use the corresponding Setter method to set related properties. You can input alternate usernames and passwords to the getConnection method, which has higher priority over property settings.
DataSource properties
Same as the DataSource interface class, the OceanBaseDataSource class provides a set of properties that specify the database to connect to. These properties follow the JavaBeans design pattern.
The following table describes the standard properties in OceanBaseDataSource in accordance with the Sun Microsystems specification.
| Name | Type | Description |
|---|---|---|
| databaseName | String | The name of the specified database on the server. |
| dataSourceName | String | The name of the underlying data source class. For connection pools, this is the data source class of underlying pooled connections. For distributed transactions, this is an underlying XA data source class. |
| description | String | The description of the data source. |
| networkProtocol | String | The network protocol for communication with the server. |
| password | String | The password of the logon user. |
| portNumber | int | The port number on which the server listens for requests. |
| serverName | String | The name of the database server. |
| user | String | The logon user name. |
The following table describes the extended properties in OceanBaseDataSource.
| Name | Type | Description |
|---|---|---|
| connectionCacheName | String | The name of the cache. The cache name cannot be changed after the cache is created. |
| connectionCacheProperties | java.util.Properties | The properties of the implicit connection cache. |
| connectionCachingEnabled | Boolean | Specifies whether to to use the implicit connection cache. |
| connectionProperties | java.util.Properties | The properties of the connection. |
| driverType | String | The JDBC driver type. |
| fastConnectionFailoverEnabled | Boolean | Specifies whether to use fast connection failover. |
| implicitCachingEnabled | Boolean | Specifies whether to enable the implicit connection cache. |
| loginTimeout | int | The maximum amount of time (in seconds) that the data source will wait when it attempts to connect to the database. |
| logWriter | java.io.PrintWriter | The log writer for the data source. |
| maxStatements | int | The maximum number of statements in the application cache. |
| serviceName | String | The database service name of the data source. |
| tnsEntry | String | The TNS entry name. The Transparent Network Substrate (TNS) entry name corresponds to the TNS entry specified in the tnsnames.ora configuration file. |
| url | String | The URL of the database connection string. You can use this property to replace the tnsEntry and driverType properties and the standard portNumber, networkProtocol, serverName, and databaseName properties. |
| ONSConfiguration | String | The Oracle Notification Service (ONS) configuration string used for remote subscription of FAN/ONS events. |
You can use the setConnectionProperties method to set the properties of the connection and use the setConnectionCacheProperties method to set the properties of the connection cache. In addition, getConnectionCacheName() returns the cache name only when the ConnectionCacheName property is set for the data source after the cache is enabled for the data source.