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
- An Oracle Cloud Infrastructure account.
- A user who is created in that account in a group with a policy that grants the desired permissions. This can be a user for yourself, or another person/system that needs to call the API.
Note:
OCI SDK is also available for Python, Go, Typescript, Javascript, .NET and Ruby. See OCI SDK Guides for more details.Creating Singleton table using OCI Java SDK
You can use CreateTableRequest
class inside a
createTable
method to create a new NoSQL 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.
- Create a NoSQL table with at least one JSON column in it.
- Freeze the schema of the table. You can freeze the table while creating it by adding with schema frozen in the DDL CREATE TABLE statement.
- A NoSQL Database table becomes a Global Active table only after adding a regional replica table. The regional replica table is created in another region.
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);