Skip to content

Commit b52984d

Browse files
authored
Added methods to set default namespace (onprem only) (#40)
Added methods to set default namespace in NoSQLHandleConfig (onprem only)
1 parent c2b360a commit b52984d

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

driver/src/main/java/oracle/nosql/driver/NoSQLHandleConfig.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ public class NoSQLHandleConfig implements Cloneable {
204204
*/
205205
private String compartment;
206206

207+
/**
208+
* On-premise only.
209+
*
210+
* The default namespace to use for all requests. If this is null (the
211+
* default), no namespace is used unless specified in table names in
212+
* requests and SQL statements.
213+
*
214+
* Any non-namespace qualified table name in requests and/or SQL
215+
* statements will be resolved/qualified to the specified namespace.
216+
*/
217+
private String defaultNamespace;
218+
207219
/**
208220
* Enable rate limiting.
209221
* Cloud service only.
@@ -1074,6 +1086,40 @@ public String getDefaultCompartment() {
10741086
return compartment;
10751087
}
10761088

1089+
/**
1090+
* @hidden
1091+
*
1092+
* On-premise only.
1093+
*
1094+
* Sets the default namespace to use for requests sent using the
1095+
* handle. This is an optional convenience method to avoid having to
1096+
* add the namespace to table names in requests and SQL statements.
1097+
*
1098+
* Any non-namespace qualified table name in requests and/or SQL
1099+
* statements will be resolved/qualified to the specified namespace.
1100+
*
1101+
* @param namespace the default namespace to use
1102+
*
1103+
* @return this
1104+
*/
1105+
public NoSQLHandleConfig setDefaultNamespace(String defaultNamespace) {
1106+
this.defaultNamespace = defaultNamespace;
1107+
return this;
1108+
}
1109+
1110+
/**
1111+
* @hidden
1112+
*
1113+
* On-premise only.
1114+
*
1115+
* Returns the default namespace to use for requests or null if not set.
1116+
*
1117+
* @return the default namespace
1118+
*/
1119+
public String getDefaultNamespace() {
1120+
return defaultNamespace;
1121+
}
1122+
10771123
/**
10781124
* Returns the SSL cipher suites to enable.
10791125
* @return cipher suites.

driver/src/main/java/oracle/nosql/driver/http/Client.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static oracle.nosql.driver.util.HttpConstants.CONTENT_LENGTH;
2323
import static oracle.nosql.driver.util.HttpConstants.CONTENT_TYPE;
2424
import static oracle.nosql.driver.util.HttpConstants.COOKIE;
25+
import static oracle.nosql.driver.util.HttpConstants.REQUEST_NAMESPACE_HEADER;
2526
import static oracle.nosql.driver.util.HttpConstants.NOSQL_DATA_PATH;
2627
import static oracle.nosql.driver.util.HttpConstants.REQUEST_ID_HEADER;
2728
import static oracle.nosql.driver.util.HttpConstants.USER_AGENT;
@@ -626,6 +627,11 @@ public Result execute(Request kvRequest) {
626627
}
627628
authProvider.setRequiredHeaders(authString, kvRequest, headers);
628629

630+
if (config.getDefaultNamespace() != null) {
631+
headers.add(REQUEST_NAMESPACE_HEADER,
632+
config.getDefaultNamespace());
633+
}
634+
629635
if (isLoggable(logger, Level.FINE) &&
630636
!kvRequest.getIsRefresh()) {
631637
logTrace(logger, "Request: " + requestClass +
@@ -808,7 +814,7 @@ public Result execute(Request kvRequest) {
808814
/* reduce protocol version and try again */
809815
if (decrementSerialVersion(serialVersionUsed) == true) {
810816
exception = upe;
811-
logInfo(logger, "Got unsupported protocol error " +
817+
logFine(logger, "Got unsupported protocol error " +
812818
"from server: decrementing serial version to " +
813819
serialVersion + " and trying again.");
814820
continue;
@@ -1656,4 +1662,12 @@ private int getRateDelayedFromHeader(HttpHeaders headers) {
16561662

16571663
return 0;
16581664
}
1665+
1666+
/**
1667+
* @hidden
1668+
* For testing use
1669+
*/
1670+
public void setDefaultNamespace(String ns) {
1671+
config.setDefaultNamespace(ns);
1672+
}
16591673
}

driver/src/main/java/oracle/nosql/driver/http/NoSQLHandleImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,15 @@ public short getSerialVersion() {
415415
return client.getSerialVersion();
416416
}
417417

418+
/**
419+
* @hidden
420+
*
421+
* Testing use only.
422+
*/
423+
public void setDefaultNamespace(String ns) {
424+
client.setDefaultNamespace(ns);
425+
}
426+
418427
/**
419428
* Cloud service only.
420429
* The refresh method of this class is called when a Signature is refreshed

driver/src/main/java/oracle/nosql/driver/util/HttpConstants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public class HttpConstants {
4646
*/
4747
public static final String REQUEST_COMPARTMENT_ID = "x-nosql-compartment-id";
4848

49+
/**
50+
* A header for transferring the default namespace on an http request.
51+
* onprem use only.
52+
*/
53+
public static final String REQUEST_NAMESPACE_HEADER = "x-nosql-default-ns";
54+
4955
/**
5056
* Headers possibly set by the load balancer service to indicate original
5157
* IP address

0 commit comments

Comments
 (0)