Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions driver/src/main/java/oracle/nosql/driver/NoSQLHandleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ public class NoSQLHandleConfig implements Cloneable {
*/
private String compartment;

/**
* On-premise only.
*
* The default namespace to use for all requests. If this is null (the
* default), no namespace is used unless specified in table names in
* requests and SQL statements.
*
* Any non-namespace qualified table name in requests and/or SQL
* statements will be resolved/qualified to the specified namespace.
*/
private String defaultNamespace;

/**
* Enable rate limiting.
* Cloud service only.
Expand Down Expand Up @@ -1074,6 +1086,40 @@ public String getDefaultCompartment() {
return compartment;
}

/**
* @hidden
*
* On-premise only.
*
* Sets the default namespace to use for requests sent using the
* handle. This is an optional convenience method to avoid having to
* add the namespace to table names in requests and SQL statements.
*
* Any non-namespace qualified table name in requests and/or SQL
* statements will be resolved/qualified to the specified namespace.
*
* @param namespace the default namespace to use
*
* @return this
*/
public NoSQLHandleConfig setDefaultNamespace(String defaultNamespace) {
this.defaultNamespace = defaultNamespace;
return this;
}

/**
* @hidden
*
* On-premise only.
*
* Returns the default namespace to use for requests or null if not set.
*
* @return the default namespace
*/
public String getDefaultNamespace() {
return defaultNamespace;
}

/**
* Returns the SSL cipher suites to enable.
* @return cipher suites.
Expand Down
16 changes: 15 additions & 1 deletion driver/src/main/java/oracle/nosql/driver/http/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static oracle.nosql.driver.util.HttpConstants.CONTENT_LENGTH;
import static oracle.nosql.driver.util.HttpConstants.CONTENT_TYPE;
import static oracle.nosql.driver.util.HttpConstants.COOKIE;
import static oracle.nosql.driver.util.HttpConstants.REQUEST_NAMESPACE_HEADER;
import static oracle.nosql.driver.util.HttpConstants.NOSQL_DATA_PATH;
import static oracle.nosql.driver.util.HttpConstants.REQUEST_ID_HEADER;
import static oracle.nosql.driver.util.HttpConstants.USER_AGENT;
Expand Down Expand Up @@ -624,6 +625,11 @@ public Result execute(Request kvRequest) {
}
authProvider.setRequiredHeaders(authString, kvRequest, headers);

if (config.getDefaultNamespace() != null) {
headers.add(REQUEST_NAMESPACE_HEADER,
config.getDefaultNamespace());
}

if (isLoggable(logger, Level.FINE) &&
!kvRequest.getIsRefresh()) {
logTrace(logger, "Request: " + requestClass +
Expand Down Expand Up @@ -806,7 +812,7 @@ public Result execute(Request kvRequest) {
/* reduce protocol version and try again */
if (decrementSerialVersion(serialVersionUsed) == true) {
exception = upe;
logInfo(logger, "Got unsupported protocol error " +
logFine(logger, "Got unsupported protocol error " +
"from server: decrementing serial version to " +
serialVersion + " and trying again.");
continue;
Expand Down Expand Up @@ -1654,4 +1660,12 @@ private int getRateDelayedFromHeader(HttpHeaders headers) {

return 0;
}

/**
* @hidden
* For testing use
*/
public void setDefaultNamespace(String ns) {
config.setDefaultNamespace(ns);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ public short getSerialVersion() {
return client.getSerialVersion();
}

/**
* @hidden
*
* Testing use only.
*/
public void setDefaultNamespace(String ns) {
client.setDefaultNamespace(ns);
}

/**
* Cloud service only.
* The refresh method of this class is called when a Signature is refreshed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public class HttpConstants {
*/
public static final String REQUEST_COMPARTMENT_ID = "x-nosql-compartment-id";

/**
* A header for transferring the default namespace on an http request.
* onprem use only.
*/
public static final String REQUEST_NAMESPACE_HEADER = "x-nosql-default-ns";

/**
* Headers possibly set by the load balancer service to indicate original
* IP address
Expand Down