use of com.scalar.db.storage.jdbc.query.DeleteQuery in project scalardb by scalar-labs.
the class JdbcService method delete.
public boolean delete(Delete delete, Connection connection) throws SQLException, ExecutionException {
operationChecker.check(delete);
TableMetadata tableMetadata = tableMetadataManager.getTableMetadata(delete);
if (!delete.getCondition().isPresent()) {
DeleteQuery deleteQuery = queryBuilder.deleteFrom(delete.forNamespace().get(), delete.forTable().get(), tableMetadata).where(delete.getPartitionKey(), delete.getClusteringKey()).build();
try (PreparedStatement preparedStatement = connection.prepareStatement(deleteQuery.sql())) {
deleteQuery.bind(preparedStatement);
preparedStatement.executeUpdate();
return true;
}
} else {
return new ConditionalMutator(delete, tableMetadata, connection, queryBuilder).mutate();
}
}
use of com.scalar.db.storage.jdbc.query.DeleteQuery in project scalardb by scalar-labs.
the class ConditionalMutator method visit.
@Override
public void visit(DeleteIf condition) {
Delete delete = (Delete) mutation;
DeleteQuery deleteQuery = queryBuilder.deleteFrom(delete.forNamespace().get(), delete.forTable().get(), tableMetadata).where(delete.getPartitionKey(), delete.getClusteringKey(), condition.getExpressions()).build();
executeMutate(deleteQuery);
}
use of com.scalar.db.storage.jdbc.query.DeleteQuery in project scalardb by scalar-labs.
the class ConditionalMutator method visit.
@Override
public void visit(DeleteIfExists condition) {
Delete delete = (Delete) mutation;
DeleteQuery deleteQuery = queryBuilder.deleteFrom(delete.forNamespace().get(), delete.forTable().get(), tableMetadata).where(delete.getPartitionKey(), delete.getClusteringKey()).build();
executeMutate(deleteQuery);
}
Aggregations