Search in sources :

Example 1 with DeleteQuery

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();
    }
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) DeleteQuery(com.scalar.db.storage.jdbc.query.DeleteQuery) PreparedStatement(java.sql.PreparedStatement)

Example 2 with 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(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);
}
Also used : Delete(com.scalar.db.api.Delete) DeleteQuery(com.scalar.db.storage.jdbc.query.DeleteQuery)

Example 3 with 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);
}
Also used : Delete(com.scalar.db.api.Delete) DeleteQuery(com.scalar.db.storage.jdbc.query.DeleteQuery)

Aggregations

DeleteQuery (com.scalar.db.storage.jdbc.query.DeleteQuery)3 Delete (com.scalar.db.api.Delete)2 TableMetadata (com.scalar.db.api.TableMetadata)1 PreparedStatement (java.sql.PreparedStatement)1