Search in sources :

Example 1 with UpsertQuery

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

Aggregations

TableMetadata (com.scalar.db.api.TableMetadata)1 UpsertQuery (com.scalar.db.storage.jdbc.query.UpsertQuery)1 PreparedStatement (java.sql.PreparedStatement)1