├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── SECURITY.md ├── THIRD_PARTY_LICENSES.txt ├── _config.yml ├── driver ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml ├── scripts │ ├── build_nson_strings.sh │ └── generate_version_strings.sh └── src │ ├── main │ ├── assembly │ │ └── sdk.xml │ └── java │ │ └── oracle │ │ └── nosql │ │ └── driver │ │ ├── AuthorizationProvider.java │ │ ├── BatchOperationNumberLimitException.java │ │ ├── Consistency.java │ │ ├── DefaultRetryHandler.java │ │ ├── DefinedTags.java │ │ ├── DeploymentException.java │ │ ├── DriverMain.java │ │ ├── Durability.java │ │ ├── EvolutionLimitException.java │ │ ├── FieldRange.java │ │ ├── FreeFormTags.java │ │ ├── IndexExistsException.java │ │ ├── IndexLimitException.java │ │ ├── IndexNotFoundException.java │ │ ├── InvalidAuthorizationException.java │ │ ├── JsonParseException.java │ │ ├── KeySizeLimitException.java │ │ ├── NoSQLException.java │ │ ├── NoSQLHandle.java │ │ ├── NoSQLHandleConfig.java │ │ ├── NoSQLHandleFactory.java │ │ ├── Nson.java │ │ ├── OperationNotSupportedException.java │ │ ├── OperationThrottlingException.java │ │ ├── PrepareQueryException.java │ │ ├── RateLimiter.java │ │ ├── ReadThrottlingException.java │ │ ├── Region.java │ │ ├── RequestSizeLimitException.java │ │ ├── RequestTimeoutException.java │ │ ├── ResourceExistsException.java │ │ ├── ResourceLimitException.java │ │ ├── ResourceNotFoundException.java │ │ ├── RetryHandler.java │ │ ├── RetryableException.java │ │ ├── RowSizeLimitException.java │ │ ├── SDKVersion.java │ │ ├── SecurityInfoNotReadyException.java │ │ ├── StatsControl.java │ │ ├── SystemException.java │ │ ├── TableBusyException.java │ │ ├── TableExistsException.java │ │ ├── TableLimitException.java │ │ ├── TableNotFoundException.java │ │ ├── TableNotReadyException.java │ │ ├── TableSizeException.java │ │ ├── ThrottlingException.java │ │ ├── TimeToLive.java │ │ ├── UnauthorizedException.java │ │ ├── UnsupportedProtocolException.java │ │ ├── UnsupportedQueryVersionException.java │ │ ├── UserInfo.java │ │ ├── Version.java │ │ ├── WriteThrottlingException.java │ │ ├── http │ │ ├── Client.java │ │ ├── NoSQLHandleImpl.java │ │ ├── Stats.java │ │ └── StatsControlImpl.java │ │ ├── httpclient │ │ ├── ConnectionPool.java │ │ ├── HttpClient.java │ │ ├── HttpClientChannelPoolHandler.java │ │ ├── HttpClientHandler.java │ │ ├── RequestState.java │ │ └── ResponseHandler.java │ │ ├── iam │ │ ├── AuthenticationProfileProvider.java │ │ ├── CertificateSupplier.java │ │ ├── FederationRequestHelper.java │ │ ├── InstanceMetadataHelper.java │ │ ├── InstancePrincipalsProvider.java │ │ ├── OCIConfigFileProvider.java │ │ ├── OCIConfigFileReader.java │ │ ├── OkeWorkloadIdentityProvider.java │ │ ├── PrivateKeyFileSupplier.java │ │ ├── PrivateKeyProvider.java │ │ ├── PrivateKeyStringSupplier.java │ │ ├── ResourcePrincipalProvider.java │ │ ├── ResourcePrincipalTokenSupplier.java │ │ ├── SecurityTokenSupplier.java │ │ ├── SessionKeyPairSupplier.java │ │ ├── SessionTokenProvider.java │ │ ├── SignatureProvider.java │ │ ├── SimpleProfileProvider.java │ │ ├── UserAuthenticationProfileProvider.java │ │ ├── Utils.java │ │ ├── package-info.java │ │ └── pki │ │ │ ├── Eraser.java │ │ │ ├── Hex.java │ │ │ ├── OpenSslPbeSecretKeyFactory.java │ │ │ ├── OpenSslPbeSecretKeyGenerator.java │ │ │ ├── Pem.java │ │ │ ├── PemEncryptedKeyException.java │ │ │ ├── PemEncryptionException.java │ │ │ ├── PemException.java │ │ │ ├── Pkcs1EncryptedPrivateKeyInfo.java │ │ │ ├── Sensitive.java │ │ │ ├── Text.java │ │ │ ├── Utf8.java │ │ │ └── package-info.java │ │ ├── kv │ │ ├── AuthenticationException.java │ │ ├── StoreAccessTokenProvider.java │ │ └── package-info.java │ │ ├── ops │ │ ├── AddReplicaRequest.java │ │ ├── DeleteRequest.java │ │ ├── DeleteResult.java │ │ ├── DropReplicaRequest.java │ │ ├── DurableRequest.java │ │ ├── GetIndexesRequest.java │ │ ├── GetIndexesResult.java │ │ ├── GetRequest.java │ │ ├── GetResult.java │ │ ├── GetTableRequest.java │ │ ├── ListTablesRequest.java │ │ ├── ListTablesResult.java │ │ ├── MultiDeleteRequest.java │ │ ├── MultiDeleteResult.java │ │ ├── PrepareRequest.java │ │ ├── PrepareResult.java │ │ ├── PreparedStatement.java │ │ ├── PutRequest.java │ │ ├── PutResult.java │ │ ├── QueryIterableResult.java │ │ ├── QueryRequest.java │ │ ├── QueryResult.java │ │ ├── ReadRequest.java │ │ ├── ReplicaStatsRequest.java │ │ ├── ReplicaStatsResult.java │ │ ├── Request.java │ │ ├── Result.java │ │ ├── RetryStats.java │ │ ├── SystemRequest.java │ │ ├── SystemResult.java │ │ ├── SystemStatusRequest.java │ │ ├── TableLimits.java │ │ ├── TableRequest.java │ │ ├── TableResult.java │ │ ├── TableUsageRequest.java │ │ ├── TableUsageResult.java │ │ ├── WriteMultipleRequest.java │ │ ├── WriteMultipleResult.java │ │ ├── WriteRequest.java │ │ ├── WriteResult.java │ │ ├── package-info.java │ │ └── serde │ │ │ ├── BinaryProtocol.java │ │ │ ├── BinarySerializerFactory.java │ │ │ ├── DeleteRequestSerializer.java │ │ │ ├── GetIndexesRequestSerializer.java │ │ │ ├── GetRequestSerializer.java │ │ │ ├── GetTableRequestSerializer.java │ │ │ ├── ListTablesRequestSerializer.java │ │ │ ├── MultiDeleteRequestSerializer.java │ │ │ ├── PrepareRequestSerializer.java │ │ │ ├── PutRequestSerializer.java │ │ │ ├── QueryRequestSerializer.java │ │ │ ├── Serializer.java │ │ │ ├── SerializerFactory.java │ │ │ ├── SystemRequestSerializer.java │ │ │ ├── SystemStatusRequestSerializer.java │ │ │ ├── TableRequestSerializer.java │ │ │ ├── TableUsageRequestSerializer.java │ │ │ ├── WriteMultipleRequestSerializer.java │ │ │ └── nson │ │ │ ├── NsonProtocol.java │ │ │ └── NsonSerializerFactory.java │ │ ├── package-info.java │ │ ├── query │ │ ├── AggrIterState.java │ │ ├── ArithOpIter.java │ │ ├── Compare.java │ │ ├── ConstIter.java │ │ ├── ExternalVarRefIter.java │ │ ├── FieldStepIter.java │ │ ├── FuncCollectIter.java │ │ ├── FuncMinMaxIter.java │ │ ├── FuncSizeIter.java │ │ ├── FuncSumIter.java │ │ ├── GroupIter.java │ │ ├── PlanIter.java │ │ ├── PlanIterState.java │ │ ├── QueryDriver.java │ │ ├── QueryException.java │ │ ├── QueryFormatter.java │ │ ├── QueryStateException.java │ │ ├── ReceiveIter.java │ │ ├── RuntimeControlBlock.java │ │ ├── SFWIter.java │ │ ├── SortIter.java │ │ ├── SortSpec.java │ │ ├── TopologyInfo.java │ │ ├── VarRefIter.java │ │ └── VirtualScan.java │ │ ├── util │ │ ├── BinaryProtocol.java │ │ ├── ByteInputStream.java │ │ ├── ByteOutputStream.java │ │ ├── CheckNull.java │ │ ├── HttpConstants.java │ │ ├── HttpRequestUtil.java │ │ ├── LogUtil.java │ │ ├── LruCache.java │ │ ├── NettyByteInputStream.java │ │ ├── NettyByteOutputStream.java │ │ ├── PackedInteger.java │ │ ├── RateLimiterMap.java │ │ ├── SerializationUtil.java │ │ ├── SimpleRateLimiter.java │ │ ├── SizeOf.java │ │ └── TimestampUtil.java │ │ └── values │ │ ├── ArrayValue.java │ │ ├── BinaryValue.java │ │ ├── BooleanValue.java │ │ ├── DoubleValue.java │ │ ├── EmptyValue.java │ │ ├── FieldValue.java │ │ ├── FieldValueCreator.java │ │ ├── FieldValueEventHandler.java │ │ ├── IntegerValue.java │ │ ├── JsonNullValue.java │ │ ├── JsonOptions.java │ │ ├── JsonPrettySerializer.java │ │ ├── JsonReader.java │ │ ├── JsonSerializer.java │ │ ├── JsonUtils.java │ │ ├── LongValue.java │ │ ├── MapValue.java │ │ ├── MapWalker.java │ │ ├── NullValue.java │ │ ├── NumberValue.java │ │ ├── PathFinder.java │ │ ├── StringValue.java │ │ ├── TimestampValue.java │ │ └── package-info.java │ └── test │ ├── java │ └── oracle │ │ └── nosql │ │ └── driver │ │ ├── BasicTest.java │ │ ├── DriverTestBase.java │ │ ├── FreePortLocator.java │ │ ├── HandleConfigTest.java │ │ ├── I18NTest.java │ │ ├── InternalsTest.java │ │ ├── JsonTest.java │ │ ├── MultiDeleteTest.java │ │ ├── NumericTest.java │ │ ├── OnPremiseTest.java │ │ ├── ProxyTestBase.java │ │ ├── QueryTest.java │ │ ├── RateLimiterTest.java │ │ ├── StatsTest.java │ │ ├── TimestampTest.java │ │ ├── ValueTest.java │ │ ├── WriteMultipleTest.java │ │ ├── httpclient │ │ └── ConnectionPoolTest.java │ │ ├── iam │ │ ├── ConfigFileTest.java │ │ ├── InstancePrincipalsProviderTest.java │ │ ├── RegionTest.java │ │ ├── ResourcePrincipalProviderTest.java │ │ ├── SessionTokenProviderTest.java │ │ ├── SignatureProviderTest.java │ │ └── UserProfileProviderTest.java │ │ └── kv │ │ └── StoreAccessTokenProviderTest.java │ └── resources │ ├── regions-config.json │ ├── utf16be.json │ ├── utf16bebom.json │ ├── utf16le.json │ ├── utf16lebom.json │ ├── utf8.json │ ├── utf8_jsondata.txt │ ├── utf8_testdata.txt │ └── utf8bom.json ├── examples ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ └── java │ ├── BasicTableExample.java │ ├── Common.java │ ├── DeleteExample.java │ ├── DocSnippets.java │ ├── HelloWorld.java │ ├── IndexExample.java │ └── RateLimitingExample.java ├── pom.xml └── sbom_generation.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.versionsBackup 3 | *.diff 4 | Fortify* 5 | logging.properties 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to this repository 2 | 3 | We welcome your contributions! There are multiple ways to contribute. 4 | 5 | ## Opening issues 6 | 7 | For bugs or enhancement requests, please file a GitHub issue unless it's 8 | security related. When filing a bug remember that the better written the bug is, 9 | the more likely it is to be fixed. If you think you've found a security 10 | vulnerability, do not raise a GitHub issue and follow the instructions in our 11 | [security policy](./SECURITY.md). 12 | 13 | ## Contributing code 14 | 15 | We welcome your code contributions. Before submitting code via a pull request, 16 | you will need to have signed the [Oracle Contributor Agreement][OCA] (OCA) and 17 | your commits need to include the following line using the name and e-mail 18 | address you used to sign the OCA: 19 | 20 | ```text 21 | Signed-off-by: Your Name 22 | ``` 23 | 24 | This can be automatically added to pull requests by committing with `--sign-off` 25 | or `-s`, e.g. 26 | 27 | ```text 28 | git commit --signoff 29 | ``` 30 | 31 | Only pull requests from committers that can be verified as having signed the OCA 32 | can be accepted. 33 | 34 | ## Pull request process 35 | 36 | 1. Ensure there is an issue created to track and discuss the fix or enhancement 37 | you intend to submit. 38 | 1. Fork this repository 39 | 1. Create a branch in your fork to implement the changes. We recommend using 40 | the issue number as part of your branch name, e.g. `1234-fixes` 41 | 1. Ensure that any documentation is updated with the changes that are required 42 | by your change. 43 | 1. Ensure that any samples are updated if the base image has been changed. 44 | 1. Submit the pull request. *Do not leave the pull request blank*. Explain exactly 45 | what your changes are meant to do and provide simple steps on how to validate 46 | your changes. Ensure that you reference the issue you created as well. 47 | 1. We will assign the pull request to 2-3 people for review before it is merged. 48 | 49 | ## Code of conduct 50 | 51 | Follow the [Golden Rule](https://en.wikipedia.org/wiki/Golden_Rule). If you'd 52 | like more specific guidelines, see the [Contributor Covenant Code of Conduct][COC]. 53 | 54 | [OCA]: https://oca.opensource.oracle.com 55 | [COC]: https://www.contributor-covenant.org/version/1/4/code-of-conduct/ 56 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, 2025 Oracle and/or its affiliates. All rights reserved. 2 | 3 | The Universal Permissive License (UPL), Version 1.0 4 | 5 | Subject to the condition set forth below, permission is hereby granted to any 6 | person obtaining a copy of this software, associated documentation and/or data 7 | (collectively the "Software"), free of charge and under any and all copyright 8 | rights in the Software, and any and all patent rights owned or freely 9 | licensable by each licensor hereunder covering either (i) the unmodified 10 | Software as contributed to or provided by such licensor, or (ii) the Larger 11 | Works (as defined below), to deal in both 12 | 13 | (a) the Software, and 14 | (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if 15 | one is included with the Software (each a "Larger Work" to which the Software 16 | is contributed by such licensors), 17 | 18 | without restriction, including without limitation the rights to copy, create 19 | derivative works of, display, perform, and distribute the Software and make, 20 | use, sell, offer for sale, import, export, have made, and have sold the 21 | Software and the Larger Work(s), and to sublicense the foregoing rights on 22 | either these or other terms. 23 | 24 | This license is subject to the following condition: 25 | The above copyright notice and either this complete permission notice or at 26 | a minimum a reference to the UPL must be included in all copies or 27 | substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 35 | SOFTWARE. 36 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting security vulnerabilities 2 | 3 | Oracle values the independent security research community and believes that 4 | responsible disclosure of security vulnerabilities helps us ensure the security 5 | and privacy of all our users. 6 | 7 | Please do NOT raise a GitHub Issue to report a security vulnerability. If you 8 | believe you have found a security vulnerability, please submit a report to 9 | [secalert_us@oracle.com][1] preferably with a proof of concept. Please review 10 | some additional information on [how to report security vulnerabilities to Oracle][2]. 11 | We encourage people who contact Oracle Security to use email encryption using 12 | [our encryption key][3]. 13 | 14 | We ask that you do not use other channels or contact the project maintainers 15 | directly. 16 | 17 | Non-vulnerability related security issues including ideas for new or improved 18 | security features are welcome on GitHub Issues. 19 | 20 | ## Security updates, alerts and bulletins 21 | 22 | Security updates will be released on a regular cadence. Many of our projects 23 | will typically release security fixes in conjunction with the 24 | Oracle Critical Patch Update program. Additional 25 | information, including past advisories, is available on our [security alerts][4] 26 | page. 27 | 28 | ## Security-related information 29 | 30 | We will provide security related information such as a threat model, considerations 31 | for secure use, or any known security issues in our documentation. Please note 32 | that labs and sample code are intended to demonstrate a concept and may not be 33 | sufficiently hardened for production use. 34 | 35 | [1]: mailto:secalert_us@oracle.com 36 | [2]: https://www.oracle.com/corporate/security-practices/assurance/vulnerability/reporting.html 37 | [3]: https://www.oracle.com/security-alerts/encryptionkey.html 38 | [4]: https://www.oracle.com/security-alerts/ 39 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /driver/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /driver/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | nosqldriver 4 | This project contains the SDK used for Oracle NoSQL Database. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Nature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /driver/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding//src/test/resources=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /driver/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /driver/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /driver/scripts/build_nson_strings.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (C) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 4 | # 5 | # This file was distributed by Oracle as part of a version of Oracle NoSQL 6 | # Database made available at: 7 | # 8 | # http://www.oracle.com/technetwork/database/database-technologies/nosqldb/downloads/index.html 9 | # 10 | # Please see the LICENSE file included in the top-level directory of the 11 | # appropriate version of Oracle NoSQL Database for a copy of the license and 12 | # additional information. 13 | 14 | # this script creates java code to enable using human-readable strings for field 15 | # names in nson debug/logging/verbose output. It modifies NsonProtocol.java to 16 | # add a map of field names to human readable field names. 17 | 18 | PROTOCOL_FILE=src/main/java/oracle/nosql/driver/ops/serde/nson/NsonProtocol.java 19 | 20 | # delete everything after the last static string 21 | lastline=$(grep -n 'public static String [A-Z]' $PROTOCOL_FILE | tail -1 | sed -e 's/:.*$//') 22 | head -$lastline $PROTOCOL_FILE > /tmp/proto.$$ 23 | 24 | # add a static array of string arrays 25 | grep 'public static String ' /tmp/proto.$$ | awk 'BEGIN{printf("\n private static String[][] mapVals = new String[][] {\n");}{printf(" {%s,\"%s\"},\n",$4,$4);}END{printf(" };\n");}' >> /tmp/proto.$$ 26 | 27 | # add remaining logic 28 | cat << EOT >> /tmp/proto.$$ 29 | 30 | private static HashMap fieldMap = null; 31 | 32 | public static String readable(String field) { 33 | if (fieldMap == null) { 34 | fieldMap = new HashMap(); 35 | for (int x=0; x /tmp/sdkversion.$$ 30 | 31 | # add SDKVersion class 32 | cat << EOT >> /tmp/sdkversion.$$ 33 | /** 34 | * Public class to manage SDK version information 35 | */ 36 | public class SDKVersion { 37 | /** 38 | * The full X.Y.Z version of the current SDK 39 | */ 40 | public static final String VERSION = "$sdk_version"; 41 | } 42 | EOT 43 | 44 | # replace file 45 | mv /tmp/sdkversion.$$ $SDK_VERSION_FILE 46 | echo "Set SDKVersion.VERSION to $sdk_version" 47 | exit 0 48 | 49 | -------------------------------------------------------------------------------- /driver/src/main/assembly/sdk.xml: -------------------------------------------------------------------------------- 1 | 4 | sdk 5 | true 6 | 7 | zip 8 | tar.gz 9 | 10 | 11 | 12 | 13 | 14 | ${project.basedir}/.. 15 | 16 | README.md 17 | LICENSE.txt 18 | THIRD_PARTY_LICENSES.txt 19 | CHANGELOG.md 20 | CONTRIBUTING.md 21 | SECURITY.md 22 | 23 | 24 | 25 | 26 | 27 | ${project.basedir}/../examples/src/main/java 28 | examples 29 | 30 | DocSnippets.java 31 | HelloWorld.java 32 | 33 | 34 | 35 | 36 | 37 | ${project.basedir}/../driver/target/apidocs 38 | doc/javadoc 39 | 0644 40 | 41 | ** 42 | 43 | 44 | 45 | 46 | 47 | 48 | ${artifact.artifactId}.${artifact.extension} 49 | lib 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/AuthorizationProvider.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import static oracle.nosql.driver.util.HttpConstants.AUTHORIZATION; 11 | 12 | import io.netty.handler.codec.http.HttpHeaders; 13 | import oracle.nosql.driver.ops.Request; 14 | 15 | /** 16 | * A callback interface used by the driver to obtain an authorization string 17 | * for a request. {@link NoSQLHandle} calls this interface when and 18 | * authorization string is required. In general applications need not implement 19 | * this interface, instead using the default mechanisms. 20 | *

21 | * Instances of this interface must be reentrant and thread-safe. 22 | */ 23 | public interface AuthorizationProvider { 24 | 25 | /** 26 | * Returns an authorization string for specified request. This is sent to 27 | * the server in the request for authorization. Authorization information 28 | * can be request-dependent. 29 | * 30 | * @param request the request being processed 31 | * 32 | * @return a string indicating that the application is authorized to perform 33 | * the request 34 | */ 35 | public String getAuthorizationString(Request request); 36 | 37 | /** 38 | * Release resources provider is using. 39 | */ 40 | public void close(); 41 | 42 | /** 43 | * Validates the authentication string. This method is optional and 44 | * by default it will not allow a null string. 45 | * 46 | * @param input the string to authorize 47 | * 48 | * @throws IllegalArgumentException if the authentication string is null 49 | */ 50 | public default void validateAuthString(String input) { 51 | if (input == null) { 52 | throw new IllegalArgumentException( 53 | "Configured AuthorizationProvider acquired an " + 54 | "unexpected null authorization string"); 55 | } 56 | } 57 | 58 | /** 59 | * Set HTTP headers required by the provider. 60 | * 61 | * @param authString the authorization string for the request 62 | * 63 | * @param request the request being processed 64 | * 65 | * @param headers the HTTP headers 66 | * 67 | * @param content the request content bytes 68 | */ 69 | public default void setRequiredHeaders(String authString, 70 | Request request, 71 | HttpHeaders headers, 72 | byte[] content) { 73 | if (authString != null) { 74 | headers.set(AUTHORIZATION, authString); 75 | } 76 | } 77 | 78 | /** 79 | * Invalidate any cached authorization strings. 80 | */ 81 | public default void flushCache() { 82 | } 83 | 84 | /** 85 | * Indicates whether or not the instance is used for the cloud 86 | * service 87 | * 88 | * @return false by default 89 | */ 90 | public default boolean forCloud() { 91 | return false; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/BatchOperationNumberLimitException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * Thrown to indicate that the number of operations included in 14 | * {@link NoSQLHandle#writeMultiple} operation exceeds the 15 | * system defined limit. 16 | */ 17 | public class BatchOperationNumberLimitException extends ResourceLimitException { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * internal use only 23 | * @param msg the message 24 | * @hidden 25 | */ 26 | public BatchOperationNumberLimitException(String msg) { 27 | super(msg); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/Consistency.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Consistency is used to provide consistency guarantees for read operations. 12 | *

13 | * {@link #ABSOLUTE} consistency may be specified to guarantee that current 14 | * values are read. {@link #EVENTUAL} consistency means that the values read 15 | * may be very slightly out of date. {@link #ABSOLUTE} consistency results in 16 | * higher cost, consuming twice the number of read units for the same data 17 | * relative to {@link #EVENTUAL} consistency, and should only be used when 18 | * required. 19 | *

20 | *

21 | * It is possible to set a default Consistency for a {@link NoSQLHandle} instance 22 | * by using {@link NoSQLHandleConfig#setConsistency}. If no Consistency 23 | * is specified in an operation and there is no default value, {@link #EVENTUAL} 24 | * is used. 25 | *

26 | *

27 | * Consistency can be specified as an optional argument to all read operations. 28 | *

29 | */ 30 | public class Consistency { 31 | final private Type type; 32 | 33 | /** 34 | * Consistency types 35 | */ 36 | public enum Type { 37 | /** 38 | * EVENTUAL consistency will read from any node in the cluster 39 | */ 40 | EVENTUAL, 41 | /** 42 | * ABSOLUTE consistency reads only from the leader node 43 | */ 44 | ABSOLUTE 45 | } 46 | 47 | /* 48 | * Convenient static instances 49 | */ 50 | /** constant for ABSOLUTE Consistency */ 51 | public static Consistency ABSOLUTE = new Consistency(Type.ABSOLUTE); 52 | /** constant for EVENTUAL Consistency */ 53 | public static Consistency EVENTUAL = new Consistency(Type.EVENTUAL); 54 | 55 | /** 56 | * Returns the {@link Type} of Consistency 57 | * @return the type 58 | */ 59 | public Type getType() { 60 | return type; 61 | } 62 | 63 | /** 64 | * Returns true if this is Consistency.ABSOLUTE 65 | * 66 | * @return true if this instance represents ABSOLUTE Consistency 67 | */ 68 | public boolean isAbsolute() { 69 | return type == Type.ABSOLUTE; 70 | } 71 | 72 | /** 73 | * Returns true if this is Consistency.EVENTUAL 74 | * 75 | * @return true if this instance represents EVENTUAL Consistency 76 | */ 77 | public boolean isEventual() { 78 | return type == Type.EVENTUAL; 79 | } 80 | 81 | private Consistency(Type type) { 82 | this.type = type; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/DefinedTags.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import oracle.nosql.driver.values.FieldValue; 11 | import oracle.nosql.driver.values.MapValue; 12 | 13 | /** 14 | * Cloud service only. 15 | * 16 | * DefinedTags is a class to encapsulate defined tags which are returned 17 | * from calls to {@link NoSQLHandle#getTable}. They can also be set during 18 | * table creation operations as well as alter table operations. 19 | * @since 5.4 20 | */ 21 | public class DefinedTags { 22 | private final MapValue tags; 23 | 24 | /** 25 | * Creates a new instance of DefinedTags. This method along with 26 | * {@link #addTag} is used to add tags to a call to create or modify 27 | * a table. 28 | */ 29 | public DefinedTags() { 30 | tags = new MapValue(); 31 | } 32 | 33 | /** 34 | * Creates a new instance of DefinedTags from JSON string input. 35 | * @param jsonString a JSON string 36 | */ 37 | public DefinedTags(String jsonString) { 38 | tags = (MapValue) FieldValue.createFromJson(jsonString, null); 39 | } 40 | 41 | /** 42 | * Adds a new tag to the set of tags in the specified namespace 43 | * 44 | * @param namespace the namespace for the tag 45 | * @param key the tag key 46 | * @param value the tag value 47 | * @return this 48 | */ 49 | public DefinedTags addTag(String namespace, String key, String value) { 50 | if (!tags.contains(namespace)) { 51 | tags.put(namespace, new MapValue()); 52 | } 53 | MapValue nsMap = (MapValue) tags.get(namespace); 54 | nsMap.put(key, value); 55 | return this; 56 | } 57 | 58 | /** 59 | * Returns the value of the named tag in the specified namespace or null 60 | * if it does not exist 61 | * @param namespace the namespace 62 | * @param key the key 63 | * @return the tag value or null 64 | */ 65 | public String getTag(String namespace, String key) { 66 | if (tags.contains(namespace)) { 67 | FieldValue val = ((MapValue)tags.get(namespace)).get(key); 68 | return val == null ? null : val.getString(); 69 | } 70 | return null; 71 | } 72 | 73 | /** 74 | * Returns true if the specified key exists in the specified namespace 75 | * @param namespace the namespace 76 | * @param key the key 77 | * @return true if the key exists 78 | */ 79 | public boolean contains(String namespace, String key) { 80 | if (tags.contains(namespace)) { 81 | return ((MapValue)tags.get(namespace)).contains(key); 82 | } 83 | return false; 84 | } 85 | 86 | /** 87 | * Returns the free-form tags as a JSON string 88 | * @return the JSON string 89 | */ 90 | @Override 91 | public String toString() { 92 | return tags.toString(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/DeploymentException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * Thrown to indicate that an attempt has been made to create or modify a table 14 | * using limits that exceed the maximum allowed for a single table or that 15 | * cause the tenant's aggregate resources to exceed the maximum allowed for a 16 | * tenant. These are system-defined limits. 17 | */ 18 | public class DeploymentException extends ResourceLimitException { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * internal use only 24 | * @param msg the exception message 25 | * @hidden 26 | */ 27 | public DeploymentException(String msg) { 28 | super(msg); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/DriverMain.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import java.io.IOException; 11 | import java.net.URL; 12 | import java.util.Enumeration; 13 | import java.util.jar.Attributes; 14 | import java.util.jar.Manifest; 15 | 16 | /** 17 | * A simple main for the driver jar file. At this time it only handles a 18 | * "version" command. If it ever is extended for other arguments it should 19 | * be better abstracted for multiple commands 20 | * 21 | * @hidden 22 | */ 23 | public class DriverMain { 24 | 25 | private static String libraryVersion = findVersion(); 26 | private static String buildId = findBuildId(); 27 | 28 | /** 29 | * Delegates to Command object named by first arg. If no args, delegates 30 | * to 'help' Command. 31 | * @param args the command line arguments 32 | * @throws Exception on failure 33 | */ 34 | public static void main(String args[]) 35 | throws Exception { 36 | 37 | if (args.length == 0 || args[0].equalsIgnoreCase("-version")) { 38 | System.out.println(libraryVersion); 39 | return; 40 | } 41 | if (args[0].equalsIgnoreCase("-build")) { 42 | System.out.println(buildId); 43 | return; 44 | } 45 | 46 | usage(); 47 | } 48 | 49 | public static String getLibraryVersion() { 50 | return libraryVersion; 51 | } 52 | 53 | /** 54 | * Top-level usage command. 55 | */ 56 | private static void usage() { 57 | final StringBuilder builder = new StringBuilder(); 58 | builder.append("java -jar [-version|-build]"); 59 | System.err.println(builder); 60 | usageExit(); 61 | } 62 | 63 | /** 64 | * Does System.exit on behalf of all usage commands. 65 | */ 66 | private static void usageExit() { 67 | System.exit(2); 68 | } 69 | 70 | /** 71 | * Pulls the version string from the manifest. The version is added 72 | * by maven. 73 | */ 74 | private static String findVersion() { 75 | return SDKVersion.VERSION; 76 | } 77 | 78 | /** 79 | * Pulls the version string from the manifest. See build.xml for 80 | * how this is constructed. 81 | */ 82 | private static String findBuildId() { 83 | Attributes attrs = findAttributes(); 84 | if (attrs != null) { 85 | return attrs.getValue("Build-Id"); 86 | } 87 | return null; 88 | } 89 | 90 | /** 91 | * Pulls the version string from the manifest. See build.xml for 92 | * how this is constructed. 93 | */ 94 | private static Attributes findAttributes() { 95 | try { 96 | Enumeration resources = DriverMain.class.getClassLoader() 97 | .getResources("META-INF/MANIFEST.MF"); 98 | while (resources.hasMoreElements()) { 99 | Manifest manifest = 100 | new Manifest(resources.nextElement().openStream()); 101 | Attributes attrs = manifest.getMainAttributes(); 102 | String title = 103 | attrs.getValue(Attributes.Name.IMPLEMENTATION_TITLE); 104 | if (title != null && 105 | title.toLowerCase().contains("sdk for java")) { 106 | return attrs; 107 | } 108 | } 109 | } catch (IOException e) { 110 | } 111 | return null; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/EvolutionLimitException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * Thrown to indicate that an attempt has been made to evolve the schema of a 14 | * a table more times than allowed by the system defined limit. 15 | */ 16 | public class EvolutionLimitException extends ResourceLimitException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * internal use only 22 | * 23 | * @param msg the exception message 24 | * @hidden 25 | */ 26 | public EvolutionLimitException(String msg) { 27 | super(msg); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/FreeFormTags.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import java.util.Iterator; 11 | import java.util.Map; 12 | 13 | import oracle.nosql.driver.values.FieldValue; 14 | import oracle.nosql.driver.values.MapValue; 15 | 16 | /** 17 | * Cloud service only. 18 | * 19 | * FreeFormTags is a class to encapsulate free-form tags which are returned 20 | * from calls to {@link NoSQLHandle#getTable}. They can also be set during 21 | * table creation operations as well as alter table operations. 22 | * @since 5.4 23 | */ 24 | public class FreeFormTags implements Iterable> { 25 | private final MapValue tags; 26 | 27 | /** 28 | * Creates a new instance of FreeFormTags. This method along with 29 | * {@link #addTag} is used to add tags to a call to create or modify 30 | * a table. 31 | */ 32 | public FreeFormTags() { 33 | tags = new MapValue(); 34 | } 35 | 36 | /** 37 | * Creates a new instance of FreeFormTags from JSON string input. 38 | * @param jsonString a JSON string 39 | */ 40 | public FreeFormTags(String jsonString) { 41 | tags = (MapValue) FieldValue.createFromJson(jsonString, null); 42 | } 43 | 44 | /** 45 | * Creates a new instance of FreeFormTags from a Map 46 | * @param map the map 47 | */ 48 | public FreeFormTags(Map map) { 49 | tags = new MapValue(); 50 | for (Map.Entry entry : map.entrySet()) { 51 | tags.put(entry.getKey(), entry.getValue()); 52 | } 53 | } 54 | 55 | /** 56 | * Adds a new tag to the set of tags 57 | * 58 | * @param key the tag key 59 | * @param value the tag value 60 | * @return this 61 | */ 62 | public FreeFormTags addTag(String key, String value) { 63 | tags.put(key, value); 64 | return this; 65 | } 66 | 67 | /** 68 | * Returns the value of the named tag or null if it does not exist 69 | * @param key the key 70 | * @return the tag value or null 71 | */ 72 | public String getTag(String key) { 73 | FieldValue val = tags.get(key); 74 | return val == null ? null : val.getString(); 75 | } 76 | 77 | /** 78 | * Returns the number of tags in the set 79 | * 80 | * @return the size 81 | */ 82 | public int size() { 83 | return tags.size(); 84 | } 85 | 86 | /** 87 | * Returns true if the specified key exists in the tags map 88 | * @param key the key 89 | * @return true if the key exists 90 | */ 91 | public boolean contains(String key) { 92 | return tags.getMap().containsKey(key); 93 | } 94 | 95 | /** 96 | * Returns the free-form tags as a JSON string 97 | * @return the JSON string 98 | */ 99 | @Override 100 | public String toString() { 101 | return tags.toString(); 102 | } 103 | 104 | @Override 105 | public Iterator> iterator() { 106 | return tags.iterator(); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/IndexExistsException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The operation attempted to create an index for a table but the named index 12 | * already exists. 13 | */ 14 | public class IndexExistsException extends ResourceExistsException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * internal use only 20 | * @param msg the exception message 21 | * @hidden 22 | */ 23 | public IndexExistsException(String msg) { 24 | super(msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/IndexLimitException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * Thrown to indicate that an attempt has been made to create more indexes on 14 | * a table than the system defined limit. 15 | */ 16 | public class IndexLimitException extends ResourceLimitException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * internal use only 22 | * @param msg the exception message 23 | * @hidden 24 | */ 25 | public IndexLimitException(String msg) { 26 | super(msg); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/IndexNotFoundException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The operation attempted to access a index that does not exist 12 | * or is not in a visible state. 13 | */ 14 | public class IndexNotFoundException extends ResourceNotFoundException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * internal use only 20 | * @param msg the exception message 21 | * @hidden 22 | */ 23 | public IndexNotFoundException(String msg) { 24 | super(msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/InvalidAuthorizationException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The exception is thrown if the application presents an invalid authorization 12 | * string in a request. 13 | */ 14 | public class InvalidAuthorizationException extends NoSQLException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * internal use only 20 | * @param msg the exception message 21 | * @hidden 22 | */ 23 | public InvalidAuthorizationException(String msg) { 24 | super(msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/JsonParseException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import java.io.IOException; 11 | 12 | import com.fasterxml.jackson.core.JsonLocation; 13 | 14 | /** 15 | * An exception indicating a problem parsing JSON. This exception encapsulates 16 | * both illegal JSON as well as {@link IOException} errors during parsing. If 17 | * available the location in the JSON document is provided. 18 | */ 19 | public class JsonParseException extends NoSQLException { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | /** 24 | * @hidden 25 | */ 26 | private JsonLocation location; 27 | 28 | /** 29 | * internal use only 30 | * @param msg the exception message 31 | * @hidden 32 | */ 33 | public JsonParseException(String msg) { 34 | super(msg); 35 | } 36 | 37 | /** 38 | * internal use only 39 | * @param msg the exception message 40 | * @param location the exception location in the input 41 | * @hidden 42 | */ 43 | public JsonParseException(String msg, JsonLocation location) { 44 | super(msg); 45 | this.location = location; 46 | } 47 | 48 | /** 49 | * Returns the column number of the error within a line if available, 50 | * otherwise a negative number is returned. 51 | * 52 | * @return the column, or -1 53 | */ 54 | public int getColumn() { 55 | if (location != null && location != JsonLocation.NA) { 56 | return location.getColumnNr(); 57 | } 58 | return -1; 59 | } 60 | 61 | /** 62 | * Returns the line number of the error within a line if available, otherwise a 63 | * negative number is returned. 64 | * 65 | * @return the line, or -1 66 | */ 67 | public int getLine() { 68 | if (location != null && location != JsonLocation.NA) { 69 | return location.getLineNr(); 70 | } 71 | return -1; 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | StringBuilder sb = new StringBuilder(); 77 | sb.append(getMessage()).append(" at line "); 78 | sb.append(lineToString()).append(", column "); 79 | sb.append(columnToString()); 80 | return sb.toString(); 81 | } 82 | 83 | /** 84 | * Internal use only 85 | * @return the location of the exception in the input 86 | * @hidden 87 | */ 88 | public JsonLocation getLocation() { 89 | return location; 90 | } 91 | 92 | private String lineToString() { 93 | return (getLine() >= 0 ? Integer.toString(getLine()) : "n/a"); 94 | } 95 | 96 | private String columnToString() { 97 | return (getColumn() >= 0 ? Integer.toString(getColumn()) : "n/a"); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/KeySizeLimitException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * Thrown to indicate that an attempt has been made to create a row with a 14 | * primary key or index key size that exceeds the system defined limit. 15 | */ 16 | public class KeySizeLimitException extends ResourceLimitException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * internal use only 22 | * @param msg the exception message 23 | * @hidden 24 | */ 25 | public KeySizeLimitException(String msg) { 26 | super(msg); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/NoSQLException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * A base exception for most exceptions thrown by the driver. All of the 12 | * exceptions defined in this package extend this exception. The driver throws 13 | * Java exceptions such as {@link IllegalArgumentException} directly. 14 | */ 15 | public class NoSQLException extends RuntimeException { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | /** 20 | * internal use only 21 | * @param msg the message 22 | * @hidden 23 | */ 24 | public /*protected*/ NoSQLException(String msg) { 25 | super(msg + " (" + SDKVersion.VERSION + ")"); 26 | } 27 | 28 | /** 29 | * internal use only 30 | * @param msg the message 31 | * @param cause the cause 32 | * @hidden 33 | */ 34 | public /*protected*/ NoSQLException(String msg, Throwable cause) { 35 | super(msg + " (" + SDKVersion.VERSION + ")", cause); 36 | } 37 | 38 | /** 39 | * Returns whether this exception can be retried with a reasonable 40 | * expectation that it may succeed. Instances of {@link RetryableException} 41 | * will return true for this method. 42 | * 43 | * @return true if this exception can be retried 44 | */ 45 | public boolean okToRetry() { 46 | return false; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/NoSQLHandleFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import static oracle.nosql.driver.util.CheckNull.requireNonNull; 11 | 12 | import oracle.nosql.driver.http.NoSQLHandleImpl; 13 | 14 | /** 15 | * Factory class used to produce handles to operate on tables. 16 | */ 17 | public class NoSQLHandleFactory { 18 | 19 | /** 20 | * Creates a handle that can be used to access tables. The application must 21 | * invoke {@link NoSQLHandle#close}, when it is done accessing the system to 22 | * free up resources associated with the handle. 23 | * 24 | * @param config the NoSQLHandle configuration parameters 25 | * 26 | * @return a valid {@link NoSQLHandle} instance, ready for use 27 | * 28 | * @throws IllegalArgumentException if an illegal configuration parameter 29 | * is specified. 30 | * 31 | * @see NoSQLHandle#close 32 | */ 33 | public static NoSQLHandle createNoSQLHandle(NoSQLHandleConfig config) { 34 | requireNonNull( 35 | config, 36 | "NoSQLHandleFactory.createNoSQLHandle: config cannot be null"); 37 | NoSQLHandleConfig configCopy = config.clone(); 38 | if (configCopy.getRetryHandler() == null) { 39 | /* 40 | * Default retry handler: 10 retries, default backoff 41 | */ 42 | configCopy.configureDefaultRetryHandler(10, 0); 43 | } 44 | return new NoSQLHandleImpl(configCopy); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/OperationNotSupportedException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The operation attempted is not supported. This may be related to 12 | * on-premises vs cloud service configurations. 13 | */ 14 | public class OperationNotSupportedException extends NoSQLException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * Internal use only 20 | * @param msg the exception message 21 | * @hidden 22 | */ 23 | public OperationNotSupportedException(String msg) { 24 | super(msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/OperationThrottlingException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * An exception that is thrown when a non-data operation is throttled. 14 | * This can happen if an application attempts too many control operations 15 | * such as table creation, deletion, or similar methods. Such operations 16 | * do not use throughput or capacity provisioned for a given table but 17 | * they consume system resources and their use is limited. 18 | *

19 | * Operations resulting in this exception can be retried but it is recommended 20 | * that callers use a relatively large delay before retrying in order to 21 | * minimize the chance that a retry will also be throttled. 22 | */ 23 | public class OperationThrottlingException extends ThrottlingException { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | /** 28 | * Internal use only 29 | * @param msg the exception message 30 | * @hidden 31 | */ 32 | public OperationThrottlingException(String msg) { 33 | super(msg); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/PrepareQueryException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The query must be recompiled after DDL changes on the tables and/or 12 | * indexes that are accessed by the query. 13 | */ 14 | public class PrepareQueryException extends NoSQLException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * @hidden 20 | * @param msg the exception message 21 | */ 22 | public PrepareQueryException(String msg) { 23 | super(msg); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ReadThrottlingException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * This exception indicates that the provisioned read throughput has been 14 | * exceeded. 15 | *

16 | * Operations resulting in this exception can be retried but it is recommended 17 | * that callers use a delay before retrying in order to minimize the chance 18 | * that a retry will also be throttled. Applications should attempt to avoid 19 | * throttling exceptions by rate limiting themselves to the degree possible. 20 | *

21 | * Retries and behavior related to throttling can be managed by configuring 22 | * the default retry handler using 23 | * {@link NoSQLHandleConfig#configureDefaultRetryHandler} or by implementing 24 | * a {@link RetryHandler} and using {@link NoSQLHandleConfig#setRetryHandler}. 25 | */ 26 | public class ReadThrottlingException extends ThrottlingException { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * Internal use only 32 | * @param msg the exception message 33 | * @hidden 34 | */ 35 | public ReadThrottlingException(String msg) { 36 | super(msg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/RequestSizeLimitException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * Thrown to indicate that the size of a Request exceeds the system defined 14 | * limit. 15 | */ 16 | public class RequestSizeLimitException extends ResourceLimitException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @hidden 22 | * @param msg the exception message 23 | */ 24 | public RequestSizeLimitException(String msg) { 25 | super(msg); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/RequestTimeoutException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | package oracle.nosql.driver; 8 | 9 | /** 10 | * Thrown when a request cannot be processed because the configured timeout 11 | * interval is exceeded. If a retry handler is configured it is possible that 12 | * the request has been retried a number of times before the timeout occurs. 13 | */ 14 | public class RequestTimeoutException extends NoSQLException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * @hidden 20 | */ 21 | private volatile int timeoutMs; 22 | 23 | /** 24 | * @hidden 25 | * Internal use only. 26 | * 27 | * @param msg the message string for the timeout 28 | */ 29 | public RequestTimeoutException(String msg) { 30 | this(0, msg, null); 31 | } 32 | 33 | /** 34 | * @hidden 35 | * Internal use only. 36 | * 37 | * @param timeoutMs the timeout that was in effect, in milliseconds 38 | * @param msg the message string for the timeout 39 | */ 40 | public RequestTimeoutException(int timeoutMs, 41 | String msg) { 42 | this(timeoutMs, msg, null); 43 | } 44 | 45 | /** 46 | * @hidden 47 | * Internal use only. 48 | * 49 | * @param timeoutMs the timeout that was in effect, in milliseconds 50 | * @param msg the message string for the timeout 51 | * @param cause the cause of the exception 52 | */ 53 | public RequestTimeoutException(int timeoutMs, 54 | String msg, 55 | Throwable cause) { 56 | super(msg, cause); 57 | this.timeoutMs = timeoutMs; 58 | } 59 | 60 | @Override 61 | public String getMessage() { 62 | StringBuilder sb = new StringBuilder(); 63 | sb.append(super.getMessage()); 64 | if (timeoutMs != 0) { 65 | sb.append(" Timeout: "); 66 | sb.append(timeoutMs); 67 | sb.append("ms"); 68 | } 69 | 70 | Throwable cause = getCause(); 71 | if (cause != null) { 72 | sb.append("\nCaused by: "); 73 | sb.append(cause.getClass().getName()); 74 | sb.append(": "); 75 | sb.append(cause.getMessage()); 76 | } 77 | return sb.toString(); 78 | } 79 | 80 | /** 81 | * Returns the timeout that was in effect for the operation. 82 | * 83 | * @return the timeout that was in use for the operation that timed out, 84 | * in milliseconds, if the timeout is not known it will be 0. 85 | */ 86 | public int getTimeoutMs() { 87 | return timeoutMs; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ResourceExistsException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The operation attempted to create a resource but it already exists. 12 | */ 13 | public class ResourceExistsException extends NoSQLException { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | /** 18 | * internal use only 19 | * @param msg the exception message 20 | * @hidden 21 | */ 22 | public ResourceExistsException(String msg) { 23 | super(msg); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ResourceLimitException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * This is a base class for exceptions that result from reaching a limit for 14 | * a particular resource, such as number of tables, indexes, or a size limit 15 | * on data. It is never thrown directly. 16 | */ 17 | public class ResourceLimitException extends NoSQLException { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * @hidden 23 | */ 24 | protected ResourceLimitException(String msg) { 25 | super(msg); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The operation attempted to access a resource that does not exist 12 | * or is not in a visible state. 13 | */ 14 | public class ResourceNotFoundException extends NoSQLException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * internal use only 20 | * @param msg the exception message 21 | * @hidden 22 | */ 23 | public ResourceNotFoundException(String msg) { 24 | super(msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/RetryHandler.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import oracle.nosql.driver.ops.Request; 11 | 12 | /** 13 | * RetryHandler is called by the request handling system when a 14 | * {@link RetryableException} is thrown. It controls the number of retries 15 | * as well as frequency of retries using a delaying algorithm. A default 16 | * RetryHandler is always configured on a {@link NoSQLHandle} instance and 17 | * can be controlled or overridden using 18 | * {@link NoSQLHandleConfig#setRetryHandler} and 19 | * {@link NoSQLHandleConfig#configureDefaultRetryHandler} 20 | *

21 | * It is not recommended that applications rely on a RetryHandler for 22 | * regulating provisioned throughput. It is best to add rate limiting to the 23 | * application based on a table's capacity and access patterns to avoid 24 | * throttling exceptions: see {@link NoSQLHandleConfig#setRateLimitingEnabled}. 25 | *

26 | * Instances of this interface must be immutable so they can be shared 27 | * among threads. 28 | */ 29 | public interface RetryHandler { 30 | 31 | /** 32 | * Returns the number of retries that this handler instance will allow 33 | * before the exception is thrown to the application. 34 | * 35 | * @return the max number of retries 36 | */ 37 | int getNumRetries(); 38 | 39 | /** 40 | * This method is called when a {@link RetryableException} is 41 | * thrown and determines whether to perform a retry or not based 42 | * on the parameters. 43 | * 44 | * @param request the Request that has triggered the exception 45 | * 46 | * @param numRetries the number of retries that have occurred for the 47 | * operation 48 | * 49 | * @param re the exception that was thrown 50 | * 51 | * @return true if the operation should be retried, false if not, causing 52 | * the exception to be thrown to the application. 53 | */ 54 | boolean doRetry(Request request, int numRetries, RetryableException re); 55 | 56 | /** 57 | * This method is called when a {@link RetryableException} is thrown and it 58 | * is determined that the request will be retried based on the return value 59 | * of {@link #doRetry}. It provides a delay between retries. Most 60 | * implementations will sleep for some period of time. The method should not 61 | * return until the desired delay period has passed. Implementations should 62 | * not busy-wait in a tight loop. 63 | * 64 | * @param request the Request that has triggered the exception 65 | * 66 | * @param numRetries the number of retries that have occurred for the 67 | * operation 68 | * 69 | * @param re the exception that was thrown 70 | */ 71 | void delay(Request request, int numRetries, RetryableException re); 72 | } 73 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/RetryableException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * A base exception for all exceptions that may be retried with a reasonable 12 | * expectation that they may succeed on retry. 13 | */ 14 | public class RetryableException extends NoSQLException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * @hidden 20 | */ 21 | protected RetryableException(String msg) { 22 | super(msg); 23 | } 24 | 25 | /** 26 | * @hidden 27 | */ 28 | protected RetryableException(String msg, Throwable cause) { 29 | super(msg, cause); 30 | } 31 | 32 | @Override 33 | public boolean okToRetry() { 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/RowSizeLimitException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * Thrown to indicate that an attempt has been made to create a row with a 14 | * size that exceeds the system defined limit. 15 | */ 16 | public class RowSizeLimitException extends ResourceLimitException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @hidden 22 | * @param msg the exception message 23 | */ 24 | public RowSizeLimitException(String msg) { 25 | super(msg); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/SDKVersion.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | package oracle.nosql.driver; 8 | /** 9 | * Public class to manage SDK version information 10 | */ 11 | public class SDKVersion { 12 | /** 13 | * The full X.Y.Z version of the current SDK 14 | */ 15 | public static final String VERSION = "5.4.18-SNAPSHOT"; 16 | } 17 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/SecurityInfoNotReadyException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * An exception that is thrown when security information is not ready in the 14 | * system. This exception will occur as the system acquires security information 15 | * and must be retried in order for authorization to work properly. 16 | */ 17 | public class SecurityInfoNotReadyException extends RetryableException { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * @hidden 23 | * Simple constructor 24 | * @param msg the message 25 | */ 26 | public SecurityInfoNotReadyException(String msg) { 27 | super(msg); 28 | } 29 | 30 | /** 31 | * @hidden 32 | * Constructor with cause 33 | * @param msg the message 34 | * @param cause the cause 35 | */ 36 | public SecurityInfoNotReadyException(String msg, Throwable cause) { 37 | super(msg, cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/SystemException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * An exception that is thrown when there is an internal system problem. 12 | * Most system problems are temporary, so this is a retryable exception. 13 | */ 14 | public class SystemException extends RetryableException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * @hidden 20 | * Simple constructor 21 | * @param msg the message to use for the exception 22 | */ 23 | public SystemException(String msg) { 24 | super(msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/TableBusyException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * An exception that is thrown when a table operation fails because the 12 | * table is in use or busy. Only one modification operation at a time is 13 | * allowed on a table. 14 | * 15 | * @deprecated this class is no longer used 16 | */ 17 | @Deprecated 18 | public class TableBusyException extends RetryableException { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * @hidden 24 | * Simple constructor 25 | * @param msg the message to use for the exception 26 | */ 27 | public TableBusyException(String msg) { 28 | super(msg); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/TableExistsException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The operation attempted to create a table but the named table already exists. 12 | */ 13 | public class TableExistsException extends ResourceExistsException { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | /** 18 | * @hidden 19 | * @param msg the exception message 20 | */ 21 | public TableExistsException(String msg) { 22 | super(msg); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/TableLimitException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * Thrown to indicate that an attempt has been made to create a number of tables 14 | * that exceeds the system defined limit. 15 | */ 16 | public class TableLimitException extends ResourceLimitException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @hidden 22 | * @param msg the exception message 23 | */ 24 | public TableLimitException(String msg) { 25 | super(msg); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/TableNotFoundException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The operation attempted to access a table that does not exist 12 | * or is not in a visible state. 13 | */ 14 | public class TableNotFoundException extends ResourceNotFoundException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * @hidden 20 | * @param msg the exception message 21 | */ 22 | public TableNotFoundException(String msg) { 23 | super(msg); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/TableNotReadyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * An exception thrown when an operation is attempted on a replicated table 14 | * that is not yet fully initialized. 15 | * 16 | * @since 5.4.13 17 | */ 18 | public class TableNotReadyException extends RetryableException { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * @hidden 24 | * @param msg the exception message 25 | */ 26 | public TableNotReadyException(String msg) { 27 | super(msg); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/TableSizeException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * An exception indicating a table size limit has been exceeded by writing more 12 | * data than the table can support. This exception is not retryable because the 13 | * conditions that lead to it being thrown, while potentially transient, 14 | * typically require user intervention. 15 | */ 16 | public class TableSizeException extends NoSQLException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @hidden 22 | * 23 | * Constructs an instance of TableSizeException. 24 | * @param msg the detail message 25 | */ 26 | public TableSizeException(String msg) { 27 | super(msg); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ThrottlingException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * ThrottlingException is a base class for exceptions that indicate the 14 | * application has exceeded a provisioned or implicit limit in terms 15 | * of size of data accessed or frequency of operation. 16 | *

17 | * Operations resulting in this exception can be retried but it is recommended 18 | * that callers use a delay before retrying in order to minimize the chance 19 | * that a retry will also be throttled. 20 | *

21 | * It is recommended that applications use rate limiting to avoid these 22 | * exceptions. 23 | */ 24 | public class ThrottlingException extends RetryableException { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** 29 | * @hidden 30 | */ 31 | protected ThrottlingException(String msg) { 32 | super(msg); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/UnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * The exception is thrown if an application does not have sufficient permission 12 | * to perform a request. 13 | */ 14 | public class UnauthorizedException extends NoSQLException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * @hidden 20 | * @param msg the exception message 21 | */ 22 | public UnauthorizedException(String msg) { 23 | super(msg); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/UnsupportedProtocolException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * This exception is thrown if the server does not support the current 12 | * driver protocol version. 13 | * 14 | * @since 5.3.0 15 | */ 16 | public class UnsupportedProtocolException extends NoSQLException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @hidden 22 | * @param msg the exception message 23 | */ 24 | public UnsupportedProtocolException(String msg) { 25 | super(msg); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/UnsupportedQueryVersionException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * This exception is thrown if the server does not support the current 12 | * query protocol version. 13 | * 14 | * @since 5.4.14 15 | */ 16 | public class UnsupportedQueryVersionException extends NoSQLException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @hidden 22 | * @param msg the exception message 23 | */ 24 | public UnsupportedQueryVersionException(String msg) { 25 | super(msg); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/UserInfo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * On-premises only. 12 | *

13 | * A class that encapsulates the information associated with a user including 14 | * the id and user name in the system. 15 | */ 16 | public class UserInfo { 17 | final private String id; 18 | final private String name; 19 | 20 | /** 21 | * @hidden 22 | * 23 | * Constructs an instance of UserInfo as returned by 24 | * {@link NoSQLHandle#listUsers}. 25 | * @param id user id 26 | * @param name user name 27 | */ 28 | public UserInfo(String id, String name) { 29 | this.id = id; 30 | this.name = name; 31 | } 32 | 33 | /** 34 | * Returns the id associated with the user. 35 | * 36 | * @return the id string 37 | */ 38 | public String getId() { 39 | return id; 40 | } 41 | 42 | /** 43 | * Returns the name associated with the user. 44 | * 45 | * @return the name string 46 | */ 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "id:" + id + ", name:" + name; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/Version.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import java.util.Arrays; 11 | import oracle.nosql.driver.ops.DeleteRequest; 12 | import oracle.nosql.driver.ops.PutRequest; 13 | 14 | /** 15 | * Version is an opaque class that represents the version of a row in the 16 | * database. It is returned by successful {@link NoSQLHandle#get} operations 17 | * and can be used in {@link PutRequest#setMatchVersion} and 18 | * {@link DeleteRequest#setMatchVersion} to conditionally perform those 19 | * operations to ensure an atomic read-modify-write cycle. This is an opaque 20 | * object from an application perspective. 21 | *

22 | * Use of Version in this way adds cost to operations so it should be done only 23 | * if necessary 24 | */ 25 | public class Version { 26 | private final byte[] version; 27 | 28 | private Version(byte[] version) { 29 | this.version = version; 30 | } 31 | 32 | /** 33 | * @hidden 34 | * @return the version bytes 35 | */ 36 | public byte[] getBytes() { 37 | return version; 38 | } 39 | 40 | /** 41 | * Creates a Version instance from a byte[] which may have been acquired 42 | * from a query using the row_version() function which returns a FieldValue 43 | * of type BINARY. 44 | * 45 | * @param version the version to use 46 | * @return a new Version instance 47 | */ 48 | public static Version createVersion(byte[] version) { 49 | if (version == null) { 50 | return null; 51 | } 52 | return new Version(version); 53 | } 54 | 55 | /** 56 | * @hidden 57 | */ 58 | @Override 59 | public String toString() { 60 | if (version != null) { 61 | return "non-null Version"; 62 | } 63 | return "null Version"; 64 | } 65 | 66 | /** 67 | * @hidden 68 | */ 69 | @Override 70 | public boolean equals(Object other) { 71 | if (other instanceof Version) { 72 | return Arrays.equals(version, ((Version)other).version); 73 | } 74 | return false; 75 | } 76 | 77 | /** 78 | * @hidden 79 | */ 80 | @Override 81 | public int hashCode() { 82 | return Arrays.hashCode(version); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/WriteThrottlingException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | /** 11 | * Cloud service only. 12 | *

13 | * This exception indicates that the provisioned write throughput has been 14 | * exceeded. 15 | *

16 | * Operations resulting in this exception can be retried but it is recommended 17 | * that callers use a delay before retrying in order to minimize the chance 18 | * that a retry will also be throttled. Applications should attempt to avoid 19 | * throttling exceptions by rate limiting themselves to the degree possible. 20 | *

21 | * Retries and behavior related to throttling can be managed by configuring 22 | * the default retry handler using 23 | * {@link NoSQLHandleConfig#configureDefaultRetryHandler} or by implementing 24 | * a {@link RetryHandler} and using {@link NoSQLHandleConfig#setRetryHandler}. 25 | */ 26 | public class WriteThrottlingException extends ThrottlingException { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * @hidden 32 | * @param msg the exception message 33 | */ 34 | public WriteThrottlingException(String msg) { 35 | super(msg); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/httpclient/RequestState.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.httpclient; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.handler.codec.http.FullHttpResponse; 12 | import io.netty.handler.codec.http.HttpHeaders; 13 | import io.netty.handler.codec.http.HttpResponseStatus; 14 | 15 | /** 16 | * An instance of this class is created when a request is sent and is used to 17 | * collect response state. The instance is attached to a Channel's attribute 18 | * map, which means that this will work for HTTP/1.1 where channels are not 19 | * multiplexed, but will need to change for HTTP/2. 20 | * 21 | * This class is not thread-safe but is used in a safe, single-threaded manner 22 | * mapped 1:1 with a channel associated with a single HTTP request/response 23 | * cycle. 24 | * 25 | * At this time this object does not aggregate chunks of content into a single 26 | * buffer. It is expected that this is done using an HttpContentAggregator in 27 | * the pipeline and is only called with a FullHttpResponse. If aggregation is 28 | * desired here it can be added using a CompositeByteBuf and calls to add 29 | * content incrementally. 30 | */ 31 | class RequestState { 32 | 33 | private final ResponseHandler handler; 34 | private FullHttpResponse response; 35 | 36 | RequestState(ResponseHandler handler) { 37 | this.handler = handler; 38 | } 39 | 40 | ResponseHandler getHandler() { 41 | return handler; 42 | } 43 | 44 | HttpResponseStatus getStatus() { 45 | if (response != null) { 46 | return response.status(); 47 | } 48 | return null; 49 | } 50 | 51 | HttpHeaders getHeaders() { 52 | if (response != null) { 53 | return response.headers(); 54 | } 55 | return null; 56 | } 57 | 58 | int getContentSize() { 59 | ByteBuf buf = getBuf(); 60 | if (buf != null) { 61 | return buf.readableBytes(); 62 | } 63 | return -1; 64 | } 65 | 66 | ByteBuf getBuf() { 67 | if (response != null) { 68 | return response.content(); 69 | } 70 | return null; 71 | } 72 | 73 | void setResponse(FullHttpResponse response) { 74 | this.response = response; 75 | } 76 | 77 | FullHttpResponse getResponse() { 78 | return response; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/AuthenticationProfileProvider.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam; 9 | 10 | import java.io.InputStream; 11 | 12 | /** 13 | * Internal use only 14 | *

15 | * The provider to supplies key id and private key that are used to generate 16 | * request signature. 17 | * @hidden 18 | */ 19 | public interface AuthenticationProfileProvider { 20 | 21 | /** 22 | * Returns the keyId used to sign requests. 23 | * @return The keyId. 24 | */ 25 | String getKeyId(); 26 | 27 | 28 | /** 29 | * Returns a new InputStream of the private key. This stream should be 30 | * closed by the caller, implementations should return new streams each 31 | * time. 32 | * 33 | * @return A new InputStream. 34 | */ 35 | InputStream getPrivateKey(); 36 | 37 | 38 | /** 39 | * Returns the optional passphrase for the (encrypted) private key, 40 | * as a character array. 41 | * 42 | * @return The passphrase as character array, or null if not applicable 43 | */ 44 | char[] getPassphraseCharacters(); 45 | } 46 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/PrivateKeyFileSupplier.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam; 9 | 10 | import java.io.File; 11 | import java.io.FileInputStream; 12 | import java.io.FileNotFoundException; 13 | import java.io.InputStream; 14 | import java.util.function.Supplier; 15 | 16 | /** 17 | * @hidden 18 | * Internal use only 19 | *

20 | * The class to supplies private key from file. 21 | */ 22 | class PrivateKeyFileSupplier implements Supplier { 23 | 24 | private final File pemFile; 25 | 26 | public PrivateKeyFileSupplier(File pemFile) { 27 | this.pemFile = pemFile; 28 | } 29 | 30 | @Override 31 | public InputStream get() { 32 | try { 33 | return new FileInputStream(pemFile); 34 | } catch (FileNotFoundException e) { 35 | throw new IllegalArgumentException( 36 | "Could not find private key: " + pemFile, e); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/PrivateKeyProvider.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.nio.channels.Channels; 13 | import java.nio.channels.ReadableByteChannel; 14 | import java.security.PrivateKey; 15 | import java.security.interfaces.RSAPrivateKey; 16 | import java.util.Arrays; 17 | 18 | import oracle.nosql.driver.iam.pki.Pem; 19 | import oracle.nosql.driver.iam.pki.PemEncryptionException; 20 | import oracle.nosql.driver.iam.pki.PemException; 21 | 22 | /** 23 | * @hidden 24 | * Internal use only 25 | *

26 | * The RSA private key provider that loads and caches private key from input 27 | * stream using PEM key utilities in oci-java-sdk. 28 | * 29 | * See com.oracle.bmc.http.signing.internal.PEMStreamRSAPrivateKeySupplier 30 | * for reference. 31 | */ 32 | class PrivateKeyProvider { 33 | private RSAPrivateKey key = null; 34 | 35 | /** 36 | * Build private key based on {@link AuthenticationProfileProvider}. 37 | */ 38 | PrivateKeyProvider(AuthenticationProfileProvider provider) { 39 | this(provider.getPrivateKey(), provider.getPassphraseCharacters()); 40 | } 41 | 42 | /** 43 | * Build private key provider from given input stream. 44 | */ 45 | PrivateKeyProvider(InputStream keyInputStream, char[] passphrase) { 46 | getKeyInternal(keyInputStream, passphrase); 47 | } 48 | 49 | /** 50 | * Get the RSAPrivateKey 51 | */ 52 | RSAPrivateKey getKey() { 53 | return key; 54 | } 55 | 56 | void reload(InputStream keyInputStream, char[] passphrase) { 57 | getKeyInternal(keyInputStream, passphrase); 58 | } 59 | 60 | void getKeyInternal(InputStream keyInputStream, char[] passphrase) { 61 | try (ReadableByteChannel channel = Channels.newChannel(keyInputStream); 62 | Pem.Passphrase pemPassphrase = Pem.Passphrase.of(passphrase)){ 63 | PrivateKey privateKey = 64 | Pem.decoder().with(pemPassphrase).decodePrivateKey(channel); 65 | if (privateKey instanceof RSAPrivateKey) { 66 | key = (RSAPrivateKey) privateKey; 67 | } else { 68 | throw new IllegalArgumentException( 69 | "Must be RSA private key, but " + privateKey.toString()); 70 | } 71 | } catch (PemEncryptionException e) { 72 | throw new IllegalArgumentException( 73 | "The provided passphrase is incorrect.", e); 74 | } catch (PemException e) { 75 | throw new IllegalArgumentException( 76 | "Private key must be in PEM format", e); 77 | } catch (IOException e) { 78 | throw new IllegalArgumentException("Error reading private key", e); 79 | } finally { 80 | if (keyInputStream != null) { 81 | try { 82 | keyInputStream.close(); 83 | } catch (IOException e) { 84 | /* ignore */ 85 | } 86 | } 87 | if (passphrase != null) { 88 | Arrays.fill(passphrase, ' '); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/PrivateKeyStringSupplier.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.InputStream; 12 | import java.util.function.Supplier; 13 | 14 | /** 15 | * @hidden 16 | * Internal use only 17 | *

18 | * Supplier to provide private key in String format 19 | */ 20 | class PrivateKeyStringSupplier implements Supplier{ 21 | private final String privateKey; 22 | 23 | public PrivateKeyStringSupplier(String privateKeyString) { 24 | this.privateKey = privateKeyString; 25 | } 26 | 27 | @Override 28 | public InputStream get() { 29 | return new ByteArrayInputStream(privateKey.getBytes()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/UserAuthenticationProfileProvider.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam; 9 | 10 | /** 11 | * @hidden 12 | * Internal use only 13 | *

14 | *

15 | * The provider to supply user's authentication profile. 16 | */ 17 | interface UserAuthenticationProfileProvider 18 | extends AuthenticationProfileProvider { 19 | 20 | /** 21 | * Returns the fingerprint of the key being used. 22 | * 23 | * @return The fingerprint. 24 | */ 25 | String getFingerprint(); 26 | 27 | /** 28 | * Returns the tenant OCID. 29 | * 30 | * @return The tenant OCID. 31 | */ 32 | String getTenantId(); 33 | 34 | /** 35 | * Returns the user OCID. 36 | * 37 | * @return The user OCID. 38 | */ 39 | String getUserId(); 40 | } 41 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/package-info.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | /** 8 | * This package contains the public API for managing security for the 9 | * Oracle NoSQL Database Cloud using Oracle Cloud Infrastructure Identity 10 | * and Access Management (IAM). It is specific to the Cloud Service. 11 | *

12 | * All operations require a request signature that is used by the system to 13 | * authorize the operation. Managing IAM identities and policies is outside 14 | * of the scope of this documentation. The interfaces and classes in this 15 | * package are used to generate a request signature for each operation. 16 | *

17 | * {@link oracle.nosql.driver.iam.SignatureProvider} is the class that uses 18 | * authentication information of user, instance or resource principal to 19 | * generate a request signature for each operation. 20 | *

21 | * The request signature produced by provider comprises the following headers: 22 | *

    23 | *
  1. (request-target)
  2. 24 | *
  3. host
  4. 25 | *
  5. date
  6. 26 | *
  7. opc-obo-token (optional)
  8. 27 | *
28 | * Note that opc-obo-token header is included only if the provider 29 | * is created with instance principal for delegation. 30 | *

31 | * Example request signature: 32 | *

Signature version="1",keyId="keyId",algorithm="rsa-sha256", headers="(request-target) host date",signature="Base64(RSA-SHA256(signing_string))"
33 | *

34 | * SignatureProvider caches the request signature to improve the driver-side 35 | * performance. The default cache duration is 4 minutes. The cached signature 36 | * is refreshed asynchronously by a refresh task that is scheduled to renew 37 | * the cached signature 20 seconds ahead of the cache eviction. 38 | *

39 | * When SignatureProvider is created with a user principal either using 40 | * OCI configuration file or passing user authentication information directly, 41 | * the request signature is calculated with user's private key. See 42 | * Required Keys and OCIDs 43 | * for details of the required parameters. 44 | *

45 | * SignatureProvider can also be created with instance or resource principal. 46 | * See Calling Services from Instances 47 | * and 48 | * Accessing Other Oracle Cloud Infrastructure Resources from Running Functions 49 | * for details of the required configurations. When using instance or resource 50 | * principal, the request signature is created with a security token issued by 51 | * IAM. The security token is cached and refreshed by the provider transparently. 52 | * When refreshing or fetching the cached signature, the security token is 53 | * refreshed if token is close to its expiration time, by default 4 minutes 54 | * ahead. If the lifetime of the security token is shorter than 4 minutes, 55 | * the provider will always refresh at the token half-life. 56 | */ 57 | package oracle.nosql.driver.iam; 58 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/Eraser.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam.pki; 9 | 10 | import java.nio.ByteBuffer; 11 | 12 | /** Services for erasing the contents of mutable data structures such as arrays */ 13 | class Eraser { 14 | 15 | public static void erase(ByteBuffer byteBuffer) { 16 | if (byteBuffer != null) { 17 | if (byteBuffer.hasArray()) { 18 | erase(byteBuffer.array()); 19 | } else { 20 | eraseDirectBuffer(byteBuffer); 21 | } 22 | } 23 | } 24 | 25 | private static void eraseDirectBuffer(ByteBuffer byteBuffer) { 26 | byteBuffer.clear(); 27 | int length = byteBuffer.capacity(); 28 | for (int i = 0; i < length; i++) { 29 | byteBuffer.put(i, (byte) 0); 30 | } 31 | } 32 | 33 | public static void erase(byte[] bytes) { 34 | if (bytes != null) { 35 | final int length = bytes.length; 36 | /* zero out first character */ 37 | if (length > 0) { 38 | bytes[0] = 0; 39 | } 40 | /* copy zeroed byte to all other bytes in buf, faster than naive iteration 41 | * over each element in the array. 42 | * Duplicates bytes in 2, 4, 8, etc increments 43 | */ 44 | for (int pos = 1; pos < length; pos += pos) { 45 | System.arraycopy(bytes, 0, bytes, pos, Math.min(length - pos, pos)); 46 | } 47 | } 48 | } 49 | 50 | public static void erase(char[] chars) { 51 | if (chars != null) { 52 | final int length = chars.length; 53 | /* zero out first character */ 54 | if (length > 0) { 55 | chars[0] = 0; 56 | } 57 | /* copy zeroed byte to all other bytes in buf, faster than naive iteration 58 | * over each element in the array. 59 | * Duplicates bytes in 2, 4, 8, etc increments 60 | */ 61 | for (int pos = 1; pos < length; pos += pos) { 62 | System.arraycopy(chars, 0, chars, pos, Math.min(length - pos, pos)); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/Hex.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam.pki; 9 | 10 | abstract class Hex { 11 | private Hex() {} 12 | 13 | private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); 14 | 15 | static String encode(byte[] bytes) { 16 | char[] hexChars = new char[bytes.length * 2]; 17 | for (int j = 0; j < bytes.length; j++) { 18 | int v = bytes[j] & 0xFF; 19 | hexChars[j * 2] = HEX_ARRAY[v >>> 4]; 20 | hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F]; 21 | } 22 | return new String(hexChars); 23 | } 24 | 25 | static byte[] decode(final CharSequence hex) { 26 | final int length = hex.length(); 27 | byte[] bytes = new byte[length / 2]; 28 | for (int i = 0; i < length; ++i) { 29 | final int highNibble = Character.digit(hex.charAt(i), 16) << 4; 30 | final int lowNibble = Character.digit(hex.charAt(++i), 16); 31 | bytes[i / 2] = (byte) (highNibble + lowNibble); 32 | } 33 | return bytes; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/OpenSslPbeSecretKeyFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam.pki; 9 | 10 | import javax.crypto.spec.PBEKeySpec; 11 | import javax.crypto.spec.SecretKeySpec; 12 | import java.security.Key; 13 | import java.security.MessageDigest; 14 | import java.security.NoSuchAlgorithmException; 15 | import java.security.spec.InvalidKeySpecException; 16 | 17 | /** Generates the derived key for OpenSSL style encryption for PKCS1 encoded private keys */ 18 | class OpenSslPbeSecretKeyFactory { 19 | private final MessageDigest digest; 20 | 21 | OpenSslPbeSecretKeyFactory() { 22 | this(digest("MD5")); 23 | } 24 | 25 | OpenSslPbeSecretKeyFactory(final MessageDigest digest) { 26 | this.digest = digest; 27 | } 28 | 29 | private static MessageDigest digest(final String algorithmName) { 30 | try { 31 | return MessageDigest.getInstance(algorithmName); 32 | } catch (NoSuchAlgorithmException e) { 33 | throw new IllegalStateException(e); 34 | } 35 | } 36 | 37 | Key generateSecret(final PBEKeySpec pbeSpec) throws InvalidKeySpecException { 38 | OpenSslPbeSecretKeyGenerator generator = 39 | OpenSslPbeSecretKeyGenerator.builder() 40 | .password(pbeSpec.getPassword()) 41 | .salt(pbeSpec.getSalt()) 42 | .keyLength(pbeSpec.getKeyLength()) 43 | .build(); 44 | final byte[] keyBytes = generator.generate(); 45 | return new SecretKeySpec(keyBytes, "OpenSSLPBKDF"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/PemEncryptedKeyException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam.pki; 9 | 10 | public class PemEncryptedKeyException extends PemEncryptionException { 11 | /** 12 | * @hidden 13 | */ 14 | PemEncryptedKeyException() { 15 | super("Private Key is encrypted, but no passphrase configured"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/PemEncryptionException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam.pki; 9 | 10 | public class PemEncryptionException extends PemException { 11 | 12 | PemEncryptionException(Throwable cause) { 13 | super(cause); 14 | } 15 | 16 | PemEncryptionException(final String message) { 17 | super(message); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/PemException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam.pki; 9 | 10 | /** 11 | * Internal use 12 | * @hidden 13 | */ 14 | public class PemException extends IllegalStateException { 15 | 16 | PemException(final String message) { 17 | this(message, null); 18 | } 19 | 20 | PemException(final Throwable cause) { 21 | this(null, cause); 22 | } 23 | 24 | PemException(final String message, final Throwable cause) { 25 | super(message, cause); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/Sensitive.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam.pki; 9 | 10 | /** 11 | * Denotes a type which holds sensitive data and must be erased once it has been used. 12 | * 13 | *

Usage Model

14 | * 15 | * Use the try-with-resources idiom to assure the sensitive data is erased after use: 16 | * 17 | *
18 |  *     try ( Sensitive sensitive = ... ) {
19 |  *         // use the sensitive data
20 |  *         ...
21 |  *     }
22 |  * 
23 | */ 24 | interface Sensitive extends AutoCloseable { 25 | /** Must erase the contents of the passphrase */ 26 | @Override 27 | void close(); 28 | } 29 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/Text.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam.pki; 9 | 10 | import java.nio.ByteBuffer; 11 | import java.nio.CharBuffer; 12 | import java.nio.charset.StandardCharsets; 13 | import java.util.Arrays; 14 | 15 | import static oracle.nosql.driver.iam.pki.Eraser.erase; 16 | 17 | abstract class Text { 18 | 19 | private Text() {} 20 | 21 | static String of(byte[] utf8) { 22 | if (utf8 == null) { 23 | return null; 24 | } else { 25 | return new String(utf8, StandardCharsets.UTF_8); 26 | } 27 | } 28 | 29 | static String of(Utf8 utf8) { 30 | if (utf8 == null) { 31 | return null; 32 | } else { 33 | return of(utf8.bytes()); 34 | } 35 | } 36 | 37 | static byte[] bytes(String text) { 38 | if (text == null) { 39 | return null; 40 | } else { 41 | return text.getBytes(StandardCharsets.UTF_8); 42 | } 43 | } 44 | 45 | static char[] chars(final byte[] content) { 46 | final ByteBuffer bytes = ByteBuffer.wrap(content); 47 | final CharBuffer buffer = StandardCharsets.UTF_8.decode(bytes); 48 | 49 | final char[] buf = buffer.array(); 50 | final int position = buffer.position(); 51 | final int limit = buffer.limit(); 52 | final int offset = buffer.arrayOffset(); 53 | if (offset == 0 && position == 0 && limit == buf.length) { 54 | // no copy needed 55 | return buf; 56 | } else { 57 | // must copy subsection of backing array 58 | final char[] chars = Arrays.copyOfRange(buf, offset + position, offset + limit); 59 | Eraser.erase(buf); 60 | return chars; 61 | } 62 | } 63 | 64 | static byte[] bytes(final CharBuffer text) { 65 | if (text == null) { 66 | return null; 67 | } else { 68 | final CharBuffer chars = text.asReadOnlyBuffer(); 69 | final ByteBuffer buffer = StandardCharsets.UTF_8.encode(chars); 70 | final byte[] buf = buffer.array(); 71 | 72 | final int position = buffer.position(); 73 | final int limit = buffer.limit(); 74 | final int offset = buffer.arrayOffset(); 75 | if (offset == 0 && position == 0 && limit == buf.length) { 76 | // no copy needed 77 | return buf; 78 | } else { 79 | // must copy subsection of backing array 80 | final byte[] bytes = Arrays.copyOfRange(buf, offset + position, offset + limit); 81 | Eraser.erase(buf); 82 | return bytes; 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/iam/pki/package-info.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | /** 8 | * This package is the clone of com.oracle.bmc.http.client.pki in oci-java-sdk 9 | */ 10 | package oracle.nosql.driver.iam.pki; 11 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/kv/AuthenticationException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.kv; 9 | 10 | import oracle.nosql.driver.NoSQLException; 11 | 12 | /** 13 | * On-premises only. 14 | *

15 | * This exception is thrown when use StoreAccessTokenProvider in following 16 | * cases: 17 | *

    18 | *
  • Authentication information was not provided in the request header 19 | *
  • 20 | *
  • The authentication session has expired. By default 21 | * {@link StoreAccessTokenProvider} will automatically retry 22 | * authentication operation based on its authentication information
  • 23 | *
24 | */ 25 | public class AuthenticationException extends NoSQLException { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | /** 30 | * internal use only 31 | * @param msg the exception message 32 | * @hidden 33 | */ 34 | public AuthenticationException(String msg) { 35 | super(msg); 36 | } 37 | 38 | /** 39 | * internal use only 40 | * @param msg the exception message 41 | * @param cause the cause 42 | * @hidden 43 | */ 44 | public AuthenticationException(String msg, Throwable cause) { 45 | super(msg, cause); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/kv/package-info.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | /** 8 | * This package contains classes that are specific to using the driver 9 | * on-premises and not applicable to the Cloud Service. 10 | */ 11 | package oracle.nosql.driver.kv; 12 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/DurableRequest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops; 9 | 10 | import oracle.nosql.driver.Durability; 11 | 12 | /** 13 | * Represents a base class for operations that support a 14 | * {@link Durability} setting. 15 | */ 16 | public abstract class DurableRequest extends Request { 17 | 18 | private Durability durability; 19 | 20 | protected DurableRequest() {} 21 | 22 | protected void setDurabilityInternal(Durability durability) { 23 | this.durability = durability; 24 | } 25 | 26 | /** 27 | * Returns the durability setting for this operation. 28 | * On-prem only. 29 | * 30 | * @return durability, if set. Otherwise null. 31 | */ 32 | public Durability getDurability() { 33 | return durability; 34 | } 35 | 36 | /** 37 | * @hidden 38 | */ 39 | @Override 40 | public boolean doesWrites() { 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/ListTablesResult.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops; 9 | 10 | import oracle.nosql.driver.NoSQLHandle; 11 | 12 | /** 13 | * Represents the result of a {@link NoSQLHandle#listTables} operation. 14 | *

15 | * On a successful operation the table names are available as well as the 16 | * index of the last returned table. Tables are returned in an array, sorted 17 | * alphabetically. 18 | * @see NoSQLHandle#listTables 19 | */ 20 | public class ListTablesResult extends Result { 21 | private String[] tables; 22 | private int lastIndexReturned; 23 | 24 | /** 25 | * Returns the array of table names returned by the operation. 26 | * 27 | * @return the table names 28 | */ 29 | public String[] getTables() { 30 | return tables; 31 | } 32 | 33 | /** 34 | * Returns the index of the last table name returned. This can be provided 35 | * to {@link ListTablesRequest} to be used as a starting point for listing 36 | * tables. 37 | * 38 | * @return the index 39 | */ 40 | public int getLastReturnedIndex() { 41 | return lastIndexReturned; 42 | } 43 | 44 | /** 45 | * Internal use only 46 | * @param tables the tables 47 | * @return this 48 | * @hidden 49 | */ 50 | public ListTablesResult setTables(String[] tables) { 51 | this.tables = tables; 52 | return this; 53 | } 54 | 55 | /** 56 | * Internal use only 57 | * @param lastIndexReturned the index 58 | * @return this 59 | * @hidden 60 | */ 61 | public ListTablesResult setLastIndexReturned(int lastIndexReturned) { 62 | this.lastIndexReturned = lastIndexReturned; 63 | return this; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | StringBuilder sb = new StringBuilder(); 69 | sb.append("["); 70 | for (int i = 0; i < tables.length; i++) { 71 | sb.append("\"").append(tables[i]).append("\""); 72 | if (i < (tables.length - 1)) { 73 | sb.append(","); 74 | } 75 | } 76 | sb.append("]"); 77 | return sb.toString(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/MultiDeleteResult.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops; 9 | 10 | import oracle.nosql.driver.NoSQLHandle; 11 | 12 | /** 13 | * Represents the result of a {@link NoSQLHandle#multiDelete} operation. 14 | *

15 | * On a successful operation the number of rows deleted is available using 16 | * {@link #getNumDeletions}. There is a limit to the amount of data consumed 17 | * by a single call. If there are still more rows to delete, the 18 | * continuation key can be get using {@link #getContinuationKey()}. 19 | * @see NoSQLHandle#multiDelete 20 | */ 21 | public class MultiDeleteResult extends Result { 22 | 23 | private byte[] continuationKey; 24 | private int nDeleted; 25 | 26 | /** 27 | * Returns the number of rows deleted from the table. 28 | * 29 | * @return the number of rows deleted 30 | */ 31 | public int getNumDeletions() { 32 | return nDeleted; 33 | } 34 | 35 | /** 36 | * Returns the continuation key where the next MultiDelete request resume 37 | * from. 38 | * 39 | * @return the continuation key, or null if there are no more rows to 40 | * delete. 41 | */ 42 | public byte[] getContinuationKey() { 43 | return continuationKey; 44 | } 45 | 46 | /* from Result */ 47 | 48 | /** 49 | * Returns the read throughput consumed by this operation, in KBytes. 50 | * This is the actual amount of data read by the operation. The number 51 | * of read units consumed is returned by {@link #getReadUnits} which may 52 | * be a larger number because this was an update operation. 53 | * 54 | * @return the read KBytes consumed 55 | */ 56 | public int getReadKB() { 57 | return super.getReadKBInternal(); 58 | } 59 | 60 | /** 61 | * Returns the write throughput consumed by this operation, in KBytes. 62 | * 63 | * @return the write KBytes consumed 64 | */ 65 | public int getWriteKB() { 66 | return super.getWriteKBInternal(); 67 | } 68 | 69 | /** 70 | * Returns the read throughput consumed by this operation, in read units. 71 | * This number may be larger than that returned by {@link #getReadKB} 72 | * because it was an update operation. 73 | * 74 | * @return the read units consumed 75 | */ 76 | public int getReadUnits() { 77 | return super.getReadUnitsInternal(); 78 | } 79 | 80 | /** 81 | * Returns the write throughput consumed by this operation, in write 82 | * units. 83 | * 84 | * @return the write units consumed 85 | */ 86 | public int getWriteUnits() { 87 | return super.getWriteUnitsInternal(); 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return "Deleted " + nDeleted + " rows"; 93 | } 94 | 95 | /** 96 | * Internal use only 97 | * @param nDeleted num deleted 98 | * @return this 99 | * @hidden 100 | */ 101 | public MultiDeleteResult setNumDeletions(int nDeleted) { 102 | this.nDeleted = nDeleted; 103 | return this; 104 | } 105 | 106 | /** 107 | * Internal use only 108 | * @param continuationKey the continuation key 109 | * @return this 110 | * @hidden 111 | */ 112 | public MultiDeleteResult setContinuationKey(byte[] continuationKey) { 113 | this.continuationKey = continuationKey; 114 | return this; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/PrepareResult.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops; 9 | 10 | import oracle.nosql.driver.Consistency; 11 | import oracle.nosql.driver.NoSQLHandle; 12 | 13 | /** 14 | * The result of a prepare operation. The returned 15 | * {@link PreparedStatement} can be re-used for query execution using 16 | * {@link QueryRequest#setPreparedStatement}. 17 | * 18 | * @see NoSQLHandle#prepare 19 | */ 20 | public class PrepareResult extends Result { 21 | 22 | private PreparedStatement preparedStatement; 23 | 24 | /** 25 | * Default constructor for PrepareResult 26 | */ 27 | public PrepareResult() {} 28 | 29 | /** 30 | * Returns the value of the prepared statement 31 | * 32 | * @return the prepared statement 33 | */ 34 | public PreparedStatement getPreparedStatement() { 35 | return preparedStatement; 36 | } 37 | 38 | /** 39 | * Internal use only 40 | * @param stmt the prepared statement 41 | * @return this 42 | * @hidden 43 | */ 44 | public PrepareResult setPreparedStatement(PreparedStatement stmt) { 45 | 46 | this.preparedStatement = stmt; 47 | return this; 48 | } 49 | 50 | /* from Result */ 51 | 52 | /** 53 | * Returns the read throughput consumed by this operation, in KBytes. 54 | * This is the actual amount of data read by the operation. The number 55 | * of read units consumed is returned by {@link #getReadUnits} which may 56 | * be a larger number if the operation used {@link Consistency#ABSOLUTE} 57 | * 58 | * @return the read KBytes consumed 59 | */ 60 | public int getReadKB() { 61 | return super.getReadKBInternal(); 62 | } 63 | 64 | /** 65 | * Returns the write throughput consumed by this operation, in KBytes. 66 | * 67 | * @return the write KBytes consumed 68 | */ 69 | public int getWriteKB() { 70 | return super.getWriteKBInternal(); 71 | } 72 | 73 | /** 74 | * Returns the read throughput consumed by this operation, in read units. 75 | * This number may be larger than that returned by {@link #getReadKB} if 76 | * the operation used {@link Consistency#ABSOLUTE} 77 | * 78 | * @return the read units consumed 79 | */ 80 | public int getReadUnits() { 81 | return super.getReadUnitsInternal(); 82 | } 83 | 84 | /** 85 | * Returns the write throughput consumed by this operation, in write 86 | * units. 87 | * 88 | * @return the write units consumed 89 | */ 90 | public int getWriteUnits() { 91 | return super.getWriteUnitsInternal(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/ReadRequest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops; 9 | 10 | import oracle.nosql.driver.Consistency; 11 | import oracle.nosql.driver.NoSQLHandle; 12 | import oracle.nosql.driver.NoSQLHandleConfig; 13 | 14 | /** 15 | * Represents a base class for read operations such as 16 | * {@link NoSQLHandle#get}. 17 | */ 18 | public abstract class ReadRequest extends Request { 19 | 20 | private Consistency consistency; 21 | 22 | protected ReadRequest() {} 23 | 24 | /** 25 | * internal use only 26 | * @return the Consistency 27 | * @hidden 28 | */ 29 | public Consistency getConsistencyInternal() { 30 | return consistency; 31 | } 32 | 33 | /** 34 | * @hidden 35 | */ 36 | protected void setConsistencyInternal(Consistency consistency) { 37 | this.consistency = consistency; 38 | } 39 | 40 | /** 41 | * 42 | * Return consistency if non-null. If null, return the default 43 | * Consistency from the config object 44 | * @hidden 45 | */ 46 | @Override 47 | public Request setDefaults(NoSQLHandleConfig config) { 48 | super.setDefaults(config); 49 | 50 | if (consistency == null) { 51 | consistency = config.getDefaultConsistency(); 52 | } 53 | return this; 54 | } 55 | 56 | protected void validateReadRequest(String requestName) { 57 | if (tableName == null || tableName.isEmpty()) { 58 | throw new IllegalArgumentException( 59 | (requestName + 60 | " requires table name")); 61 | } 62 | } 63 | 64 | /** 65 | * @hidden 66 | */ 67 | @Override 68 | public boolean doesReads() { 69 | return true; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/WriteRequest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops; 9 | 10 | import oracle.nosql.driver.NoSQLHandle; 11 | import oracle.nosql.driver.NoSQLHandleConfig; 12 | import oracle.nosql.driver.values.JsonUtils; 13 | 14 | /** 15 | * Represents a base class for the single row modifying operations 16 | * {@link NoSQLHandle#put} and {@link NoSQLHandle#delete}. 17 | */ 18 | public abstract class WriteRequest extends DurableRequest { 19 | 20 | private boolean returnRow; 21 | private String rowMetadata; 22 | 23 | protected WriteRequest() {} 24 | 25 | protected void setReturnRowInternal(boolean value) { 26 | this.returnRow = value; 27 | } 28 | 29 | /* getters are public for access by serializers */ 30 | 31 | /** 32 | * internal use only 33 | * @return true if there is a return row 34 | * @hidden 35 | */ 36 | public boolean getReturnRowInternal() { 37 | return returnRow; 38 | } 39 | 40 | /** 41 | * @hidden 42 | */ 43 | @Override 44 | public Request setDefaults(NoSQLHandleConfig config) { 45 | super.setDefaults(config); 46 | return this; 47 | } 48 | 49 | protected void validateWriteRequest(String requestName) { 50 | if (tableName == null || tableName.isEmpty()) { 51 | throw new IllegalArgumentException( 52 | (requestName + 53 | " requires table name")); 54 | } 55 | } 56 | 57 | /** 58 | * Returns the row metadata to be used for this request. 59 | * 60 | * @return the metadata, or null if not set 61 | * 62 | * @since 5.4.18 63 | */ 64 | public String getRowMetadata() { 65 | return rowMetadata; 66 | } 67 | 68 | /** 69 | * Sets the row metadata to use for this request. 70 | * This is an optional parameter. 71 | * The @parameter rowMetadata must be in a JSON Object format or null, 72 | * otherwise an IllegalArgumentException is thrown. 73 | * 74 | * @param rowMetadata the row metadata 75 | * @throws IllegalArgumentException if rowMetadata not null and invalid 76 | * JSON Object format 77 | * 78 | * @since 5.4.18 79 | * @return this 80 | */ 81 | public WriteRequest setRowMetadata(String rowMetadata) { 82 | if (rowMetadata == null) { 83 | this.rowMetadata = null; 84 | return this; 85 | } 86 | 87 | JsonUtils.validateJsonObject(rowMetadata); 88 | this.rowMetadata = rowMetadata; 89 | return this; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/package-info.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | /** 8 | * Contains the input and response classes used for Oracle NoSQL 9 | * Database operations. These include classes derived from 10 | * {@link oracle.nosql.driver.ops.Request} and 11 | * {@link oracle.nosql.driver.ops.Result}. 12 | *

13 | * {@link oracle.nosql.driver.ops.Request} instances are parameter objects that 14 | * hold required and optional state for a given request type and 15 | * operation. Some parameters are defaulted based on the 16 | * {@link oracle.nosql.driver.NoSQLHandleConfig} 17 | * and can be overridden in a specific request. Examples of these are timeouts 18 | * and {@link oracle.nosql.driver.Consistency}. Some parameters are required. 19 | * For example, most requests require a table name for the target table, 20 | * {@link oracle.nosql.driver.NoSQLHandle#put} requires a value, etc. 21 | *

22 | * Validation of parameter state is not performed until the object is used in a 23 | * request, so illegal state is not immediately detected. 24 | *

25 | * {@link oracle.nosql.driver.ops.Result} instances represent return state for 26 | * operations that succeed. All result instances contain information about 27 | * throughput used by that operation if available, in the form of 28 | * getReadUnits and getWriteUnits interfaces on the objects. 29 | * When used against an on-premises service resource consumption information is 30 | * not available and will be 0. 31 | *

32 | * {@link oracle.nosql.driver.ops.Request} and 33 | * {@link oracle.nosql.driver.ops.Result} instances are not thread-safe and not 34 | * intended to be shared. {@link oracle.nosql.driver.ops.Request} can be reused 35 | * and are not modified when used in operations, but they should not be modified 36 | * while in use by the system. 37 | */ 38 | package oracle.nosql.driver.ops; 39 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/DeleteRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.Version; 13 | import oracle.nosql.driver.ops.DeleteRequest; 14 | import oracle.nosql.driver.ops.DeleteResult; 15 | import oracle.nosql.driver.ops.Request; 16 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 17 | import oracle.nosql.driver.util.ByteInputStream; 18 | import oracle.nosql.driver.util.ByteOutputStream; 19 | 20 | class DeleteRequestSerializer extends BinaryProtocol implements Serializer { 21 | 22 | /* 23 | * The flag indicates if the serializer is used for a standalone request 24 | * or a sub operation of WriteMultiple request. 25 | * 26 | * If it is used to serialize the sub operation, then some information 27 | * like SerialVersion, Timeout, Namespace and TableName will be skipped 28 | * during serialization. 29 | */ 30 | private final boolean isSubRequest; 31 | 32 | DeleteRequestSerializer() { 33 | this(false); 34 | } 35 | 36 | DeleteRequestSerializer(boolean isSubRequest) { 37 | this.isSubRequest = isSubRequest; 38 | } 39 | 40 | @Override 41 | public void serialize(Request request, 42 | short serialVersion, 43 | ByteOutputStream out) 44 | throws IOException { 45 | 46 | DeleteRequest deleteRq = (DeleteRequest) request; 47 | Version matchVersion = deleteRq.getMatchVersion(); 48 | 49 | writeOpCode(out, (matchVersion != null ? OpCode.DELETE_IF_VERSION : 50 | OpCode.DELETE)); 51 | if (isSubRequest) { 52 | out.writeBoolean(deleteRq.getReturnRow()); 53 | } else { 54 | serializeWriteRequest(deleteRq, out, serialVersion); 55 | } 56 | writeFieldValue(out, deleteRq.getKey()); 57 | if (matchVersion != null) { 58 | writeVersion(out, matchVersion); 59 | } 60 | } 61 | 62 | @Override 63 | public DeleteResult deserialize(Request request, 64 | ByteInputStream in, 65 | short serialVersion) 66 | throws IOException { 67 | 68 | DeleteResult result = new DeleteResult(); 69 | deserializeConsumedCapacity(in, result); 70 | boolean success = in.readBoolean(); 71 | result.setSuccess(success); 72 | deserializeWriteResponse(in, result, serialVersion); 73 | return result; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/GetIndexesRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.GetIndexesRequest; 13 | import oracle.nosql.driver.ops.GetIndexesResult; 14 | import oracle.nosql.driver.ops.GetIndexesResult.IndexInfo; 15 | import oracle.nosql.driver.ops.Request; 16 | import oracle.nosql.driver.ops.Result; 17 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 18 | import oracle.nosql.driver.util.ByteInputStream; 19 | import oracle.nosql.driver.util.ByteOutputStream; 20 | 21 | class GetIndexesRequestSerializer extends BinaryProtocol 22 | implements Serializer { 23 | 24 | @Override 25 | public void serialize(Request request, 26 | short serialVersion, 27 | ByteOutputStream out) 28 | throws IOException { 29 | 30 | GetIndexesRequest getRq = (GetIndexesRequest) request; 31 | 32 | writeOpCode(out, OpCode.GET_INDEXES); 33 | serializeRequest(getRq, out); 34 | writeString(out, getRq.getTableName()); 35 | if (getRq.getIndexName() != null) { 36 | out.writeBoolean(true); 37 | writeString(out, getRq.getIndexName()); 38 | } else { 39 | out.writeBoolean(false); 40 | } 41 | } 42 | 43 | @Override 44 | public Result deserialize(Request request, 45 | ByteInputStream in, 46 | short serialVersion) 47 | throws IOException { 48 | 49 | GetIndexesResult result = new GetIndexesResult(); 50 | int numIndexes = readInt(in); 51 | IndexInfo[] indexes = new IndexInfo[numIndexes]; 52 | for (int i = 0; i < numIndexes; i++) { 53 | indexes[i] = deserializeIndexInfo(in); 54 | } 55 | result.setIndexes(indexes); 56 | return result; 57 | } 58 | 59 | private IndexInfo deserializeIndexInfo(ByteInputStream in) 60 | throws IOException { 61 | 62 | String indexName = readString(in); 63 | int nFields = readInt(in); 64 | String[] fieldNames = new String[nFields]; 65 | for (int n = 0; n < nFields; n++) { 66 | fieldNames[n] = readString(in); 67 | } 68 | return new IndexInfo(indexName, fieldNames, null); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/GetRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import static oracle.nosql.driver.util.BinaryProtocol.V2; 11 | import static oracle.nosql.driver.util.BinaryProtocol.V3; 12 | 13 | import java.io.IOException; 14 | 15 | import oracle.nosql.driver.ops.GetRequest; 16 | import oracle.nosql.driver.ops.GetResult; 17 | import oracle.nosql.driver.ops.Request; 18 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 19 | import oracle.nosql.driver.util.ByteInputStream; 20 | import oracle.nosql.driver.util.ByteOutputStream; 21 | 22 | class GetRequestSerializer extends BinaryProtocol implements Serializer { 23 | 24 | @Override 25 | public void serialize(Request request, 26 | short serialVersion, 27 | ByteOutputStream out) 28 | throws IOException { 29 | 30 | GetRequest getRq = (GetRequest) request; 31 | 32 | writeOpCode(out, OpCode.GET); 33 | serializeReadRequest(getRq, out); 34 | writeFieldValue(out, getRq.getKey()); 35 | } 36 | 37 | @Override 38 | public GetResult deserialize(Request request, 39 | ByteInputStream in, 40 | short serialVersion) 41 | throws IOException { 42 | 43 | GetResult result = new GetResult(); 44 | deserializeConsumedCapacity(in, result); 45 | if (serialVersion < V3) { 46 | result.setModificationTime(-1); 47 | } 48 | boolean hasRow = in.readBoolean(); 49 | if (hasRow) { 50 | result.setValue(readFieldValue(in).asMap()); 51 | result.setExpirationTime(readLong(in)); 52 | result.setVersion(readVersion(in)); 53 | if (serialVersion > V2) { 54 | result.setModificationTime(readLong(in)); 55 | } 56 | } 57 | return result; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/GetTableRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.GetTableRequest; 13 | import oracle.nosql.driver.ops.Request; 14 | import oracle.nosql.driver.ops.TableResult; 15 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 16 | import oracle.nosql.driver.util.ByteInputStream; 17 | import oracle.nosql.driver.util.ByteOutputStream; 18 | 19 | class GetTableRequestSerializer extends BinaryProtocol implements Serializer { 20 | 21 | @Override 22 | public void serialize(Request request, 23 | short serialVersion, 24 | ByteOutputStream out) 25 | throws IOException { 26 | 27 | GetTableRequest getRq = (GetTableRequest) request; 28 | 29 | writeOpCode(out, OpCode.GET_TABLE); 30 | serializeRequest(getRq, out); 31 | writeString(out, getRq.getTableName()); 32 | writeString(out, getRq.getOperationId()); 33 | } 34 | 35 | @Override 36 | public TableResult deserialize(Request request, 37 | ByteInputStream in, 38 | short serialVersion) 39 | throws IOException { 40 | 41 | return deserializeTableResult(in, serialVersion); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/ListTablesRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.ListTablesRequest; 13 | import oracle.nosql.driver.ops.ListTablesResult; 14 | import oracle.nosql.driver.ops.Request; 15 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 16 | import oracle.nosql.driver.util.ByteInputStream; 17 | import oracle.nosql.driver.util.ByteOutputStream; 18 | 19 | class ListTablesRequestSerializer extends BinaryProtocol implements Serializer { 20 | 21 | @Override 22 | public void serialize(Request request, 23 | short serialVersion, 24 | ByteOutputStream out) 25 | throws IOException { 26 | 27 | ListTablesRequest listRq = (ListTablesRequest) request; 28 | 29 | writeOpCode(out, OpCode.LIST_TABLES); 30 | serializeRequest(listRq, out); 31 | out.writeInt(listRq.getStartIndex()); 32 | out.writeInt(listRq.getLimit()); 33 | /* new in V2 */ 34 | writeString(out, listRq.getNamespace()); 35 | } 36 | 37 | @Override 38 | public ListTablesResult deserialize(Request request, 39 | ByteInputStream in, 40 | short serialVersion) 41 | throws IOException { 42 | 43 | ListTablesResult result = new ListTablesResult(); 44 | int numTables = readInt(in); 45 | String[] tables = new String[numTables]; 46 | for (int i = 0; i < numTables; i++) { 47 | tables[i] = readString(in); 48 | } 49 | result.setTables(tables); 50 | result.setLastIndexReturned(readInt(in)); 51 | return result; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/MultiDeleteRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.MultiDeleteRequest; 13 | import oracle.nosql.driver.ops.MultiDeleteResult; 14 | import oracle.nosql.driver.ops.Request; 15 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 16 | import oracle.nosql.driver.util.ByteInputStream; 17 | import oracle.nosql.driver.util.ByteOutputStream; 18 | 19 | class MultiDeleteRequestSerializer extends BinaryProtocol 20 | implements Serializer { 21 | 22 | @Override 23 | public void serialize(Request request, 24 | short serialVersion, 25 | ByteOutputStream out) 26 | throws IOException { 27 | 28 | MultiDeleteRequest mdRq = (MultiDeleteRequest) request; 29 | writeOpCode(out, OpCode.MULTI_DELETE); 30 | serializeRequest(mdRq, out); 31 | writeString(out, mdRq.getTableName()); 32 | writeDurability(out, mdRq.getDurability(), serialVersion); 33 | writeFieldValue(out, mdRq.getKey()); 34 | writeFieldRange(out, mdRq.getRange()); 35 | writeInt(out, mdRq.getMaxWriteKB()); 36 | writeByteArray(out, mdRq.getContinuationKey()); 37 | } 38 | 39 | @Override 40 | public MultiDeleteResult deserialize(Request request, 41 | ByteInputStream in, 42 | short serialVersion) 43 | throws IOException { 44 | 45 | MultiDeleteResult result = new MultiDeleteResult(); 46 | deserializeConsumedCapacity(in, result); 47 | result.setNumDeletions(readInt(in)); 48 | result.setContinuationKey(readByteArray(in)); 49 | return result; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/Serializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.Request; 13 | import oracle.nosql.driver.ops.Result; 14 | import oracle.nosql.driver.util.ByteInputStream; 15 | import oracle.nosql.driver.util.ByteOutputStream; 16 | 17 | /** 18 | * @hidden 19 | * An interface for serialization/deserialization of Requests and their Results 20 | */ 21 | public interface Serializer { 22 | 23 | /* 24 | * The interface to serialize a request 25 | */ 26 | void serialize(Request request, 27 | short serialVersion, 28 | ByteOutputStream out) throws IOException; 29 | 30 | /* 31 | * Deserialize a response 32 | */ 33 | Result deserialize(Request request, 34 | ByteInputStream in, 35 | short serialVersion) throws IOException; 36 | 37 | /* 38 | * The interface to serialize a query request. Same as above but 39 | * with an added query version parameter. 40 | */ 41 | default void serialize(Request request, 42 | short serialVersion, 43 | short queryVersion, 44 | ByteOutputStream out) throws IOException { 45 | throw new IllegalArgumentException("Query serialization not " + 46 | "supported for " + request.getClass().getName()); 47 | } 48 | 49 | /* 50 | * Deserialize a query response. Same as above but with an 51 | * added query version parameter. 52 | */ 53 | default Result deserialize(Request request, 54 | ByteInputStream in, 55 | short serialVersion, 56 | short queryVersion) throws IOException { 57 | throw new IllegalArgumentException("Query deserialization not " + 58 | "supported for " + request.getClass().getName()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/SerializerFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | import oracle.nosql.driver.util.ByteInputStream; 12 | import oracle.nosql.driver.util.ByteOutputStream; 13 | 14 | /** 15 | * @hidden 16 | */ 17 | public interface SerializerFactory { 18 | 19 | /* serializers */ 20 | Serializer createDeleteSerializer(); 21 | 22 | Serializer createGetSerializer(); 23 | 24 | Serializer createPutSerializer(); 25 | 26 | Serializer createQuerySerializer(); 27 | 28 | Serializer createPrepareSerializer(); 29 | 30 | Serializer createGetTableSerializer(); 31 | 32 | Serializer createGetTableUsageSerializer(); 33 | 34 | Serializer createListTablesSerializer(); 35 | 36 | Serializer createGetIndexesSerializer(); 37 | 38 | Serializer createTableOpSerializer(); 39 | 40 | Serializer createSystemOpSerializer(); 41 | 42 | Serializer createSystemStatusSerializer(); 43 | 44 | Serializer createWriteMultipleSerializer(); 45 | 46 | Serializer createMultiDeleteSerializer(); 47 | 48 | Serializer createAddReplicaSerializer(); 49 | 50 | Serializer createDropReplicaSerializer(); 51 | 52 | Serializer createGetReplicaStatsSerializer(); 53 | 54 | /* deserializers */ 55 | Serializer createDeleteDeserializer(); 56 | 57 | Serializer createGetDeserializer(); 58 | 59 | Serializer createPutDeserializer(); 60 | 61 | Serializer createQueryDeserializer(); 62 | 63 | Serializer createPrepareDeserializer(); 64 | 65 | Serializer createGetTableDeserializer(); 66 | 67 | Serializer createGetTableUsageDeserializer(); 68 | 69 | Serializer createListTablesDeserializer(); 70 | 71 | Serializer createGetIndexesDeserializer(); 72 | 73 | Serializer createTableOpDeserializer(); 74 | 75 | Serializer createSystemOpDeserializer(); 76 | 77 | Serializer createSystemStatusDeserializer(); 78 | 79 | Serializer createWriteMultipleDeserializer(); 80 | 81 | Serializer createMultiDeleteDeserializer(); 82 | 83 | Serializer createAddReplicaDeserializer(); 84 | 85 | Serializer createDropReplicaDeserializer(); 86 | 87 | Serializer createGetReplicaStatsDeserializer(); 88 | 89 | /* 90 | * These methods encapsulate differences in serializer streams 91 | */ 92 | default int readErrorCode(ByteInputStream bis) throws IOException { 93 | return 0; 94 | } 95 | 96 | default void writeSerialVersion(short serialVersion, ByteOutputStream bis) 97 | throws IOException { 98 | } 99 | 100 | default String getSerdeVersionString() { 101 | return null; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/SystemRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.Request; 13 | import oracle.nosql.driver.ops.SystemRequest; 14 | import oracle.nosql.driver.ops.SystemResult; 15 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 16 | import oracle.nosql.driver.util.ByteInputStream; 17 | import oracle.nosql.driver.util.ByteOutputStream; 18 | 19 | class SystemRequestSerializer extends BinaryProtocol implements Serializer { 20 | 21 | @Override 22 | public void serialize(Request request, 23 | short serialVersion, 24 | ByteOutputStream out) 25 | throws IOException { 26 | 27 | SystemRequest rq = (SystemRequest) request; 28 | 29 | writeOpCode(out, OpCode.SYSTEM_REQUEST); 30 | serializeRequest(rq, out); 31 | writeCharArrayAsUTF8(out, rq.getStatement()); 32 | } 33 | 34 | @Override 35 | public SystemResult deserialize(Request request, 36 | ByteInputStream in, 37 | short serialVersion) 38 | throws IOException { 39 | 40 | return deserializeSystemResult(in); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/SystemStatusRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.Request; 13 | import oracle.nosql.driver.ops.SystemStatusRequest; 14 | import oracle.nosql.driver.ops.SystemResult; 15 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 16 | import oracle.nosql.driver.util.ByteInputStream; 17 | import oracle.nosql.driver.util.ByteOutputStream; 18 | 19 | class SystemStatusRequestSerializer extends BinaryProtocol implements Serializer { 20 | 21 | @Override 22 | public void serialize(Request request, 23 | short serialVersion, 24 | ByteOutputStream out) 25 | throws IOException { 26 | 27 | SystemStatusRequest rq = (SystemStatusRequest) request; 28 | 29 | writeOpCode(out, OpCode.SYSTEM_STATUS_REQUEST); 30 | serializeRequest(rq, out); 31 | writeString(out, rq.getOperationId()); 32 | writeString(out, rq.getStatement()); 33 | } 34 | 35 | @Override 36 | public SystemResult deserialize(Request request, 37 | ByteInputStream in, 38 | short serialVersion) 39 | throws IOException { 40 | 41 | return deserializeSystemResult(in); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/TableRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.Request; 13 | import oracle.nosql.driver.ops.TableLimits; 14 | import oracle.nosql.driver.ops.TableRequest; 15 | import oracle.nosql.driver.ops.TableResult; 16 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 17 | import oracle.nosql.driver.util.ByteInputStream; 18 | import oracle.nosql.driver.util.ByteOutputStream; 19 | 20 | class TableRequestSerializer extends BinaryProtocol implements Serializer { 21 | 22 | @Override 23 | public void serialize(Request request, 24 | short serialVersion, 25 | ByteOutputStream out) 26 | throws IOException { 27 | 28 | TableRequest rq = (TableRequest) request; 29 | 30 | writeOpCode(out, OpCode.TABLE_REQUEST); 31 | serializeRequest(rq, out); 32 | writeString(out, rq.getStatement()); 33 | 34 | TableLimits limits = rq.getTableLimits(); 35 | if (limits != null) { 36 | out.writeBoolean(true); 37 | // TODO create serializer for limits 38 | out.writeInt(limits.getReadUnits()); 39 | out.writeInt(limits.getWriteUnits()); 40 | out.writeInt(limits.getStorageGB()); 41 | writeCapacityMode(out, limits.getMode(), serialVersion); 42 | if (rq.getTableName() != null) { 43 | /* table name may exist with limits */ 44 | out.writeBoolean(true); 45 | writeString(out, rq.getTableName()); 46 | } else { 47 | out.writeBoolean(false); 48 | } 49 | } else { 50 | out.writeBoolean(false); 51 | } 52 | } 53 | 54 | @Override 55 | public TableResult deserialize(Request request, 56 | ByteInputStream in, 57 | short serialVersion) 58 | throws IOException { 59 | 60 | return deserializeTableResult(in, serialVersion); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/ops/serde/TableUsageRequestSerializer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.ops.serde; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.Request; 13 | import oracle.nosql.driver.ops.TableUsageRequest; 14 | import oracle.nosql.driver.ops.TableUsageResult; 15 | import oracle.nosql.driver.ops.TableUsageResult.TableUsage; 16 | import oracle.nosql.driver.util.BinaryProtocol.OpCode; 17 | import oracle.nosql.driver.util.ByteInputStream; 18 | import oracle.nosql.driver.util.ByteOutputStream; 19 | 20 | class TableUsageRequestSerializer extends BinaryProtocol implements Serializer { 21 | 22 | @Override 23 | public void serialize(Request request, 24 | short serialVersion, 25 | ByteOutputStream out) 26 | throws IOException { 27 | 28 | TableUsageRequest getRq = (TableUsageRequest) request; 29 | 30 | writeOpCode(out, OpCode.GET_TABLE_USAGE); 31 | serializeRequest(getRq, out); 32 | writeString(out, getRq.getTableName()); 33 | writeLong(out, getRq.getStartTime()); 34 | writeLong(out, getRq.getEndTime()); 35 | writeInt(out, getRq.getLimit()); 36 | } 37 | 38 | @Override 39 | public TableUsageResult deserialize(Request request, 40 | ByteInputStream in, 41 | short serialVersion) 42 | throws IOException { 43 | 44 | TableUsageResult result = new TableUsageResult(); 45 | /* don't use tenantId, but it's in the result */ 46 | readString(in); // tenantId 47 | result.setTableName(readString(in)); 48 | int numResults = readInt(in); 49 | TableUsage[] usageRecords = new TableUsage[numResults]; 50 | for (int i = 0; i < numResults; i++) { 51 | usageRecords[i] = deserializeUsage(in); 52 | } 53 | result.setUsageRecords(usageRecords); 54 | return result; 55 | } 56 | 57 | private TableUsage deserializeUsage(ByteInputStream in) 58 | throws IOException { 59 | 60 | TableUsage usage = new TableUsage(); 61 | usage.startTimeMillis = readLong(in); 62 | usage.secondsInPeriod = readInt(in); 63 | usage.readUnits = readInt(in); 64 | usage.writeUnits = readInt(in); 65 | usage.storageGB = readInt(in); 66 | usage.readThrottleCount = readInt(in); 67 | usage.writeThrottleCount = readInt(in); 68 | usage.storageThrottleCount = readInt(in); 69 | return usage; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/AggrIterState.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | import java.math.BigDecimal; 11 | 12 | import oracle.nosql.driver.values.FieldValue; 13 | import oracle.nosql.driver.values.FieldValue.Type; 14 | import oracle.nosql.driver.values.NullValue; 15 | 16 | class AggrIterState extends PlanIterState { 17 | 18 | long theCount; 19 | 20 | long theLongSum; 21 | 22 | double theDoubleSum; 23 | 24 | BigDecimal theNumberSum = null; 25 | 26 | Type theSumType = Type.LONG; 27 | 28 | boolean theNullInputOnly = true; 29 | 30 | FieldValue theMinMax = NullValue.getInstance(); 31 | 32 | @Override 33 | public void reset(PlanIter iter) { 34 | super.reset(iter); 35 | theCount = 0; 36 | theLongSum = 0; 37 | theDoubleSum = 0; 38 | theNumberSum = null; 39 | theSumType = Type.LONG; 40 | theNullInputOnly = true; 41 | theMinMax = NullValue.getInstance(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/ConstIter.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.ops.serde.BinaryProtocol; 13 | import oracle.nosql.driver.values.FieldValue; 14 | import oracle.nosql.driver.util.ByteInputStream; 15 | 16 | /** 17 | * ConstIter represents a reference to a constant value in the query. 18 | * Such a reference will need to be "executed" at the driver side when 19 | * the constant appears in the OFFSET or LIMIT clause. 20 | */ 21 | public class ConstIter extends PlanIter { 22 | 23 | final FieldValue theValue; 24 | 25 | ConstIter(ByteInputStream in, short serialVersion) throws IOException { 26 | 27 | super(in, serialVersion); 28 | theValue = BinaryProtocol.readFieldValue(in); 29 | } 30 | 31 | @Override 32 | public PlanIterKind getKind() { 33 | return PlanIterKind.CONST; 34 | } 35 | 36 | @Override 37 | public void open(RuntimeControlBlock rcb) { 38 | rcb.setState(theStatePos, new PlanIterState()); 39 | rcb.setRegVal(theResultReg, theValue); 40 | } 41 | 42 | @Override 43 | public boolean next(RuntimeControlBlock rcb) { 44 | 45 | PlanIterState state = rcb.getState(theStatePos); 46 | 47 | if (state.isDone()) { 48 | return false; 49 | } 50 | 51 | state.done(); 52 | return true; 53 | } 54 | 55 | @Override 56 | public void reset(RuntimeControlBlock rcb) { 57 | PlanIterState state = rcb.getState(theStatePos); 58 | state.reset(this); 59 | } 60 | 61 | @Override 62 | public void close(RuntimeControlBlock rcb) { 63 | PlanIterState state = rcb.getState(theStatePos); 64 | if (state == null) { 65 | return; 66 | } 67 | state.close(); 68 | } 69 | 70 | FieldValue getValue() { 71 | return theValue; 72 | } 73 | 74 | @Override 75 | protected void displayContent(StringBuilder sb, QueryFormatter formatter) { 76 | formatter.indent(sb); 77 | sb.append(theValue.toJson()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/ExternalVarRefIter.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.values.FieldValue; 13 | import oracle.nosql.driver.util.ByteInputStream; 14 | import oracle.nosql.driver.util.SerializationUtil; 15 | 16 | /** 17 | * In general, ExternalVarRefIter represents a reference to an external variable 18 | * in the query. Such a reference will need to be "executed" at the driver side 19 | * when the variable appears in the OFFSET or LIMIT clause. 20 | * 21 | * ExternalVarRefIter simply returns the value that the variable is currently 22 | * bound to. This value is set by the app via the methods of QueryRequest. 23 | * 24 | * theName: 25 | * The name of the variable. Used only when displaying the execution plan 26 | * and in error messages. 27 | * 28 | * theId: 29 | * The variable id. It is used as an index into an array of FieldValues 30 | * in the RCB that stores the values of the external vars. 31 | */ 32 | public class ExternalVarRefIter extends PlanIter { 33 | 34 | private final String theName; 35 | 36 | private final int theId; 37 | 38 | ExternalVarRefIter( 39 | ByteInputStream in, 40 | short serialVersion) throws IOException { 41 | 42 | super(in, serialVersion); 43 | theName = SerializationUtil.readString(in); 44 | theId = readPositiveInt(in); 45 | } 46 | 47 | @Override 48 | public PlanIterKind getKind() { 49 | return PlanIterKind.EXTERNAL_VAR_REF; 50 | } 51 | 52 | @Override 53 | public void open(RuntimeControlBlock rcb) { 54 | rcb.setState(theStatePos, new PlanIterState()); 55 | } 56 | 57 | @Override 58 | public boolean next(RuntimeControlBlock rcb) { 59 | 60 | PlanIterState state = rcb.getState(theStatePos); 61 | 62 | if (state.isDone()) { 63 | return false; 64 | } 65 | 66 | FieldValue val = rcb.getExternalVar(theId); 67 | 68 | /* 69 | * val should not be null, because we check before starting query 70 | * execution that all the external vars have been bound. So this is 71 | * a sanity check. 72 | */ 73 | if (val == null) { 74 | throw new QueryStateException( 75 | "Variable " + theName + " has not been set"); 76 | } 77 | 78 | rcb.setRegVal(theResultReg, val); 79 | state.done(); 80 | return true; 81 | } 82 | 83 | @Override 84 | public void reset(RuntimeControlBlock rcb) { 85 | PlanIterState state = rcb.getState(theStatePos); 86 | state.reset(this); 87 | } 88 | 89 | @Override 90 | public void close(RuntimeControlBlock rcb) { 91 | PlanIterState state = rcb.getState(theStatePos); 92 | if (state == null) { 93 | return; 94 | } 95 | state.close(); 96 | } 97 | 98 | @Override 99 | protected void display(StringBuilder sb, QueryFormatter formatter) { 100 | formatter.indent(sb); 101 | displayContent(sb, formatter); 102 | displayRegs(sb); 103 | } 104 | 105 | @Override 106 | protected void displayContent(StringBuilder sb, QueryFormatter formatter) { 107 | sb.append("EXTENAL_VAR_REF("); 108 | sb.append(theName); 109 | sb.append(", ").append(theId); 110 | sb.append(")"); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/FuncSizeIter.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.values.ArrayValue; 13 | import oracle.nosql.driver.values.FieldValue; 14 | import oracle.nosql.driver.values.IntegerValue; 15 | import oracle.nosql.driver.values.MapValue; 16 | import oracle.nosql.driver.values.NullValue; 17 | import oracle.nosql.driver.util.ByteInputStream; 18 | 19 | public class FuncSizeIter extends PlanIter { 20 | 21 | private final PlanIter theInput; 22 | 23 | FuncSizeIter(ByteInputStream in, short serialVersion) throws IOException { 24 | super(in, serialVersion); 25 | theInput = deserializeIter(in, serialVersion); 26 | } 27 | 28 | @Override 29 | public PlanIterKind getKind() { 30 | return PlanIterKind.FN_SIZE; 31 | } 32 | 33 | @Override 34 | PlanIter getInputIter() { 35 | return theInput; 36 | } 37 | 38 | @Override 39 | public void open(RuntimeControlBlock rcb) { 40 | rcb.setState(theStatePos, new AggrIterState()); 41 | theInput.open(rcb); 42 | } 43 | 44 | @Override 45 | public void reset(RuntimeControlBlock rcb) { 46 | theInput.reset(rcb); 47 | PlanIterState state = rcb.getState(theStatePos); 48 | state.reset(this); 49 | } 50 | 51 | @Override 52 | public void close(RuntimeControlBlock rcb) { 53 | 54 | PlanIterState state = rcb.getState(theStatePos); 55 | if (state == null) { 56 | return; 57 | } 58 | 59 | theInput.close(rcb); 60 | state.close(); 61 | } 62 | 63 | @Override 64 | public boolean next(RuntimeControlBlock rcb) { 65 | 66 | PlanIterState state = rcb.getState(theStatePos); 67 | 68 | if (state.isDone()) { 69 | return false; 70 | } 71 | 72 | boolean more = theInput.next(rcb); 73 | 74 | if (!more) { 75 | state.done(); 76 | return false; 77 | } 78 | 79 | int size; 80 | 81 | FieldValue item = rcb.getRegVal(theInput.getResultReg()); 82 | 83 | if (item.isNull()) { 84 | rcb.setRegVal(theResultReg, NullValue.getInstance()); 85 | state.done(); 86 | return true; 87 | } 88 | 89 | if (item.isArray()) { 90 | size = ((ArrayValue)item).size(); 91 | } else if (item.isMap()) { 92 | size = ((MapValue)item).size(); 93 | } else { 94 | throw new QueryException( 95 | "Input to the size() function has wrong type\n" + 96 | "Expected a complex item. Actual item type is:\n" + 97 | item.getType(), getLocation()); 98 | } 99 | 100 | FieldValue res = new IntegerValue(size); 101 | rcb.setRegVal(theResultReg, res); 102 | return true; 103 | } 104 | 105 | @Override 106 | protected void displayContent(StringBuilder sb, QueryFormatter formatter) { 107 | theInput.display(sb, formatter); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/PlanIterState.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | public class PlanIterState { 11 | 12 | public static enum StateEnum { 13 | OPEN, 14 | RUNNING, 15 | DONE, 16 | CLOSED 17 | } 18 | 19 | private StateEnum theState; 20 | 21 | public PlanIterState() { 22 | theState = StateEnum.OPEN; 23 | } 24 | 25 | public boolean isOpen() { 26 | return theState == StateEnum.OPEN; 27 | } 28 | 29 | boolean isClosed() { 30 | return theState == StateEnum.CLOSED; 31 | } 32 | 33 | public boolean isDone() { 34 | return theState == StateEnum.DONE; 35 | } 36 | 37 | public void reset(PlanIter iter) { 38 | setState(StateEnum.OPEN); 39 | } 40 | 41 | public void close() { 42 | setState(StateEnum.CLOSED); 43 | } 44 | 45 | public void done() { 46 | setState(StateEnum.DONE); 47 | } 48 | 49 | public void setState(StateEnum v) { 50 | switch (theState) { 51 | case RUNNING: 52 | if (v == StateEnum.RUNNING || 53 | v == StateEnum.DONE || 54 | v == StateEnum.CLOSED || 55 | v == StateEnum.OPEN) { 56 | theState = v; 57 | return; 58 | } 59 | break; 60 | case DONE: 61 | if (v == StateEnum.OPEN || v == StateEnum.CLOSED) { 62 | theState = v; 63 | return; 64 | } 65 | break; 66 | case OPEN: 67 | /* 68 | * OPEN --> DONE transition is allowed for iterators that are "done" 69 | * on the 1st next() call after an open() or reset() call. In this 70 | * case, rather than setting the state to RUNNING on entrance to the 71 | * next() call and then setting the state again to DONE before 72 | * returning from the same next() call, we allow a direct transition 73 | * from OPEN to DONE. 74 | */ 75 | if (v == StateEnum.OPEN || 76 | v == StateEnum.RUNNING || 77 | v == StateEnum.CLOSED || 78 | v == StateEnum.DONE) { 79 | theState = v; 80 | return; 81 | } 82 | break; 83 | case CLOSED: 84 | break; 85 | } 86 | 87 | throw new QueryStateException( 88 | "Wrong state transition for iterator " + getClass() + 89 | ". Current state: " + theState + " New state: " + v); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/QueryFormatter.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | /** 11 | * A simple class to hold query expression and plan formatting information, 12 | * such as indent level. A new instance of this class is passed to 13 | * display() methods. 14 | * 15 | * theIndent: 16 | * The current number of space chars to be printed as indentation when 17 | * displaying the expression tree or the query execution plan. 18 | */ 19 | public class QueryFormatter { 20 | 21 | private final int theIndentIncrement; 22 | 23 | private int theIndent; 24 | 25 | public QueryFormatter(int increment) { 26 | theIndentIncrement = increment; 27 | } 28 | 29 | public QueryFormatter() { 30 | theIndentIncrement = 2; 31 | } 32 | 33 | public int getIndent() { 34 | return theIndent; 35 | } 36 | 37 | public int getIndentIncrement() { 38 | return theIndentIncrement; 39 | } 40 | 41 | public void setIndent(int v) { 42 | theIndent = v; 43 | } 44 | 45 | public void incIndent() { 46 | theIndent += theIndentIncrement; 47 | } 48 | 49 | public void decIndent() { 50 | theIndent -= theIndentIncrement; 51 | } 52 | 53 | public void indent(StringBuilder sb) { 54 | for (int i = 0; i < theIndent; ++i) { 55 | sb.append(' '); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/QueryStateException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | import java.io.PrintWriter; 11 | import java.io.StringWriter; 12 | 13 | /** 14 | * An internal class that encapsulates illegal states in the query engine. 15 | * The query engine operates inside clients and servers and cannot safely 16 | * throw IllegalStateException as that can crash the server. This exception is 17 | * used to indicate problems in the engine that are most likely query engine 18 | * bugs but are not otherwise fatal to the system. 19 | */ 20 | public class QueryStateException extends IllegalStateException { 21 | 22 | static final long serialVersionUID = 1; 23 | 24 | private final String stackTrace; 25 | 26 | public QueryStateException(String message) { 27 | super("Unexpected state in query engine:\n" + message); 28 | 29 | final StringWriter sw = new StringWriter(500); 30 | new RuntimeException().printStackTrace(new PrintWriter(sw)); 31 | stackTrace = sw.toString(); 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | final StringBuilder sb = new StringBuilder(1000); 37 | sb.append(super.toString()); 38 | sb.append("\nStack trace: "); 39 | sb.append(stackTrace); 40 | return sb.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/SortSpec.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.util.ByteInputStream; 13 | 14 | /** 15 | * The order-by clause, for each sort expression allows for an optional 16 | * "sort spec", which specifies the relative order of NULLs (less than or 17 | * greater than all other values) and whether the values returned by the 18 | * sort expr should be sorted in ascending or descending order. 19 | * 20 | * The SortSpec class stores these two pieces of information. 21 | */ 22 | public class SortSpec { 23 | 24 | public final boolean theIsDesc; 25 | 26 | public final boolean theNullsFirst; 27 | 28 | SortSpec() { 29 | theIsDesc = false; 30 | theNullsFirst = false; 31 | } 32 | 33 | public SortSpec(ByteInputStream in) throws IOException { 34 | theIsDesc = in.readBoolean(); 35 | theNullsFirst = in.readBoolean(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/TopologyInfo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | import java.util.Arrays; 11 | 12 | public class TopologyInfo { 13 | 14 | private int theSeqNum = -1; 15 | 16 | private int[] theShardIds; 17 | 18 | public TopologyInfo(int seqNum, int[] shardIds) { 19 | if (shardIds == null) { 20 | throw new IllegalArgumentException("TopologyInfo shardIds must not be null"); 21 | } 22 | theSeqNum = seqNum; 23 | theShardIds = shardIds; 24 | } 25 | 26 | public int getSeqNum() { 27 | return theSeqNum; 28 | } 29 | 30 | int numShards() { 31 | return theShardIds.length; 32 | } 33 | 34 | int getShardId(int i) { 35 | return theShardIds[i]; 36 | } 37 | 38 | int getLastShardId() { 39 | return theShardIds[theShardIds.length-1]; 40 | } 41 | 42 | int[] getShardIds() { 43 | return theShardIds; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | 49 | TopologyInfo other = (TopologyInfo)o; 50 | 51 | if (this == other || 52 | theSeqNum == other.theSeqNum || 53 | Arrays.equals(theShardIds, other.theShardIds)) { 54 | return true; 55 | } 56 | 57 | return false; 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return theSeqNum; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | 68 | StringBuilder sb = new StringBuilder(); 69 | sb.append("seqNum = ").append(theSeqNum); 70 | sb.append(" shards ids = [ "); 71 | for (int sid : theShardIds) { 72 | sb.append(sid).append(" "); 73 | } 74 | sb.append("]"); 75 | 76 | return sb.toString(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/query/VarRefIter.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.query; 9 | 10 | import java.io.IOException; 11 | 12 | import oracle.nosql.driver.util.ByteInputStream; 13 | import oracle.nosql.driver.util.SerializationUtil; 14 | 15 | /** 16 | * VarRefIter represents a reference to a non-external variable in the query. 17 | * It simply returns the value that the variable is currently bound to. This 18 | * value is computed by the variable's "domain iterator" (the iterator that 19 | * evaluates the domain expression of the variable). The domain iterator stores 20 | * the value in theResultReg of this VarRefIter. 21 | * 22 | * In the context of the driver, an implicit internal variable is used 23 | * to represent the results arriving from the proxy. All other expressions that 24 | * are computed at the driver operate on these results, so all such expressions 25 | * reference this variable. This is analogous to the internal variable used in 26 | * kvstore to represent the table alias in the FROM clause. 27 | * 28 | * theName: 29 | * The name of the variable. Used only when displaying the execution plan. 30 | */ 31 | public class VarRefIter extends PlanIter { 32 | 33 | private final String theName; 34 | 35 | VarRefIter(ByteInputStream in, short serialVersion) throws IOException { 36 | 37 | super(in, serialVersion); 38 | theName = SerializationUtil.readString(in); 39 | } 40 | 41 | @Override 42 | public PlanIterKind getKind() { 43 | return PlanIterKind.VAR_REF; 44 | } 45 | 46 | @Override 47 | public void open(RuntimeControlBlock rcb) { 48 | rcb.setState(theStatePos, new PlanIterState()); 49 | } 50 | 51 | @Override 52 | public boolean next(RuntimeControlBlock rcb) { 53 | 54 | PlanIterState state = rcb.getState(theStatePos); 55 | 56 | if (state.isDone()) { 57 | if (rcb.getTraceLevel() >= 4) { 58 | rcb.trace("No Value for variable " + theName + " in register " + 59 | theResultReg); 60 | } 61 | return false; 62 | } 63 | 64 | if (rcb.getTraceLevel() >= 4) { 65 | rcb.trace("Value for variable " + theName + " in register " + 66 | theResultReg + ":\n" + rcb.getRegVal(theResultReg)); 67 | } 68 | 69 | state.done(); 70 | return true; 71 | } 72 | 73 | @Override 74 | public void reset(RuntimeControlBlock rcb) { 75 | PlanIterState state = rcb.getState(theStatePos); 76 | state.reset(this); 77 | } 78 | 79 | @Override 80 | public void close(RuntimeControlBlock rcb) { 81 | 82 | PlanIterState state = rcb.getState(theStatePos); 83 | if (state == null) { 84 | return; 85 | } 86 | 87 | state.close(); 88 | } 89 | 90 | @Override 91 | protected void display(StringBuilder sb, QueryFormatter formatter) { 92 | formatter.indent(sb); 93 | displayContent(sb, formatter); 94 | displayRegs(sb); 95 | } 96 | 97 | @Override 98 | protected void displayContent(StringBuilder sb, QueryFormatter formatter) { 99 | sb.append("VAR_REF("); 100 | sb.append(theName); 101 | sb.append(")"); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/util/ByteInputStream.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.util; 9 | 10 | import java.io.DataInput; 11 | 12 | /** 13 | * An extension of DataInput that provides access to methods 14 | * to get and set offsets into the byte buffer that underlies the stream. 15 | */ 16 | 17 | public interface ByteInputStream extends DataInput, AutoCloseable { 18 | 19 | /** 20 | * Returns the current read offset 21 | * @return the offset 22 | */ 23 | public int getOffset(); 24 | 25 | /** 26 | * Returns true if the backing buffer is a direct buffer, indicating 27 | * that the underlying byte array is not accessible via the array() call. 28 | * @return true if direct 29 | */ 30 | public boolean isDirect(); 31 | 32 | /** 33 | * Returns the backing byte array 34 | * @return the array 35 | */ 36 | public byte[] array(); 37 | 38 | 39 | /** 40 | * Sets the read offset. It can only be set smaller than the current 41 | * offset 42 | * @param offset the offset 43 | * @throws IllegalArgumentException if the offset exceeds the current offset 44 | */ 45 | public void setOffset(int offset); 46 | 47 | /** 48 | * Skips the specified number of bytes 49 | * @param toSkip the number of bytes 50 | * @throws IllegalArgumentException if toSkip exceeds the capacity of 51 | * the underlying stream 52 | */ 53 | public void skip(int toSkip); 54 | 55 | /** 56 | * This override avoids the default signature of Closeable that throws 57 | * Exception 58 | */ 59 | @Override 60 | public void close(); 61 | 62 | /** 63 | * Ensure that the buffer has at least this many bytes available to read 64 | * from the backing array. 65 | * @param nbytes the number of bytes required 66 | * @throws IllegalArgumentException if the specified number of bytes are 67 | * not available 68 | */ 69 | public void ensureCapacity(int nbytes); 70 | } 71 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/util/ByteOutputStream.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.util; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * An extension of DataOutput that operates on an underlying stream and 14 | * provides access to methods to get and set offsets into the buffer 15 | * that underlies the stream. 16 | */ 17 | public interface ByteOutputStream extends java.io.DataOutput, AutoCloseable { 18 | 19 | /** 20 | * Returns the current write offset into the byte buffer 21 | * @return the offset 22 | */ 23 | public int getOffset(); 24 | 25 | /** 26 | * Returns true if the backing buffer is a direct buffer, indicating 27 | * that the underlying byte array is not accessible via the array() call. 28 | * @return true if direct 29 | */ 30 | public boolean isDirect(); 31 | 32 | /** 33 | * Returns the backing byte array 34 | * @return the array 35 | */ 36 | public byte[] array(); 37 | 38 | /** 39 | * Sets the current write offset into the byte buffer 40 | * @param index the offset/index 41 | */ 42 | public void setWriteIndex(int index); 43 | 44 | /** 45 | * Skip numBytes, resetting the offset. 46 | * @param numBytes the number of bytes to skip 47 | */ 48 | public void skip(int numBytes); 49 | 50 | /** 51 | * Writes the value at the specified offset. The offset must be less 52 | * than the current offset. 53 | * @param offset the offset 54 | * @param value the value to write 55 | * @throws IOException if an I/O error occurs 56 | * @throws IllegalArgumentException if the offset exceeds the current offset 57 | */ 58 | public void writeIntAtOffset(int offset, int value) 59 | throws IOException; 60 | 61 | /** 62 | * Writes the value at the specified offset. The offset must be less 63 | * than the current offset. 64 | * @param offset the offset 65 | * @param value the value to write 66 | * @throws IOException if an I/O error occurs 67 | * @throws IllegalArgumentException if the offset exceeds the current offset 68 | */ 69 | public void writeBooleanAtOffset(int offset, boolean value) 70 | throws IOException; 71 | 72 | /** 73 | * Writes the byte array at the specified offset. The offset must be less 74 | * than the current offset. 75 | * @param offset the offset 76 | * @param value the value to write 77 | * @throws IOException if an I/O error occurs 78 | * @throws IllegalArgumentException if the offset exceeds the current offset 79 | */ 80 | public void writeArrayAtOffset(int offset, byte[] value) 81 | throws IOException; 82 | 83 | /** 84 | * This override avoids the default signature of Closeable that throws 85 | * Exception 86 | */ 87 | @Override 88 | public void close(); 89 | 90 | /** 91 | * Ensure that the buffer has at least this many bytes available for 92 | * writing in the backing array. If the backing array automatically 93 | * grows it will be reallocated to a larger size and an exception is 94 | * not thrown unless there is insufficient memory available. 95 | * 96 | * @param nbytes the number of bytes required 97 | * @throws IllegalArgumentException if the specified number of bytes are 98 | * not available and the buffer does not grow on demand 99 | */ 100 | public void ensureCapacity(int nbytes); 101 | } 102 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/util/CheckNull.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.util; 9 | 10 | import java.util.Objects; 11 | 12 | /** 13 | * @hidden 14 | * Wrapper for calls to Objects.requireNonNull 15 | */ 16 | public class CheckNull { 17 | 18 | public static void requireNonNull(Object value, String message) { 19 | Objects.requireNonNull(value, message); 20 | } 21 | 22 | /* 23 | * throws IAE instead of NPE 24 | */ 25 | public static void requireNonNullIAE(Object value, String message) { 26 | if (value == null) { 27 | throw new IllegalArgumentException(message); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/util/LogUtil.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.util; 9 | 10 | import java.util.logging.Level; 11 | import java.util.logging.Logger; 12 | 13 | /** 14 | * Utility methods to facilitate Logging. 15 | */ 16 | public class LogUtil { 17 | 18 | public static boolean isFineEnabled(Logger logger) { 19 | return logger != null && logger.isLoggable(Level.FINE); 20 | } 21 | 22 | public static void logSevere(Logger logger, String msg) { 23 | if (logger != null) { 24 | logger.log(Level.SEVERE, msg); 25 | } 26 | } 27 | 28 | public static void logSevere(Logger logger, String msg, Throwable thrown) { 29 | if (logger != null) { 30 | logger.log(Level.SEVERE, msg, thrown); 31 | } 32 | } 33 | 34 | public static void logWarning(Logger logger, String msg) { 35 | if (logger != null) { 36 | logger.log(Level.WARNING, msg); 37 | } 38 | } 39 | 40 | public static void logWarning(Logger logger, String msg, Throwable thrown) { 41 | if (logger != null) { 42 | logger.log(Level.WARNING, msg, thrown); 43 | } 44 | } 45 | 46 | public static void logInfo(Logger logger, String msg) { 47 | if (logger != null) { 48 | logger.log(Level.INFO, msg); 49 | } 50 | } 51 | 52 | public static void logFine(Logger logger, String msg) { 53 | if (logger != null) { 54 | logger.log(Level.FINE, msg); 55 | } 56 | } 57 | 58 | /** 59 | * Trace == FINE 60 | */ 61 | public static void logTrace(Logger logger, String msg) { 62 | if (logger != null) { 63 | logger.log(Level.FINE, msg); 64 | } 65 | } 66 | 67 | public static boolean isLoggable(Logger logger, Level level) { 68 | return (logger != null && logger.isLoggable(level)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/util/NettyByteInputStream.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.util; 9 | 10 | /** 11 | * An implementation of ByteInputStream that uses Netty's 12 | * ByteBufInputStream 13 | */ 14 | import io.netty.buffer.ByteBuf; 15 | import io.netty.buffer.ByteBufInputStream; 16 | import io.netty.buffer.Unpooled; 17 | 18 | /** 19 | * A ByteInputStream based on Netty's ByteBufInputStream 20 | */ 21 | public class NettyByteInputStream extends ByteBufInputStream 22 | implements ByteInputStream { 23 | 24 | final ByteBuf buffer; 25 | 26 | /** 27 | * Creates an instance using a (Netty) ByteBuf 28 | * @param buffer the buffer 29 | */ 30 | public NettyByteInputStream(ByteBuf buffer) { 31 | super(buffer); 32 | this.buffer = buffer; 33 | } 34 | 35 | /** 36 | * Creates an instance using an existing byte array 37 | * @param bytes the byte array 38 | * @return the stream 39 | */ 40 | public static NettyByteInputStream createFromBytes(byte[] bytes) { 41 | return new NettyByteInputStream(Unpooled.wrappedBuffer(bytes)); 42 | } 43 | 44 | @Override 45 | public int getOffset() { 46 | return buffer.readerIndex(); 47 | } 48 | 49 | @Override 50 | public boolean isDirect() { 51 | return buffer.isDirect(); 52 | } 53 | 54 | @Override 55 | public byte[] array() { 56 | return buffer.array(); 57 | } 58 | 59 | @Override 60 | public void setOffset(int offset) { 61 | try { 62 | buffer.readerIndex(offset); 63 | } catch (IndexOutOfBoundsException e) { 64 | throw new IllegalArgumentException(e); 65 | } 66 | } 67 | 68 | @Override 69 | public void skip(int toSkip) { 70 | setOffset(getOffset() + toSkip); 71 | } 72 | 73 | /** 74 | * Returns the underlying (Netty) ByteBuf 75 | * @return the buffer 76 | */ 77 | public ByteBuf buffer() { 78 | return buffer; 79 | } 80 | 81 | @Override 82 | public void close() { 83 | try { 84 | super.close(); 85 | } catch (Exception e) {} 86 | } 87 | 88 | @Override 89 | public void ensureCapacity(int nbytes) { 90 | if (nbytes > buffer.readableBytes()) { 91 | throw new IllegalArgumentException( 92 | "Operation exceeds capacity of the buffer; it requires: " + 93 | nbytes + ", available: " + buffer.readableBytes()); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/values/BooleanValue.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.values; 9 | 10 | /** 11 | * A {@link FieldValue} instance representing a boolean value. Boolean values 12 | * are singleton final instances and never constructed. 13 | */ 14 | public abstract class BooleanValue extends FieldValue { 15 | 16 | private static final BooleanValue TRUE = new TrueBooleanValue(); 17 | private static final BooleanValue FALSE = new FalseBooleanValue(); 18 | 19 | /** 20 | * Returns a singleton instance representing a true BooleanValue 21 | * 22 | * @return the value 23 | */ 24 | public static BooleanValue trueInstance() { 25 | return TRUE; 26 | } 27 | 28 | /** 29 | * Returns a singleton instance representing a false BooleanValue 30 | * 31 | * @return the value 32 | */ 33 | public static BooleanValue falseInstance() { 34 | return FALSE; 35 | } 36 | 37 | /** 38 | * Returns a singleton instance representing the boolean value provided. 39 | * 40 | * @param value the value 41 | * 42 | * @return the value 43 | */ 44 | public static BooleanValue getInstance(boolean value) { 45 | return (value ? TRUE : FALSE); 46 | } 47 | 48 | /** 49 | * Returns the boolean value of the field 50 | * 51 | * @return the value 52 | */ 53 | abstract public boolean getValue(); 54 | 55 | private BooleanValue() { 56 | super(); 57 | } 58 | 59 | @Override 60 | public String getString() { 61 | return toJson(); 62 | } 63 | 64 | @Override 65 | public Type getType() { 66 | return Type.BOOLEAN; 67 | } 68 | 69 | private static class TrueBooleanValue extends BooleanValue { 70 | @Override 71 | public boolean getValue() { 72 | return true; 73 | } 74 | 75 | @Override 76 | public String toJson(JsonOptions options) { 77 | return "true"; 78 | } 79 | } 80 | 81 | private static class FalseBooleanValue extends BooleanValue { 82 | @Override 83 | public boolean getValue() { 84 | return false; 85 | } 86 | 87 | @Override 88 | public String toJson(JsonOptions options) { 89 | return "false"; 90 | } 91 | } 92 | 93 | @Override 94 | public int compareTo(FieldValue other) { 95 | return ((Boolean)getValue()).compareTo(other.getBoolean()); 96 | } 97 | 98 | @Override 99 | public boolean equals(Object other) { 100 | if (other instanceof BooleanValue) { 101 | return getValue() == ((BooleanValue)other).getValue(); 102 | } 103 | return false; 104 | } 105 | 106 | @Override 107 | public int hashCode() { 108 | return ((Boolean) getValue()).hashCode(); 109 | } 110 | 111 | @Override 112 | public long sizeof() { 113 | return 0; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/values/DoubleValue.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.values; 9 | 10 | import static oracle.nosql.driver.util.CheckNull.requireNonNull; 11 | 12 | import java.math.BigDecimal; 13 | 14 | import oracle.nosql.driver.util.SizeOf; 15 | 16 | /** 17 | * A {@link FieldValue} instance representing a double value. 18 | */ 19 | public class DoubleValue extends FieldValue { 20 | 21 | private double value; 22 | 23 | /** 24 | * Creates a new instance. 25 | * 26 | * @param value the value to use 27 | */ 28 | public DoubleValue(double value) { 29 | super(); 30 | this.value = value; 31 | } 32 | 33 | /** 34 | * Creates a new instance from a String value 35 | * 36 | * @param value the value to use 37 | * 38 | * @throws NumberFormatException if the value is not a valid double 39 | */ 40 | public DoubleValue(String value) { 41 | super(); 42 | this.value = Double.parseDouble(value); 43 | } 44 | 45 | @Override 46 | public Type getType() { 47 | return Type.DOUBLE; 48 | } 49 | 50 | /** 51 | * Returns the double value of this object 52 | * 53 | * @return the double value 54 | */ 55 | public double getValue() { 56 | return value; 57 | } 58 | 59 | /** 60 | * internal use only 61 | * 62 | * @param v the value to use 63 | * @hidden 64 | */ 65 | public void setValue(double v) { 66 | value = v; 67 | } 68 | 69 | /** 70 | * Returns the double value of this object 71 | * 72 | * @return the double value 73 | */ 74 | @Override 75 | public double castAsDouble() { 76 | return value; 77 | } 78 | 79 | @Override 80 | public int compareTo(FieldValue other) { 81 | requireNonNull(other, "DoubleValue.compareTo: other must be non-null"); 82 | return Double.compare(value, other.getDouble()); 83 | } 84 | 85 | /** 86 | * Returns a BigDecimal value for this object 87 | * 88 | * @return the BigDecimal value 89 | */ 90 | @Override 91 | public BigDecimal getNumber() { 92 | return new BigDecimal(value); 93 | } 94 | 95 | @Override 96 | public String getString() { 97 | return toJson(null); 98 | } 99 | 100 | @Override 101 | public String toJson(JsonOptions options) { 102 | return String.valueOf(value); 103 | } 104 | 105 | @Override 106 | public boolean equals(Object other) { 107 | if (other instanceof DoubleValue) { 108 | /* Use Double.equals to handle values like NaN */ 109 | return ((Double)value).equals(((DoubleValue)other).value); 110 | } 111 | return false; 112 | } 113 | 114 | @Override 115 | public int hashCode() { 116 | return ((Double) value).hashCode(); 117 | } 118 | 119 | /** 120 | * @hidden 121 | */ 122 | @Override 123 | public long sizeof() { 124 | return SizeOf.OBJECT_OVERHEAD + 8; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/values/EmptyValue.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.values; 9 | 10 | /** 11 | * Only used by hidden scan interface 12 | * 13 | * A {@link FieldValue} instance representing an empty value. This type 14 | * is only relevant inside a table field of type JSON and only when that 15 | * field is indexed. It is used in index keys to represent 16 | * a missing value for the indexed field. This is different from a 17 | * {@link JsonNullValue} value, which is a concrete value. It is also different 18 | * from NullValue which represents a null/missing field in a fully-typed 19 | * field in the table schema as opposed to a JSON field 20 | * @hidden 21 | */ 22 | public class EmptyValue extends FieldValue { 23 | 24 | private static final EmptyValue INSTANCE = new EmptyValue(); 25 | 26 | private EmptyValue() { 27 | super(); 28 | } 29 | 30 | @Override 31 | public Type getType() { 32 | return Type.EMPTY; 33 | } 34 | 35 | /** 36 | * Returns an instance (singleton) of EmptyValue. 37 | * 38 | * @return the value 39 | */ 40 | public static EmptyValue getInstance() { 41 | return INSTANCE; 42 | } 43 | 44 | @Override 45 | public int compareTo(FieldValue other) { 46 | if (other instanceof EmptyValue) { 47 | return 0; 48 | } 49 | /* TODO: sort empty types? */ 50 | return -1; 51 | } 52 | 53 | @Override 54 | public String toJson(JsonOptions options) { 55 | return "\"EMPTY\""; 56 | } 57 | 58 | @Override 59 | public boolean equals(Object other) { 60 | return other == INSTANCE; 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return super.hashCode(); 66 | } 67 | 68 | /** 69 | * @hidden 70 | */ 71 | @Override 72 | public long sizeof() { 73 | return 0; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/values/IntegerValue.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.values; 9 | 10 | import java.math.BigDecimal; 11 | 12 | import oracle.nosql.driver.util.SizeOf; 13 | 14 | /** 15 | * A {@link FieldValue} instance representing an integer value. 16 | */ 17 | public class IntegerValue extends FieldValue { 18 | 19 | private final int value; 20 | 21 | /** 22 | * Creates a new instance. 23 | * 24 | * @param value the value to use 25 | */ 26 | public IntegerValue(int value) { 27 | super(); 28 | this.value = value; 29 | } 30 | 31 | /** 32 | * Creates a new instance from a String value 33 | * 34 | * @param value the value to use 35 | * 36 | * @throws NumberFormatException if the value is not a valid integer 37 | */ 38 | public IntegerValue(String value) { 39 | super(); 40 | this.value = Integer.parseInt(value); 41 | } 42 | 43 | @Override 44 | public Type getType() { 45 | return Type.INTEGER; 46 | } 47 | 48 | /** 49 | * Returns the integer value of this object 50 | * 51 | * @return the integer value 52 | */ 53 | public int getValue() { 54 | return value; 55 | } 56 | 57 | @Override 58 | public int compareTo(FieldValue other) { 59 | return Integer.compare(value, (other.getInt())); 60 | } 61 | 62 | /** 63 | * Returns a long value for this object. 64 | * 65 | * @return the long value 66 | */ 67 | @Override 68 | public long getLong() { 69 | return value; 70 | } 71 | 72 | /** 73 | * Casts this integer to a double, possibly with loss of information about 74 | * magnitude, precision or sign. 75 | * 76 | * @return a double value 77 | */ 78 | @Override 79 | public double castAsDouble() { 80 | return value; 81 | } 82 | 83 | /** 84 | * Returns a Double value for this object. 85 | * 86 | * @return the double value 87 | */ 88 | @Override 89 | public double getDouble() { 90 | return value; 91 | } 92 | 93 | /** 94 | * Returns a BigDecimal value for this object. 95 | * 96 | * @return the BigDecimal value 97 | */ 98 | @Override 99 | public BigDecimal getNumber() { 100 | return new BigDecimal(value); 101 | } 102 | 103 | @Override 104 | public String getString() { 105 | return toJson(null); 106 | } 107 | 108 | @Override 109 | public String toJson(JsonOptions options) { 110 | return String.valueOf(value); 111 | } 112 | 113 | @Override 114 | public boolean equals(Object other) { 115 | if (other instanceof IntegerValue) { 116 | return value == ((IntegerValue)other).value; 117 | } 118 | return false; 119 | } 120 | 121 | @Override 122 | public int hashCode() { 123 | return ((Integer) value).hashCode(); 124 | } 125 | 126 | /** 127 | * @hidden 128 | */ 129 | @Override 130 | public long sizeof() { 131 | return SizeOf.OBJECT_OVERHEAD + 4; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/values/JsonNullValue.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.values; 9 | 10 | /** 11 | * A {@link FieldValue} instance representing an explicit JSON null 12 | * value in a JSON object or array. 13 | * On input this type can only be used in a table field of type JSON. This 14 | * is an immutable singleton object. 15 | */ 16 | public class JsonNullValue extends FieldValue { 17 | 18 | private static final JsonNullValue INSTANCE = new JsonNullValue(); 19 | 20 | private JsonNullValue() { 21 | super(); 22 | } 23 | 24 | @Override 25 | public Type getType() { 26 | return Type.JSON_NULL; 27 | } 28 | 29 | /** 30 | * Returns an instance (singleton) of JsonNullValue. 31 | * 32 | * @return the value 33 | */ 34 | public static JsonNullValue getInstance() { 35 | return INSTANCE; 36 | } 37 | 38 | @Override 39 | public int compareTo(FieldValue other) { 40 | if (other instanceof JsonNullValue) { 41 | return 0; 42 | } 43 | /* TODO: sort empty types? */ 44 | return -1; 45 | } 46 | 47 | @Override 48 | public String getString() { 49 | return toJson(null); 50 | } 51 | 52 | @Override 53 | public String toJson(JsonOptions options) { 54 | return "null"; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object other) { 59 | return other == INSTANCE; 60 | } 61 | 62 | @Override 63 | public int hashCode() { 64 | return super.hashCode(); 65 | } 66 | 67 | /** 68 | * @hidden 69 | */ 70 | @Override 71 | public long sizeof() { 72 | return 0; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/values/NullValue.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.values; 9 | 10 | /** 11 | * A {@link FieldValue} instance representing a null or missing value 12 | * in a fully-typed schema. This type only exists in index keys on a fully-typed 13 | * field and never inside indexed JSON. 14 | */ 15 | public class NullValue extends FieldValue { 16 | 17 | private static final NullValue INSTANCE = new NullValue(); 18 | 19 | private NullValue() { 20 | super(); 21 | } 22 | 23 | @Override 24 | public Type getType() { 25 | return Type.NULL; 26 | } 27 | 28 | /** 29 | * Returns an instance (singleton) of NullValue. 30 | * 31 | * @return the value 32 | */ 33 | public static NullValue getInstance() { 34 | return INSTANCE; 35 | } 36 | 37 | @Override 38 | public int compareTo(FieldValue other) { 39 | if (other instanceof NullValue) { 40 | return 0; 41 | } 42 | /* TODO: sort empty types? */ 43 | return -1; 44 | } 45 | 46 | @Override 47 | public String getString() { 48 | return toJson(null); 49 | } 50 | 51 | @Override 52 | public String toJson(JsonOptions options) { 53 | return "null"; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object other) { 58 | return other == INSTANCE; 59 | } 60 | 61 | @Override 62 | public int hashCode() { 63 | return super.hashCode(); 64 | } 65 | 66 | /** 67 | * @hidden 68 | */ 69 | @Override 70 | public long sizeof() { 71 | return 0; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /driver/src/main/java/oracle/nosql/driver/values/StringValue.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.values; 9 | 10 | import static oracle.nosql.driver.util.CheckNull.requireNonNull; 11 | 12 | import java.math.BigDecimal; 13 | 14 | import com.fasterxml.jackson.core.io.CharTypes; 15 | 16 | import oracle.nosql.driver.util.SizeOf; 17 | 18 | /** 19 | * A {@link FieldValue} instance representing a string value. 20 | */ 21 | public class StringValue extends FieldValue { 22 | 23 | private final String value; 24 | 25 | /** 26 | * Creates a new instance 27 | * 28 | * @param value the value to use 29 | */ 30 | public StringValue(String value) { 31 | super(); 32 | requireNonNull(value, "StringValue: value must be non-null"); 33 | this.value = value; 34 | } 35 | 36 | @Override 37 | public Type getType() { 38 | return Type.STRING; 39 | } 40 | 41 | /** 42 | * Returns the String value 43 | * 44 | * @return the String value of this object 45 | */ 46 | public String getValue() { 47 | return value; 48 | } 49 | 50 | @Override 51 | public int getInt() { 52 | return Integer.parseInt(value); 53 | } 54 | 55 | @Override 56 | public double getDouble() { 57 | return Double.parseDouble(value); 58 | } 59 | 60 | @Override 61 | public long getLong() { 62 | return Long.parseLong(value); 63 | } 64 | 65 | @Override 66 | public BigDecimal getNumber() { 67 | return new BigDecimal(value); 68 | } 69 | 70 | @Override 71 | public boolean getBoolean() { 72 | return Boolean.parseBoolean(value); 73 | } 74 | 75 | @Override 76 | public boolean equals(Object other) { 77 | if (other instanceof StringValue) { 78 | return value.equals(((StringValue)other).value); 79 | } 80 | return false; 81 | } 82 | 83 | @Override 84 | public int hashCode() { 85 | return value.hashCode(); 86 | } 87 | 88 | @Override 89 | public int compareTo(FieldValue other) { 90 | if (other instanceof StringValue) { 91 | return value.compareTo(other.asString().getValue()); 92 | } 93 | throw new ClassCastException("Object is not an StringValue"); 94 | } 95 | 96 | @Override 97 | public String toJson(JsonOptions options) { 98 | StringBuilder sb = new StringBuilder(); 99 | sb.append("\""); 100 | CharTypes.appendQuoted(sb, value); 101 | sb.append("\""); 102 | return sb.toString(); 103 | } 104 | 105 | /** 106 | * @hidden 107 | */ 108 | @Override 109 | public long sizeof() { 110 | return (SizeOf.OBJECT_OVERHEAD + 111 | SizeOf.OBJECT_REF_OVERHEAD + 112 | SizeOf.stringSize(value)); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /driver/src/test/java/oracle/nosql/driver/InternalsTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver; 9 | 10 | import static org.junit.Assert.fail; 11 | 12 | import java.util.concurrent.CountDownLatch; 13 | import java.util.concurrent.atomic.AtomicInteger; 14 | 15 | import oracle.nosql.driver.ops.ListTablesRequest; 16 | 17 | import org.junit.Before; 18 | import org.junit.Test; 19 | 20 | public class InternalsTest extends ProxyTestBase { 21 | 22 | @Override 23 | protected void perTestHandleConfig(NoSQLHandleConfig config) { 24 | config.setNumThreads(8); 25 | } 26 | 27 | @Before 28 | @Override 29 | /* 30 | * Override the default beforeTest() so we do not make 31 | * any requests at all to the server before the actual test 32 | * is run. The default runs a ListTables request. 33 | */ 34 | public void beforeTest() throws Exception { 35 | super.beforeTest(); 36 | handle = getHandle(endpoint); 37 | /* do NOT list tables here */ 38 | } 39 | 40 | @Test 41 | public void serialSetupTest() { 42 | /* 43 | * Start N threads. Make them all run at the same time. 44 | * Each thread will issue requests. Verify that none of them 45 | * throw UnsupportedProtocolException. This verifies that the 46 | * logic inside Client properly manages setting the serial version 47 | * on the first request(s) that may happen in parallel. 48 | * 49 | * This test really only does anything if the server it's running 50 | * against is an older version. But it's ok to run with the current 51 | * server version anyway. 52 | */ 53 | CountDownLatch latch = new CountDownLatch(1); 54 | AtomicInteger errors = new AtomicInteger(0); 55 | final int numThreads = 5; 56 | Thread[] threads = new Thread[numThreads]; 57 | for (int x=0; x { 59 | try { latch.await(); } catch (Exception e) {} 60 | runRequests(errors); 61 | }); 62 | threads[x].start(); 63 | } 64 | 65 | latch.countDown(); 66 | 67 | /* wait for threads to finish */ 68 | for(int x=0; x 0) { 72 | fail("Got " + errors.get() + " errors"); 73 | } 74 | } 75 | 76 | private void runRequests(AtomicInteger errors) { 77 | ListTablesRequest req = new ListTablesRequest() 78 | .setLimit(1); 79 | try { 80 | for (int x=0; x<5; x++) { 81 | handle.listTables(req); 82 | } 83 | } catch (Exception e) { 84 | System.out.println("Got exception: " + e); 85 | errors.incrementAndGet(); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /driver/src/test/java/oracle/nosql/driver/iam/RegionTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Licensed under the Universal Permissive License v 1.0 as shown at 5 | * https://oss.oracle.com/licenses/upl/ 6 | */ 7 | 8 | package oracle.nosql.driver.iam; 9 | 10 | import static org.junit.Assert.assertNotNull; 11 | import static org.junit.Assert.assertNull; 12 | import static org.junit.Assert.assertTrue; 13 | import static org.junit.Assert.fail; 14 | 15 | import oracle.nosql.driver.DriverTestBase; 16 | import oracle.nosql.driver.Region; 17 | 18 | import org.junit.After; 19 | import org.junit.Before; 20 | import org.junit.BeforeClass; 21 | import org.junit.Test; 22 | 23 | public class RegionTest extends DriverTestBase { 24 | private static final String basePath = getResourcesDir(); 25 | private static final String regionConfigName = "regions-config.json"; 26 | private static final String envVarRegion = 27 | "{" + 28 | " \"regionKey\": \"abc\", " + 29 | " \"realmKey\": \"oc99\", " + 30 | " \"regionIdentifier\": \"us-nowhere-1\", " + 31 | " \"realmDomainComponent\": \"nocloud.com\" " + 32 | "}"; 33 | 34 | /* missing realm key */ 35 | private static final String badRegion = 36 | "{" + 37 | " \"regionKey\": \"abc\", " + 38 | " \"regionIdentifier\": \"us-nowhere-1\", " + 39 | " \"realmDomainComponent\": \"nocloud.com\" " + 40 | "}"; 41 | 42 | @BeforeClass 43 | public static void staticSetup() { 44 | System.setProperty("OCI_REGION_METADATA", envVarRegion); 45 | } 46 | 47 | @Before 48 | public void setUp() { 49 | clearTestDirectory(); 50 | } 51 | 52 | @After 53 | public void tearDown() { 54 | clearTestDirectory(); 55 | } 56 | 57 | @Test 58 | public void testParseProfile() 59 | throws Exception { 60 | assertNull(Region.fromRegionId("notARegion")); 61 | assertNull(Region.fromRegionId("af-newregion-1")); 62 | 63 | /* load a fake regions-config.json file */ 64 | Region.readRegionConfigFile(basePath + "/" + regionConfigName); 65 | /* it should exist now */ 66 | assertNotNull(Region.fromRegionId("af-newregion-1")); 67 | 68 | /* good, existing region */ 69 | assertNotNull(Region.fromRegionId("us-ashburn-1")); 70 | 71 | /* re-read env var, as previous tests may have set one-time-use flag */ 72 | Region.readEnvVar(); 73 | 74 | /* this was added by env var, see static init above */ 75 | assertNotNull(Region.fromRegionId("us-nowhere-1")); 76 | 77 | /* bad region in env */ 78 | System.setProperty("OCI_REGION_METADATA", badRegion); 79 | try { 80 | Region.readEnvVar(); 81 | fail("Should have failed"); 82 | } catch (IllegalArgumentException iae) { 83 | assertTrue(iae.getMessage().contains("issing field realmKey")); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /driver/src/test/resources/regions-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"regionKey": "jnb", "realmKey": "oc77", "regionIdentifier": "af-newregion-1", "realmDomainComponent": "oraclecloud77.com"}, 3 | {"regionKey": "yny", "realmKey": "oc77", "regionIdentifier": "af-newregion-2", "realmDomainComponent": "oraclecloud77.com"}, 4 | {"regionKey": "hyd", "realmKey": "oc77", "regionIdentifier": "af-newregion-3", "realmDomainComponent": "oraclecloud77.com"} 5 | ] 6 | -------------------------------------------------------------------------------- /driver/src/test/resources/utf16be.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/nosql-java-sdk/bdac8558329db13056c5c59d436b55fb5e79e9d4/driver/src/test/resources/utf16be.json -------------------------------------------------------------------------------- /driver/src/test/resources/utf16bebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/nosql-java-sdk/bdac8558329db13056c5c59d436b55fb5e79e9d4/driver/src/test/resources/utf16bebom.json -------------------------------------------------------------------------------- /driver/src/test/resources/utf16le.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/nosql-java-sdk/bdac8558329db13056c5c59d436b55fb5e79e9d4/driver/src/test/resources/utf16le.json -------------------------------------------------------------------------------- /driver/src/test/resources/utf16lebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/nosql-java-sdk/bdac8558329db13056c5c59d436b55fb5e79e9d4/driver/src/test/resources/utf16lebom.json -------------------------------------------------------------------------------- /driver/src/test/resources/utf8.json: -------------------------------------------------------------------------------- 1 | {"id": 2, "name":"newnâme"} 2 | -------------------------------------------------------------------------------- /driver/src/test/resources/utf8_testdata.txt: -------------------------------------------------------------------------------- 1 | zh{ 2 | 中文姓名 3 | 中文姓名2 4 | } 5 | 6 | fr{ 7 | 1: newnâme 8 | 2:{"id":1,"name":"çé_myname"} 9 | 3:{"id":2,"name":"çé_newname"} 10 | 4:Perry's Union Street_çé 11 | } 12 | 13 | jp{ 14 | ネームの名 15 | ネームの名2 16 | } 17 | -------------------------------------------------------------------------------- /driver/src/test/resources/utf8bom.json: -------------------------------------------------------------------------------- 1 | {"id": 2, "name":"newnâme"} 2 | -------------------------------------------------------------------------------- /examples/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | nosql-java-sdk-examples 4 | Java examples for Oracle NoSQL Database. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. 5 | 6 | nosqldriver 7 | 8 | 9 | 10 | org.eclipse.jdt.core.javabuilder 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Builder 16 | 17 | 18 | 19 | 20 | 21 | org.eclipse.m2e.core.maven2Nature 22 | org.eclipse.jdt.core.javanature 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /examples/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 7 | org.eclipse.jdt.core.compiler.release=disabled 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /examples/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.oracle.nosql.sdk 6 | 5.4.18-SNAPSHOT 7 | nosql-java-sdk-examples 8 | Oracle NoSQL Database Java Examples 9 | Java examples for Oracle NoSQL Database 10 | TBD 11 | jar 12 | 13 | 14 | UTF-8 15 | 1.8 16 | 1.8 17 | 18 | true 19 | true 20 | true 21 | true 22 | 23 | 24 | 25 | 26 | com.oracle.nosql.sdk 27 | nosqldriver 28 | 5.4.18-SNAPSHOT 29 | 30 | 31 | 32 | 33 | ${project.artifactId} 34 | 35 | 36 | maven-compiler-plugin 37 | 3.11.0 38 | 39 | true 40 | 1.8 41 | 1.8 42 | true 43 | true 44 | 45 | 46 | ${javac} 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.oracle.nosql.sdk 8 | nosql-java-sdk 9 | 5.4.18-SNAPSHOT 10 | pom 11 | Oracle NoSQL SDK 12 | 13 | This project contains the SDK for Oracle NoSQL Database 14 | 15 | https://github.com/oracle/nosql-java-sdk 16 | 17 | 18 | The Universal Permissive License (UPL), Version 1.0 19 | http://www.oracle.com/technetwork/licenses/upl-license-2927578.html 20 | repo 21 | 22 | 23 | 24 | 25 | oracle 26 | Oracle 27 | https://www.oracle.com 28 | 29 | 30 | 31 | scm:git:git@github.com:oracle/nosql-java-sdk.git 32 | https://github.com/oracle/nosql-java-sdk 33 | 34 | 35 | 36 | true 37 | true 38 | 39 | 40 | 41 | driver 42 | examples 43 | 44 | 45 | 46 | clean compile 47 | 48 | 49 | -------------------------------------------------------------------------------- /sbom_generation.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, 2025 Oracle and/or its affiliates. All rights reserved. 2 | 3 | version: 0.1 4 | component: build 5 | timeoutInSeconds: 1000 6 | shell: bash 7 | 8 | steps: 9 | - type: Command 10 | name: "Run Maven cycloneDX plugin command" 11 | command: | 12 | # For more details, visit https://github.com/CycloneDX/cyclonedx-maven-plugin/blob/master/README.md 13 | mvn org.cyclonedx:cyclonedx-maven-plugin:2.7.5:makeAggregateBom -DincludeRuntimeScope=true -DincludeCompileScope=true -DincludeProvidedScope=false -DincludeSystemScope=false -DincludeTestScope=false -DoutputFormat=json -DoutputName=artifactSBOM -DschemaVersion=1.4 14 | mv target/artifactSBOM.json ./artifactSBOM.json 15 | outputArtifacts: 16 | - name: artifactSBOM 17 | type: BINARY 18 | location: ${OCI_PRIMARY_SOURCE_DIR}/artifactSBOM.json 19 | --------------------------------------------------------------------------------