Search in sources :

Example 96 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class ConsensusCommitIntegrationTestBase method createTables.

private void createTables() throws ExecutionException {
    Map<String, String> options = getCreateOptions();
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, DataType.INT).addPartitionKey(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    admin.createNamespace(namespace1, true, options);
    consensusCommitAdmin.createTransactionalTable(namespace1, TABLE_1, tableMetadata, true, options);
    admin.createNamespace(namespace2, true, options);
    consensusCommitAdmin.createTransactionalTable(namespace2, TABLE_2, tableMetadata, true, options);
    consensusCommitAdmin.createCoordinatorTable(options);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata)

Example 97 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class TwoPhaseConsensusCommitIntegrationTest method createTables.

private static void createTables() throws ExecutionException {
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, DataType.INT).addPartitionKey(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    admin.createNamespace(NAMESPACE, true);
    consensusCommitAdmin.createTransactionalTable(NAMESPACE, TABLE_1, tableMetadata, true);
    consensusCommitAdmin.createTransactionalTable(NAMESPACE, TABLE_2, tableMetadata, true);
    consensusCommitAdmin.createCoordinatorTable();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata)

Example 98 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class DeleteStatementHandler method handle.

@Nonnull
@Override
public List<Map<String, AttributeValue>> handle(Operation operation) throws ExecutionException {
    checkArgument(operation, Delete.class);
    Delete delete = (Delete) operation;
    TableMetadata tableMetadata = metadataManager.getTableMetadata(operation);
    try {
        delete(delete, tableMetadata);
    } catch (ConditionalCheckFailedException e) {
        throw new NoMutationException("no mutation was applied.", e);
    } catch (TransactionConflictException e) {
        throw new RetriableExecutionException(e.getMessage(), e);
    } catch (DynamoDbException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
    return Collections.emptyList();
}
Also used : Delete(com.scalar.db.api.Delete) TableMetadata(com.scalar.db.api.TableMetadata) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) TransactionConflictException(software.amazon.awssdk.services.dynamodb.model.TransactionConflictException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) ExecutionException(com.scalar.db.exception.storage.ExecutionException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) ConditionalCheckFailedException(software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException) NoMutationException(com.scalar.db.exception.storage.NoMutationException) Nonnull(javax.annotation.Nonnull)

Example 99 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class Dynamo method scan.

@Override
public Scanner scan(Scan scan) throws ExecutionException {
    scan = copyAndSetTargetToIfNot(scan);
    operationChecker.check(scan);
    TableMetadata metadata = metadataManager.getTableMetadata(scan);
    ScalarDbUtils.addProjectionsForKeys(scan, metadata);
    List<Map<String, AttributeValue>> items = selectStatementHandler.handle(scan);
    return new ScannerImpl(items, new ResultInterpreter(scan.getProjections(), metadata));
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Map(java.util.Map)

Example 100 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class SelectStatementHandler method handle.

@Nonnull
@Override
public List<Map<String, AttributeValue>> handle(Operation operation) throws ExecutionException {
    checkArgument(operation, Get.class, Scan.class);
    TableMetadata tableMetadata = metadataManager.getTableMetadata(operation);
    try {
        if (ScalarDbUtils.isSecondaryIndexSpecified(operation, tableMetadata)) {
            return executeQueryWithIndex((Selection) operation, tableMetadata);
        }
        if (operation instanceof Get) {
            return executeGet((Get) operation, tableMetadata);
        } else {
            return executeQuery((Scan) operation, tableMetadata);
        }
    } catch (DynamoDbException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) Get(com.scalar.db.api.Get) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Nonnull(javax.annotation.Nonnull)

Aggregations

TableMetadata (com.scalar.db.api.TableMetadata)101 Test (org.junit.jupiter.api.Test)39 Get (com.scalar.db.api.Get)11 PreparedStatement (java.sql.PreparedStatement)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Key (com.scalar.db.io.Key)6 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)6 Mutation (com.scalar.db.api.Mutation)5 Result (com.scalar.db.api.Result)5 GetTableMetadataResponse (com.scalar.db.rpc.GetTableMetadataResponse)5 ResultSet (java.sql.ResultSet)5 Nonnull (javax.annotation.Nonnull)5 HashMap (java.util.HashMap)4 Options (com.datastax.driver.core.schemabuilder.Create.Options)3 KeyspaceOptions (com.datastax.driver.core.schemabuilder.KeyspaceOptions)3 TableOptions (com.datastax.driver.core.schemabuilder.TableOptions)3 ScanAll (com.scalar.db.api.ScanAll)3 NoMutationException (com.scalar.db.exception.storage.NoMutationException)3