use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class JdbcService method put.
public boolean put(Put put, Connection connection) throws SQLException, ExecutionException {
operationChecker.check(put);
TableMetadata tableMetadata = tableMetadataManager.getTableMetadata(put);
if (!put.getCondition().isPresent()) {
UpsertQuery upsertQuery = queryBuilder.upsertInto(put.forNamespace().get(), put.forTable().get(), tableMetadata).values(put.getPartitionKey(), put.getClusteringKey(), put.getColumns()).build();
try (PreparedStatement preparedStatement = connection.prepareStatement(upsertQuery.sql())) {
upsertQuery.bind(preparedStatement);
preparedStatement.executeUpdate();
return true;
}
} else {
return new ConditionalMutator(put, tableMetadata, connection, queryBuilder).mutate();
}
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class DeleteStatementHandler method execute.
@Override
protected List<Record> execute(Operation operation) throws CosmosException, ExecutionException {
Mutation mutation = (Mutation) operation;
TableMetadata tableMetadata = metadataManager.getTableMetadata(mutation);
if (mutation.getCondition().isPresent()) {
executeStoredProcedure(mutation, tableMetadata);
} else {
execute(mutation, tableMetadata);
}
return Collections.emptyList();
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class TableMetadataManagerTest method getTableMetadata_CalledAfterCacheExpiration_ShouldCallDistributedStorageAdminAgain.
@Test
public void getTableMetadata_CalledAfterCacheExpiration_ShouldCallDistributedStorageAdminAgain() throws ExecutionException {
// Arrange
// one second
TableMetadataManager tableMetadataManager = new TableMetadataManager(admin, 1L);
TableMetadata expectedTableMetadata = TableMetadata.newBuilder().addColumn("c1", DataType.INT).addColumn("c2", DataType.INT).addPartitionKey("c1").build();
when(admin.getTableMetadata(anyString(), anyString())).thenReturn(expectedTableMetadata);
Get get = new Get(new Key("c1", "aaa")).forNamespace("ns").forTable("tbl");
// Act
tableMetadataManager.getTableMetadata(get);
// Wait for cache to be expired
Uninterruptibles.sleepUninterruptibly(1200, TimeUnit.MILLISECONDS);
TableMetadata actualTableMetadata = tableMetadataManager.getTableMetadata(get);
// Assert
verify(admin, times(2)).getTableMetadata(anyString(), anyString());
assertThat(actualTableMetadata).isEqualTo(expectedTableMetadata);
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class TableMetadataManagerTest method getTableMetadata_CalledTwice_ShouldCallDistributedStorageAdminOnlyOnce.
@Test
public void getTableMetadata_CalledTwice_ShouldCallDistributedStorageAdminOnlyOnce() throws ExecutionException {
// Arrange
TableMetadataManager tableMetadataManager = new TableMetadataManager(admin, -1);
TableMetadata expectedTableMetadata = TableMetadata.newBuilder().addColumn("c1", DataType.INT).addColumn("c2", DataType.INT).addPartitionKey("c1").build();
when(admin.getTableMetadata(anyString(), anyString())).thenReturn(expectedTableMetadata);
Get get = new Get(new Key("c1", "aaa")).forNamespace("ns").forTable("tbl");
// Act
tableMetadataManager.getTableMetadata(get);
TableMetadata actualTableMetadata = tableMetadataManager.getTableMetadata(get);
// Assert
verify(admin).getTableMetadata(anyString(), anyString());
assertThat(actualTableMetadata).isEqualTo(expectedTableMetadata);
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class GrpcTransactionOnBidirectionalStream method scan.
public List<Result> scan(Scan scan) throws CrudException {
throwIfTransactionFinished();
ResponseOrError responseOrError = sendRequest(TransactionRequest.newBuilder().setScanRequest(ScanRequest.newBuilder().setScan(ProtoUtils.toScan(scan))).build());
throwIfErrorForCrud(responseOrError);
TableMetadata tableMetadata = getTableMetadata(scan);
return responseOrError.getResponse().getScanResponse().getResultList().stream().map(r -> ProtoUtils.toResult(r, tableMetadata)).collect(Collectors.toList());
}
Aggregations