use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class JdbcTransaction method put.
@Override
public void put(Put put) throws CrudException {
put = copyAndSetTargetToIfNot(put);
// Ignore the condition in the put
if (put.getCondition().isPresent()) {
LOGGER.warn("ignoring the condition of the mutation: {}", put);
put.withCondition(null);
}
try {
jdbcService.put(put, connection);
} catch (SQLException e) {
throw createCrudException(e, "put operation failed");
} catch (ExecutionException e) {
throw new CrudException("put operation failed", e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class CassandraAdmin method createTableInternal.
@VisibleForTesting
void createTableInternal(String keyspace, String table, TableMetadata metadata, Map<String, String> options) throws ExecutionException {
Create createTable = SchemaBuilder.createTable(quoteIfNecessary(keyspace), quoteIfNecessary(table));
// Add columns
for (String pk : metadata.getPartitionKeyNames()) {
createTable = createTable.addPartitionKey(quoteIfNecessary(pk), toCassandraDataType(metadata.getColumnDataType(pk)));
}
for (String ck : metadata.getClusteringKeyNames()) {
createTable = createTable.addClusteringColumn(quoteIfNecessary(ck), toCassandraDataType(metadata.getColumnDataType(ck)));
}
for (String column : metadata.getColumnNames()) {
if (metadata.getPartitionKeyNames().contains(column) || metadata.getClusteringKeyNames().contains(column)) {
continue;
}
createTable = createTable.addColumn(quoteIfNecessary(column), toCassandraDataType(metadata.getColumnDataType(column)));
}
// Add clustering order
Create.Options createTableWithOptions = createTable.withOptions();
for (String ck : metadata.getClusteringKeyNames()) {
Direction direction = metadata.getClusteringOrder(ck) == Order.ASC ? Direction.ASC : Direction.DESC;
createTableWithOptions = createTableWithOptions.clusteringOrder(quoteIfNecessary(ck), direction);
}
// Add compaction strategy
CompactionStrategy compactionStrategy = CompactionStrategy.valueOf(options.getOrDefault(COMPACTION_STRATEGY, CompactionStrategy.STCS.toString()));
CompactionOptions<?> strategy;
switch(compactionStrategy) {
case LCS:
strategy = SchemaBuilder.leveledStrategy();
break;
case TWCS:
strategy = SchemaBuilder.timeWindowCompactionStrategy();
break;
default:
strategy = SchemaBuilder.sizedTieredStategy();
}
createTableWithOptions = createTableWithOptions.compactionOptions(strategy);
try {
clusterManager.getSession().execute(createTableWithOptions.getQueryString());
} catch (RuntimeException e) {
throw new ExecutionException(String.format("creating the table %s.%s failed", keyspace, table), e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class CosmosAdmin method truncateTable.
@Override
public void truncateTable(String namespace, String table) throws ExecutionException {
try {
CosmosDatabase database = client.getDatabase(namespace);
CosmosContainer container = database.getContainer(table);
CosmosPagedIterable<Record> records = container.queryItems("SELECT t." + ID + ", t." + CONCATENATED_PARTITION_KEY + " FROM " + "t", new CosmosQueryRequestOptions(), Record.class);
records.forEach(record -> container.deleteItem(record.getId(), new PartitionKey(record.getConcatenatedPartitionKey()), new CosmosItemRequestOptions()));
} catch (RuntimeException e) {
throw new ExecutionException("truncating the container failed", e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class CosmosAdmin method dropTable.
@Override
public void dropTable(String namespace, String table) throws ExecutionException {
if (!databaseExists(namespace)) {
throw new ExecutionException("the database does not exist");
}
CosmosDatabase database = client.getDatabase(namespace);
if (!containerExists(database, table)) {
throw new ExecutionException("the container does not exist");
}
try {
database.getContainer(table).delete();
deleteTableMetadata(namespace, table);
} catch (RuntimeException e) {
throw new ExecutionException("deleting the container failed", e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class CosmosAdmin method putTableMetadata.
private void putTableMetadata(String namespace, String table, TableMetadata metadata) throws ExecutionException {
try {
createMetadataDatabaseAndContainerIfNotExists();
CosmosTableMetadata cosmosTableMetadata = convertToCosmosTableMetadata(getFullTableName(namespace, table), metadata);
getMetadataContainer().upsertItem(cosmosTableMetadata);
} catch (RuntimeException e) {
throw new ExecutionException("putting the table metadata failed", e);
}
}
Aggregations