ScalarDB SQL API Guide
This guide describes how to use ScalarDB SQL API.
Add ScalarDB SQL API to your project
To add the dependencies on ScalarDB SQL API by using Gradle, use the following, replacing <VERSION>
with the versions of ScalarDB SQL API and the related library, respectively, that you are using:
dependencies {
implementation 'com.scalar-labs:scalardb-sql:<VERSION>'
implementation 'com.scalar-labs:scalardb-cluster-java-client-sdk:<VERSION>'
}
To add the dependencies by using Maven, use the following, replacing ...
with the version of ScalarDB SQL API that you are using:
<dependencies>
<dependency>
<groupId>com.scalar-labs</groupId>
<artifactId>scalardb-sql</artifactId>
<version>...</version>
</dependency>
<dependency>
<groupId>com.scalar-labs</groupId>
<artifactId>scalardb-cluster-java-client-sdk</artifactId>
<version>...</version>
</dependency>
</dependencies>
SqlSessionFactory
In ScalarDB SQL API, you execute all operations through a SqlSession
instance, which is instantiated with SqlSessionFactory
.
This section explains how to use them.
Before explaining SqlSessionFactory
, we start with the explanation for Connection mode and Transaction mode.
Transaction mode
Also, ScalarDB SQL offers two transaction modes: Transaction mode and Two-phase Commit Transaction mode.
Transaction mode exposes only commit
interface to users and runs two-phase commit behind the scene, while Two-phase Commit Transaction mode exposes two-phase commit style interfaces (prepare
and commit
) to users.
You can specify the default transaction mode in your configuration file or when you build SqlSessionFactory
.
And you also can change it with the setTransactionMode()
method of SqlSession
.
Build SqlSessionFactory
You can build SqlSessionFactory
with a properties file as follows:
SqlSessionFactory sqlSessionFactory = SqlSessionFactory.builder()
.withPropertiesFile("<your configuration file>")
// If you need to set custom properties, you can specify them with withProperty() or withProperties()
.withProperty("<custom property name>", "<custom property value>")
.build();