use of com.hazelcast.sql.impl.client.SqlPage in project hazelcast by hazelcast.
the class QueryClientStateRegistry method registerAndFetch.
public SqlPage registerAndFetch(UUID clientId, AbstractSqlResult result, int cursorBufferSize, InternalSerializationService serializationService) {
QueryId queryId = result.getQueryId();
QueryClientState clientCursor = new QueryClientState(clientId, queryId, result, false);
boolean delete = false;
try {
// Register the cursor.
QueryClientState previousClientCursor = clientCursors.putIfAbsent(queryId, clientCursor);
// Check if the cursor is already closed.
if (previousClientCursor != null) {
assert previousClientCursor.isClosed();
delete = true;
QueryException error = QueryException.cancelledByUser();
result.close(error);
throw error;
}
// Fetch the next page.
SqlPage page = fetchInternal(clientCursor, cursorBufferSize, serializationService, result.isInfiniteRows());
delete = page.isLast();
return page;
} catch (Exception e) {
delete = true;
throw e;
} finally {
if (delete) {
deleteClientCursor(queryId);
}
}
}
use of com.hazelcast.sql.impl.client.SqlPage in project hazelcast by hazelcast.
the class SqlPageCodecTest method check.
private void check(SqlColumnType type, List<Object> values, boolean last) {
SqlRowMetadata rowMetadata = new SqlRowMetadata(Collections.singletonList(new SqlColumnMetadata("a", type, true)));
List<SqlRow> rows = new ArrayList<>();
for (Object value : values) {
if (SqlPage.convertToData(type) && value != null) {
value = serializationService.toData(value);
}
rows.add(new SqlRowImpl(rowMetadata, new JetSqlRow(TEST_SS, new Object[] { value })));
}
SqlPage originalPage = SqlPage.fromRows(Collections.singletonList(type), rows, last, serializationService);
ClientMessage message = ClientMessage.createForEncode();
SqlPageCodec.encode(message, originalPage);
SqlPage restoredPage = SqlPageCodec.decode(message.frameIterator());
assertEquals(1, restoredPage.getColumnCount());
assertEquals(values.size(), restoredPage.getRowCount());
assertEquals(last, restoredPage.isLast());
assertEquals(1, restoredPage.getColumnTypes().size());
assertEquals(type, restoredPage.getColumnTypes().get(0));
for (int i = 0; i < values.size(); i++) {
Object value = values.get(i);
Object restoredValue = restoredPage.getColumnValueForClient(0, i);
if (restoredValue instanceof Data) {
assertTrue(SqlPage.convertToData(type));
restoredValue = serializationService.toObject(restoredValue);
}
assertEquals(value, restoredValue);
}
}
Aggregations