ScalarDB Java API Guide
The ScalarDB Java API is mainly composed of the Administrative API and Transactional API. This guide briefly explains what kinds of APIs exist, how to use them, and related topics like how to handle exceptions.
Administrative API​
This section explains how to execute administrative operations programmatically by using the Administrative API in ScalarDB.
When an Administrative API call writes to the underlying databases, it triggers several write operations. However, these operations are not executed atomically, meaning that if the call fails midway, you may encounter inconsistent states. To resolve this inconsistency issue, you can repair the table. For details, see the following pages:
- Repair a table by using the Java API
- Repair tables by using ScalarDB Schema Loader
Another method for executing administrative operations is to use Schema Loader.
Get a DistributedTransactionAdmin instance​
You first need to get a DistributedTransactionAdmin instance to execute administrative operations.
To get a DistributedTransactionAdmin instance, you can use TransactionFactory as follows:
TransactionFactory transactionFactory = TransactionFactory.create("<CONFIGURATION_FILE_PATH>");
DistributedTransactionAdmin admin = transactionFactory.getTransactionAdmin();
For details about configurations, see ScalarDB Configurations.
After you have executed all administrative operations, you should close the DistributedTransactionAdmin instance as follows:
admin.close();
Create a namespace​
Before creating tables, namespaces must be created since a table belongs to one namespace.
You can create a namespace as follows:
// Create the namespace "ns". If the namespace already exists, an exception will be thrown.
admin.createNamespace("ns");
// Create the namespace only if it does not already exist.
boolean ifNotExists = true;
admin.createNamespace("ns", ifNotExists);
// Create the namespace with options.
Map<String, String> options = ...;
admin.createNamespace("ns", options);
Creation options​
In the namespace creation operations, you can specify options that are maps of option names and values (Map<String, String>). By using the options, you can set storage adapter–specific configurations.
Select your database to see the options available:
- JDBC databases
- DynamoDB
- Cosmos DB for NoSQL
- Cassandra
No options are available.
No options are available.
| Name | Description | Default |
|---|---|---|
| ru | Base resource unit. | 400 |
| no-scaling | Disable auto-scaling for Cosmos DB for NoSQL. | false |
| Name | Description | Default |
|---|---|---|
| replication-strategy | Cassandra replication strategy. Must be SimpleStrategy or NetworkTopologyStrategy. | SimpleStrategy |
| replication-factor | Cassandra replication factor. | 1 |