use of com.scalar.db.storage.jdbc.query.SelectQuery in project scalardb by scalar-labs.
the class JdbcService method scan.
public List<Result> scan(Scan scan, Connection connection) throws SQLException, ExecutionException {
if (scan instanceof ScanAll) {
operationChecker.check((ScanAll) scan);
} else {
operationChecker.check(scan);
}
TableMetadata tableMetadata = tableMetadataManager.getTableMetadata(scan);
SelectQuery selectQuery = scan instanceof ScanAll ? buildSelectQueryForScanAll((ScanAll) scan, tableMetadata) : buildSelectQueryForScan(scan, tableMetadata);
try (PreparedStatement preparedStatement = connection.prepareStatement(selectQuery.sql())) {
selectQuery.bind(preparedStatement);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
List<Result> ret = new ArrayList<>();
ResultInterpreter resultInterpreter = new ResultInterpreter(scan.getProjections(), tableMetadata);
while (resultSet.next()) {
ret.add(resultInterpreter.interpret(resultSet));
}
return ret;
}
}
}
use of com.scalar.db.storage.jdbc.query.SelectQuery in project scalardb by scalar-labs.
the class JdbcService method getScanner.
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
public Scanner getScanner(Scan scan, Connection connection) throws SQLException, ExecutionException {
if (scan instanceof ScanAll) {
operationChecker.check((ScanAll) scan);
} else {
operationChecker.check(scan);
}
TableMetadata tableMetadata = tableMetadataManager.getTableMetadata(scan);
SelectQuery selectQuery = scan instanceof ScanAll ? buildSelectQueryForScanAll((ScanAll) scan, tableMetadata) : buildSelectQueryForScan(scan, tableMetadata);
PreparedStatement preparedStatement = connection.prepareStatement(selectQuery.sql());
selectQuery.bind(preparedStatement);
ResultSet resultSet = preparedStatement.executeQuery();
return new ScannerImpl(new ResultInterpreter(scan.getProjections(), tableMetadata), connection, preparedStatement, resultSet);
}
use of com.scalar.db.storage.jdbc.query.SelectQuery in project scalardb by scalar-labs.
the class JdbcService method get.
public Optional<Result> get(Get get, Connection connection) throws SQLException, ExecutionException {
operationChecker.check(get);
TableMetadata tableMetadata = tableMetadataManager.getTableMetadata(get);
SelectQuery selectQuery = queryBuilder.select(get.getProjections()).from(get.forNamespace().get(), get.forTable().get(), tableMetadata).where(get.getPartitionKey(), get.getClusteringKey()).build();
try (PreparedStatement preparedStatement = connection.prepareStatement(selectQuery.sql())) {
selectQuery.bind(preparedStatement);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
Optional<Result> ret = Optional.of(new ResultInterpreter(get.getProjections(), tableMetadata).interpret(resultSet));
if (resultSet.next()) {
throw new IllegalArgumentException("please use scan() for non-exact match selection");
}
return ret;
}
return Optional.empty();
}
}
}
Aggregations