Interface OracleConnectionBuilder
-
- All Superinterfaces:
java.sql.ConnectionBuilder,OracleCommonConnectionBuilder
- All Known Implementing Classes:
OracleConnectionBuilderImpl
public interface OracleConnectionBuilder extends OracleCommonConnectionBuilder
A builder created from aOracleDataSourceobject, used to establish a connection to the database that theOracleDataSourceobject represents. The connection properties that were specified for theOracleDataSourceare used as the default values by theOracleConnectionBuilder.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
OracleConnectionBuilderto create aOracleConnection: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();- Since:
- 12.2
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description OracleConnectionBuilderaccessToken(AccessToken accessToken)Specifies theaccessTokento be used when creating a connection.OracleConnectionbuild()Builds the connection object.java.util.concurrent.CompletionStage<OracleConnection>buildAsyncOracle()Returns aCompletionStagethat completes with aConnectionhaving the same state as if it were built by callingbuildon thisConnectionBuilder.java.util.concurrent.Flow.Publisher<OracleConnection>buildConnectionPublisherOracle()Returns aPublisherthat publishes a singleConnectionobject with the same state as if it were built by callingbuildon thisConnectionBuilder.OracleConnectionBuilderexecutorOracle(java.util.concurrent.Executor executor)Set theExecutorused for asynchronous tasks by thisConnectionBuilderand anyConnectionobjects built by it.OracleConnectionBuildergssCredential(org.ietf.jgss.GSSCredential credential)Provide the GSSCredential used to authenticate the connection.OracleConnectionBuilderhostnameResolver(OracleHostnameResolver hostnameResolver)Sets a custom hostname resolver implementingOracleHostnameResolverused to provide a custom DNS name resolution strategy to locate the database host.OracleConnectionBuilderpassword(java.lang.String password)OracleConnectionBuilderradiusChallengeResponseHandler(java.util.function.Function<byte[],byte[]> radiusAuthenticationHandler)Specifies theFunctionthat will be used during the Challenge/Response phase of RADIUS authentication.OracleConnectionBuilderreadOnlyInstanceAllowed(boolean readOnlyInstanceAllowed)Sets the read-only instance allowed value on this builder.OracleConnectionBuildershardingKey(java.sql.ShardingKey shardingKey)OracleConnectionBuildershardingKey(OracleShardingKey shardingKey)OracleConnectionBuildersslContext(javax.net.ssl.SSLContext sslContext)Specifies aSSLContextto use as a factory for SSLEngine objects that carry out the TLS protocol.OracleConnectionBuildersuperShardingKey(java.sql.ShardingKey superShardingKey)OracleConnectionBuildersuperShardingKey(OracleShardingKey superShardingKey)OracleConnectionBuildertraceEventListener(TraceEventListener traceEventListener)Configures aTraceEventListenerthat receives events from connections built by this builder.OracleConnectionBuilderuser(java.lang.String user)
-
-
-
Method Detail
-
user
OracleConnectionBuilder user(java.lang.String user)
- Specified by:
userin interfacejava.sql.ConnectionBuilder- Parameters:
user-- Returns:
- This
OracleConnectionBuilder
-
password
OracleConnectionBuilder password(java.lang.String password)
- Specified by:
passwordin interfacejava.sql.ConnectionBuilder- Parameters:
password-- Returns:
- This
OracleConnectionBuilder
-
shardingKey
OracleConnectionBuilder shardingKey(OracleShardingKey shardingKey)
- Parameters:
shardingKey- Sharding Key object that needs to be part of connection request- Returns:
- This
OracleConnectionBuilder
-
superShardingKey
OracleConnectionBuilder superShardingKey(OracleShardingKey superShardingKey)
- Parameters:
superShardingKey- Super sharding key object that needs to be part of connection request- Returns:
- This
OracleConnectionBuilder
-
shardingKey
OracleConnectionBuilder shardingKey(java.sql.ShardingKey shardingKey)
- Specified by:
shardingKeyin interfacejava.sql.ConnectionBuilder- Parameters:
shardingKey- Sharding Key object that needs to be part of connection request- Returns:
- This
OracleConnectionBuilder
-
superShardingKey
OracleConnectionBuilder superShardingKey(java.sql.ShardingKey superShardingKey)
- Specified by:
superShardingKeyin interfacejava.sql.ConnectionBuilder- Parameters:
superShardingKey- Super sharding key object that needs to be part of connection request- Returns:
- This
OracleConnectionBuilder
-
gssCredential
OracleConnectionBuilder gssCredential(org.ietf.jgss.GSSCredential credential)
Provide the GSSCredential used to authenticate the connection.- Parameters:
credential- used to authenticate the connection. Not null.- Returns:
- This
OracleConnectionBuilder
-
sslContext
OracleConnectionBuilder sslContext(javax.net.ssl.SSLContext sslContext)
Specifies aSSLContextto 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.
- Parameters:
sslContext- An SSLContext to use as an SSLEngine factory. May be null.- Returns:
- This
OracleConnectionBuilder - Since:
- 20
-
radiusChallengeResponseHandler
OracleConnectionBuilder radiusChallengeResponseHandler(java.util.function.Function<byte[],byte[]> radiusAuthenticationHandler)
Specifies theFunctionthat 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 isUTF-8encoded. The handler is expected to return the response for the challenge asbyte[].Challenge response handler can also be configured via connection property
OracleConnection.CONNECTION_PROPERTY_THIN_NET_RADIUS_CHALLENGE_RESPONSE_HANDLER
Example: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();- Parameters:
radiusAuthenticationHandler- Radius authentication handler. May benull.- Returns:
- This
OracleConnectionBuilder - Since:
- 23ai
-
traceEventListener
OracleConnectionBuilder traceEventListener(TraceEventListener traceEventListener)
Configures aTraceEventListenerthat receives events from connections built by this builder.- Parameters:
traceEventListener- Listener that receives trace events. May benullto disable tracing.- Returns:
- This
OracleConnectionBuilder.
-
hostnameResolver
OracleConnectionBuilder hostnameResolver(OracleHostnameResolver hostnameResolver)
Sets a custom hostname resolver implementingOracleHostnameResolverused to provide a custom DNS name resolution strategy to locate the database host.- Parameters:
hostnameResolver- an OracleHostnameResolver to use when resolving the datasource hostname- Returns:
- This
OracleConnectionBuilder - Since:
- 23
-
readOnlyInstanceAllowed
OracleConnectionBuilder readOnlyInstanceAllowed(boolean readOnlyInstanceAllowed)
Sets the read-only instance allowed value on this builder. This property is applicable to sharded database only. When the property value is set to true, the database allows connection creation to read-only instances as well otherwise not. A shard instance goes into read-only mode for a chunk if the chunk move/split operation is in progress on that instance. The default value is false which means by default connection creation is not allowed to a read-only instance.- Parameters:
readOnlyInstanceAllowed- whether to allow connection creation to a read-only instance or not- Returns:
- This
OracleConnectionBuilder
-
executorOracle
OracleConnectionBuilder executorOracle(java.util.concurrent.Executor executor)
Set the
Executorused for asynchronous tasks by thisConnectionBuilderand anyConnectionobjects built by it. The default value isForkJoinPool.commonPool().Oracle JDBC implements this
OracleCommonConnectionmethod to return this instance ofOracleConnectionBuilder.- Specified by:
executorOraclein interfaceOracleCommonConnectionBuilder- Parameters:
executor- an Executor to use for asynchronous tasks. Not null.- Returns:
- this OracleCommonConnectionBuilder
-
accessToken
OracleConnectionBuilder accessToken(AccessToken accessToken)
Specifies the
accessTokento 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)oruser(String)are invoked with non null values, then aSQLExceptionindicating an invalid configuration is thrown when creating a connection with this builder.- Parameters:
accessToken- the token to use for this connection. Notnull.- Returns:
- the same
ConnectionBuilderinstance - Throws:
java.lang.NullPointerException- If theaccessTokenisnull.
-
buildAsyncOracle
java.util.concurrent.CompletionStage<OracleConnection> buildAsyncOracle() throws java.sql.SQLException
Returns aCompletionStagethat completes with aConnectionhaving the same state as if it were built by callingbuildon thisConnectionBuilder.The returned stage is completed exceptionally with a
SQLExceptionif a failure occurs when building theConnection.- Returns:
- a
CompletionStagethat completes with aConnectionbuilt by thisConnectionBuilder - Throws:
java.sql.SQLException- Since:
- 20
-
buildConnectionPublisherOracle
java.util.concurrent.Flow.Publisher<OracleConnection> buildConnectionPublisherOracle() throws java.sql.SQLException
Returns a
Publisherthat publishes a singleConnectionobject with the same state as if it were built by callingbuildon thisConnectionBuilder. The returnedPublisherdoes not support multipleSubscribers.Oracle JDBC implements this
OracleCommonConnectionmethod to publish an instance ofOracleConnection.- Specified by:
buildConnectionPublisherOraclein interfaceOracleCommonConnectionBuilder- Returns:
- a
Publisherof aConnectionbuilt by thisConnectionBuilder - Throws:
java.sql.SQLException
-
build
OracleConnection build() throws java.sql.SQLException
Builds the connection object.- Specified by:
buildin interfacejava.sql.ConnectionBuilder- Returns:
- New
OracleConnectionthat is created. - Throws:
java.sql.SQLException
-
-