use of io.crate.auth.AccessControl in project crate by crate.
the class PostgresWireProtocol method handleSingleQuery.
private CompletableFuture<?> handleSingleQuery(Statement statement, DelayableWriteChannel channel) {
CompletableFuture<?> result = new CompletableFuture<>();
String query;
try {
query = SqlFormatter.formatSql(statement);
} catch (Exception e) {
query = statement.toString();
}
AccessControl accessControl = getAccessControl.apply(session.sessionContext());
try {
session.analyze("", statement, Collections.emptyList(), query);
session.bind("", "", Collections.emptyList(), null);
DescribeResult describeResult = session.describe('P', "");
List<Symbol> fields = describeResult.getFields();
CompletableFuture<?> execute;
if (fields == null) {
RowCountReceiver rowCountReceiver = new RowCountReceiver(query, channel.bypassDelay(), accessControl);
execute = session.execute("", 0, rowCountReceiver);
} else {
Messages.sendRowDescription(channel, fields, null, describeResult.relation());
ResultSetReceiver resultSetReceiver = new ResultSetReceiver(query, channel.bypassDelay(), TransactionState.IDLE, accessControl, Lists2.map(fields, x -> PGTypes.get(x.valueType())), null);
execute = session.execute("", 0, resultSetReceiver);
}
if (execute != null) {
channel.delayWritesUntil(execute);
}
return session.sync();
} catch (Throwable t) {
Messages.sendErrorResponse(channel, accessControl, t);
result.completeExceptionally(t);
return result;
}
}
Aggregations