Skip to content

Instantly share code, notes, and snippets.

View brfrn169's full-sized avatar

Toshihiro Suzuki brfrn169

View GitHub Profile
@brfrn169
brfrn169 / builders_example.java
Created July 20, 2022 03:28
Examples of operation builders in Scalar DB
// Create a Get operation
Get get =
Get.newBuilder()
.namespace("ns")
.table("tbl")
.partitionKey(Key.ofInt("c1", 10))
.clusteringKey(Key.of("c2", "aaa", "c3", 100L))
.projections("c1", "c2", "c3", "c4")
.build();
@brfrn169
brfrn169 / schema.json
Created May 23, 2022 01:33
schema.json for Multi-storage Transactions
{
"customer.customers": {
"transaction": true,
"partition-key": [
"customer_id"
],
"columns": {
"customer_id": "INT",
"name": "TEXT",
"credit_limit": "INT",
@brfrn169
brfrn169 / database.properties
Created May 23, 2022 01:29
database.properties for Multi-storage Transactions
scalar.db.storage=multi-storage
scalar.db.multi_storage.storages=cassandra,mysql
scalar.db.multi_storage.storages.cassandra.storage=cassandra
scalar.db.multi_storage.storages.cassandra.contact_points=localhost
scalar.db.multi_storage.storages.cassandra.username=cassandra
scalar.db.multi_storage.storages.cassandra.password=cassandra
scalar.db.multi_storage.storages.mysql.storage=jdbc
scalar.db.multi_storage.storages.mysql.contact_points=jdbc:mysql://localhost:3306/
scalar.db.multi_storage.storages.mysql.username=root
scalar.db.multi_storage.storages.mysql.password=mysql
@brfrn169
brfrn169 / Repayment.java
Last active July 20, 2022 05:44
How to Get Started with Scalar DB (Japanses)
public void repayment(int customerId, int amount) throws TransactionException {
DistributedTransaction transaction = null;
try {
// トランザクションを開始
transaction = manager.start();
// 顧客情報をcustomersテーブルから取得
Optional<Result> customer =
transaction.get(
Get.newBuilder()
@brfrn169
brfrn169 / PlacingOrder.java
Last active July 20, 2022 05:42
How to Get Started with Scalar DB (Japanese)
public String placeOrder(int customerId, int[] itemIds, int[] itemCounts)
throws TransactionException {
assert itemIds.length == itemCounts.length;
DistributedTransaction transaction = null;
try {
String orderId = UUID.randomUUID().toString();
// トランザクションを開始
transaction = manager.start();
@brfrn169
brfrn169 / GettingCustomerInformation.java
Last active July 20, 2022 05:39
How to Get Started with Scalar DB (Japanese)
public String getCustomerInfo(int customerId) throws TransactionException {
DistributedTransaction transaction = null;
try {
// トランザクションを開始
transaction = manager.start();
// customers テーブルから指定された顧客IDの顧客情報を取得
Optional<Result> customer =
transaction.get(
Get.newBuilder()
@brfrn169
brfrn169 / Repayment.java
Last active July 24, 2022 14:59
How to Get Started with Scalar DB (English)
public void repayment(int customerId, int amount) throws TransactionException {
DistributedTransaction transaction = null;
try {
// Start a transaction
transaction = manager.start();
// Retrieve the customer info for the specified customer ID from the customers table
Optional<Result> customer =
transaction.get(
Get.newBuilder()
@brfrn169
brfrn169 / PlacingOrder.java
Last active July 20, 2022 05:34
How to Get Started with Scalar DB (English)
public String placeOrder(int customerId, int[] itemIds, int[] itemCounts)
throws TransactionException {
assert itemIds.length == itemCounts.length;
DistributedTransaction transaction = null;
try {
String orderId = UUID.randomUUID().toString();
// Start a transaction
transaction = manager.start();
@brfrn169
brfrn169 / GettingCustomerInformation.java
Last active July 20, 2022 05:31
How to Get Started with Scalar DB (English)
public String getCustomerInfo(int customerId) throws TransactionException {
DistributedTransaction transaction = null;
try {
// Start a transaction
transaction = manager.start();
// Retrieve the customer info for the specified customer ID from the customers table
Optional<Result> customer =
transaction.get(
Get.newBuilder()
@brfrn169
brfrn169 / CreateDistributedTransactionManager.java
Last active July 20, 2022 05:29
How to Get Started with Scalar DB
TransactionFactory factory = TransactionFactory.create("database.properties");
DistributedTransactionManager manager = factory.getTransactionManager();