public interface OracleConnectionBuilder extends OracleCommonConnectionBuilder
OracleDataSource
object, used to establish a
connection to the database that the OracleDataSource
object
represents. The connection properties that were specified for the
OracleDataSource
are used as the default values by the
OracleConnectionBuilder
.
To use the builder, the corresponding builder method needs to be called for each parameter that needs to be part of the connection request followed by a build() method. The order in which the builder methods are called is not important. However if the same builder attribute is applied more than once, only the most recent value will be considered while building the connection. The builder object can be reused to build more than one connection and the builder attributes will be retained across multiple invocations of the build() method.
The following example illustrates the use of OracleConnectionBuilder
to create a OracleConnection
:
OracleDataSource ods = new oracle.jdbc.pool.OracleDataSource();
OracleShardingKey superShardingKey =
ods.createShardingKeyBuilder()
.subkey("EASTERN_REGION", JDBCType.VARCHAR)
.build();
OracleShardingKey shardingKey =
ods.createShardingKeyBuilder()
.subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR)
.build();
OracleConnection connection = ods.createConnectionBuilder()
.user("rafa")
.password("tennis")
.shardingKey(shardingKey)
.superShardingKey(superShardingKey)
.build();
Modifier and Type | Method and Description |
---|---|
OracleConnectionBuilder |
accessToken(AccessToken accessToken)
Specifies the
accessToken to be used when creating a connection. |
OracleConnection |
build()
Builds the connection object.
|
java.util.concurrent.CompletionStage<OracleConnection> |
buildAsyncOracle()
Returns a
CompletionStage that completes with a Connection
having the same state as if it were built by calling build
on this ConnectionBuilder . |
OracleConnectionBuilder |
executorOracle(java.util.concurrent.Executor executor)
Set the
Executor used for asynchronous tasks by this
ConnectionBuilder and any Connection objects built by
it. |
OracleConnectionBuilder |
gssCredential(org.ietf.jgss.GSSCredential credential)
Provide the GSSCredential used to authenticate the connection.
|
OracleConnectionBuilder |
hostnameResolver(OracleHostnameResolver hostnameResolver)
Sets a custom hostname resolver implementing
OracleHostnameResolver
used to provide a custom DNS name resolution strategy to locate the database host. |
OracleConnectionBuilder |
password(java.lang.String password) |
OracleConnectionBuilder |
radiusChallengeResponseHandler(java.util.function.Function<byte[],byte[]> radiusAuthenticationHandler)
Specifies the
Function that will be used during
the Challenge/Response phase of RADIUS authentication. |
OracleConnectionBuilder |
readOnlyInstanceAllowed(boolean readOnlyInstanceAllowed)
Sets the read-only instance allowed value on this builder.
|
OracleConnectionBuilder |
shardingKey(OracleShardingKey shardingKey) |
OracleConnectionBuilder |
sslContext(javax.net.ssl.SSLContext sslContext)
Specifies a
SSLContext to use as a factory for
SSLEngine objects that carry out the TLS
protocol. |
OracleConnectionBuilder |
superShardingKey(OracleShardingKey superShardingKey) |
OracleConnectionBuilder |
traceEventListener(TraceEventListener traceEventListener)
Configures a
TraceEventListener that receives events from
connections built by this builder. |
OracleConnectionBuilder |
user(java.lang.String user) |
OracleConnectionBuilder user(java.lang.String user)
user
- OracleConnectionBuilder
OracleConnectionBuilder password(java.lang.String password)
password
- OracleConnectionBuilder
OracleConnectionBuilder shardingKey(OracleShardingKey shardingKey)
shardingKey
- Sharding Key object that needs to be part of connection requestOracleConnectionBuilder
OracleConnectionBuilder superShardingKey(OracleShardingKey superShardingKey)
superShardingKey
- Super sharding key object that needs to be part of connection
requestOracleConnectionBuilder
OracleConnectionBuilder gssCredential(org.ietf.jgss.GSSCredential credential)
credential
- used to authenticate the connection. Not null.OracleConnectionBuilder
OracleConnectionBuilder sslContext(javax.net.ssl.SSLContext sslContext)
SSLContext
to use as a factory for
SSLEngine objects that carry out the TLS
protocol.
The SSLContext must be initialized before building the connection. 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 builder to behave as if this method had never been called at all.
sslContext
- An SSLContext to use as an SSLEngine factory. May be
null.OracleConnectionBuilder
OracleConnectionBuilder radiusChallengeResponseHandler(java.util.function.Function<byte[],byte[]> radiusAuthenticationHandler)
Function
that will be used during
the Challenge/Response phase of RADIUS authentication.
The byte[]
input is the challenge hint text that is used
while prompting the user for a response. The text is UTF-8
encoded.
The handler is expected to return the response for the challenge as byte[]
.
Challenge response handler can also be configured via connection property OracleConnection.CONNECTION_PROPERTY_THIN_NET_RADIUS_CHALLENGE_RESPONSE_HANDLER
OracleDataSource ods = new OracleDataSource(); ods.setURL(url); ods.setUser("myRadiusUser"); ods.setPassword("myRadiusPassword"); OracleConnection conn = (OracleConnection)ods.createConnectionBuilder() .radiusChallengeResponseHandler((hint) -> { // do some processing to calculate the challenge response final String response = getChallengeResponse(hint); return response.getBytes(StandardCharsets.UTF_8); }).build();
radiusAuthenticationHandler
- Radius authentication handler. May be null
.OracleConnectionBuilder
OracleConnectionBuilder traceEventListener(TraceEventListener traceEventListener)
TraceEventListener
that receives events from
connections built by this builder.traceEventListener
- Listener that receives trace events. May be
null
to disable tracing.OracleConnectionBuilder
.OracleConnectionBuilder hostnameResolver(OracleHostnameResolver hostnameResolver)
OracleHostnameResolver
used to provide a custom DNS name resolution strategy to locate the database host.hostnameResolver
- an OracleHostnameResolver to use when resolving the
datasource hostnameOracleConnectionBuilder
OracleConnectionBuilder readOnlyInstanceAllowed(boolean readOnlyInstanceAllowed)
readOnlyInstanceAllowed
- whether to allow connection creation to a read-only instance or notOracleConnectionBuilder
OracleConnectionBuilder executorOracle(java.util.concurrent.Executor executor)
Set the Executor
used for asynchronous tasks by this
ConnectionBuilder
and any Connection
objects built by
it. The default value is ForkJoinPool.commonPool()
.
Oracle JDBC implements this OracleCommonConnection
method to
return this instance of OracleConnectionBuilder
.
executorOracle
in interface OracleCommonConnectionBuilder
executor
- an Executor to use for asynchronous tasks. Not null.OracleConnectionBuilder accessToken(AccessToken accessToken)
Specifies the accessToken
to be used when creating a connection.
The issuer of the token must be one that is supported by Oracle Database
for client authentication.
It is invalid to configure this builder with both a token and with
a username or password. If both this method and password(String)
or user(String)
are invoked with non null values, then a
SQLException
indicating an invalid configuration is thrown when
creating a connection with this builder.
accessToken
- the token to use for this connection. Not null
.ConnectionBuilder
instancejava.lang.NullPointerException
- If the accessToken
is null
.java.util.concurrent.CompletionStage<OracleConnection> buildAsyncOracle() throws java.sql.SQLException
CompletionStage
that completes with a Connection
having the same state as if it were built by calling build
on this ConnectionBuilder
.
The returned stage is completed exceptionally with a SQLException
if a failure occurs when building the Connection
.
CompletionStage
that completes with a Connection
built by this ConnectionBuilder
java.sql.SQLException
OracleConnection build() throws java.sql.SQLException
OracleConnection
that is created.java.sql.SQLException