About OCI SDK APIs

Oracle Cloud Infrastructure provides a number of Software Development Kits (SDKs) to facilitate the development of custom solutions.

Software Development Kits (SDKs) are used to build and deploy apps that integrate with Oracle Cloud Infrastructure services. Different OCI SDKs are there supporting Java, Python, Go, .NET, Typescript, Javascript, and Ruby. Each SDK provides the tools you need to develop an app, including code samples and documentation to create, test, and troubleshoot. The Oracle Cloud Infrastructure SDK enables you to write code to manage Oracle Cloud Infrastructure resources.

Using OCI SDK APIs

To use the OCI SDKs, you must have the following:

OCI SDK for Java: You can download the OCI SDK for Java here. In addition to the above requirements, you need to have Java Version 8 or more installed. For more details, see SDK for Java.

Note: OCI SDK is also available for Python, Go, Typescript, Javascript, .NET and Ruby. See OCI SDK Guides.

Creating Singleton table using OCI Java SDK

You can use CreateTableRequest class inside a createTable method to create a new NoSQL table.

The following code snippet shows how to use OCI Java SDK to create a singleton table.

private static final String DEF_OCI_CONFIG = "~/.oci/config";
private static final String DEF_PROFILE = "DEFAULT";
String tableName = "<table_name>";
String region = "<region_name>";

/* Initialize NoSQLHandle */
   NosqlClient client = connect(endpoint, DEF_OCI_CONFIG, DEF_PROFILE);

/* Create table */
   String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + "(" +
                     "id INTEGER, info JSON, PRIMARY KEY(id)) " ;
   TableLimits limits = TableLimits.builder()
                .maxReadUnits(50)
                .maxWriteUnits(50)
                .maxStorageInGBs(1)
                .build();
   CreateTableDetails.Builder payload = CreateTableDetails.builder()
                .compartmentId(compartmentId)
                .name(tableName)
                .ddlStatement(ddl)
                .tableLimits(limits);
   CreateTableRequest tableReq = CreateTableRequest.builder()
                .createTableDetails(payload.build())
                .build();
   CreateTableResponse tableRes = client.createTable(tableReq);
        output("\nCreating table: " + ddl);
        waitForComplete(client, tableRes.getOpcWorkRequestId());
        output("Table created: " + tableName);

Creating Global Active table using OCI Java SDK

You can use OCI Java SDK to create a Global Active table in NDCS.

To create a Global Active table:

The following code snippet shows how to create a Global Active table using OCI Java SDK.

private static final String DEF_OCI_CONFIG = "~/.oci/config";
private static final String DEF_PROFILE = "DEFAULT";
String tableName = "<table_name>";
String region = "<region_name>";

/* Initialize NoSQLHandle */
   NosqlClient client = connect(endpoint, DEF_OCI_CONFIG, DEF_PROFILE);

/* Create table */
   String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + "(" +
                     "id INTEGER, info JSON, PRIMARY KEY(id)) " +
                     "with schema frozen";
   TableLimits limits = TableLimits.builder()
                .maxReadUnits(50)
                .maxWriteUnits(50)
                .maxStorageInGBs(1)
                .build();
   CreateTableDetails.Builder payload = CreateTableDetails.builder()
                .compartmentId(compartmentId)
                .name(tableName)
                .ddlStatement(ddl)
                .tableLimits(limits);
   CreateTableRequest tableReq = CreateTableRequest.builder()
                .createTableDetails(payload.build())
                .build();
   CreateTableResponse tableRes = client.createTable(tableReq);
        output("\nCreating table: " + ddl);
        waitForComplete(client, tableRes.getOpcWorkRequestId());
        output("Table created: " + tableName);

/* Add replica ca-montreal-1 */
   CreateReplicaDetails info = CreateReplicaDetails
                .builder()
                .region(region)
                .compartmentId(compartmentId)
                .build();
   CreateReplicaRequest replicaReq = CreateReplicaRequest
                .builder()
                .tableNameOrId(tableName)
                .createReplicaDetails(info)
                .build();
   CreateReplicaResponse replicaRes = client.createReplica(replicaReq);
        output("\nAdding replica: " + region);
        waitForComplete(client, replicaRes.getOpcWorkRequestId());
        output("Added replica: " + region);