Search in sources :

Example 1 with QueryId

use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.

the class SqlClientService method fetchAsync.

public void fetchAsync(Connection connection, QueryId queryId, int cursorBufferSize, SqlClientResult res) {
    ClientMessage requestMessage = SqlFetchCodec.encodeRequest(queryId, cursorBufferSize);
    ClientInvocationFuture future = invokeAsync(requestMessage, connection);
    future.whenComplete(withTryCatch(logger, (message, error) -> handleFetchResponse(connection, res, message, error)));
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) Member(com.hazelcast.cluster.Member) SqlStatement(com.hazelcast.sql.SqlStatement) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionType(com.hazelcast.internal.nio.ConnectionType) SqlFetchCodec(com.hazelcast.client.impl.protocol.codec.SqlFetchCodec) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) ArrayList(java.util.ArrayList) ILogger(com.hazelcast.logging.ILogger) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QueryUtils(com.hazelcast.sql.impl.QueryUtils) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Nonnull(javax.annotation.Nonnull) QueryException(com.hazelcast.sql.impl.QueryException) SqlService(com.hazelcast.sql.SqlService) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) Connection(com.hazelcast.internal.nio.Connection) Data(com.hazelcast.internal.serialization.Data) SqlCloseCodec(com.hazelcast.client.impl.protocol.codec.SqlCloseCodec) SqlMappingDdlCodec(com.hazelcast.client.impl.protocol.codec.SqlMappingDdlCodec) UUID(java.util.UUID) QueryId(com.hazelcast.sql.impl.QueryId) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) List(java.util.List) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) SqlResult(com.hazelcast.sql.SqlResult) AccessControlException(java.security.AccessControlException) ExceptionUtil.withTryCatch(com.hazelcast.internal.util.ExceptionUtil.withTryCatch) SqlExecuteCodec(com.hazelcast.client.impl.protocol.codec.SqlExecuteCodec) SqlErrorCode(com.hazelcast.sql.impl.SqlErrorCode) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 2 with QueryId

use of com.hazelcast.sql.impl.QueryId 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);
        }
    }
}
Also used : QueryException(com.hazelcast.sql.impl.QueryException) QueryId(com.hazelcast.sql.impl.QueryId) SqlPage(com.hazelcast.sql.impl.client.SqlPage) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) QueryException(com.hazelcast.sql.impl.QueryException)

Example 3 with QueryId

use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.

the class SqlClientExecuteCloseRaceTest method testExecuteClose.

@Test
public void testExecuteClose() {
    QueryId queryId = QueryId.create(UUID.randomUUID());
    // Send "execute"
    Connection connection = clientService.getQueryConnection();
    ClientMessage executeResponse = sendExecuteRequest(connection, queryId);
    checkExecuteResponse(executeResponse, true);
    assertEquals(1, memberService.getInternalService().getClientStateRegistry().getCursorCount());
    // Send "close"
    ClientMessage closeRequest = SqlCloseCodec.encodeRequest(queryId);
    clientService.invokeOnConnection(connection, closeRequest);
    assertEquals(0, memberService.getInternalService().getClientStateRegistry().getCursorCount());
}
Also used : QueryId(com.hazelcast.sql.impl.QueryId) Connection(com.hazelcast.internal.nio.Connection) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with QueryId

use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.

the class SqlNoDeserializationTest method testClient.

@Test
public void testClient() {
    int pageSize = KEY_COUNT / 2;
    SqlClientService clientService = (SqlClientService) client().getSql();
    ClientConnection connection = clientService.getQueryConnection();
    // Get the first page through the "execute" request
    QueryId queryId = QueryId.create(connection.getRemoteUuid());
    ClientMessage executeRequest = SqlExecuteCodec.encodeRequest(SQL, Collections.emptyList(), Long.MAX_VALUE, pageSize, null, SqlExpectedResultType.ROWS.getId(), queryId, false);
    SqlExecuteCodec.ResponseParameters executeResponse = SqlExecuteCodec.decodeResponse(clientService.invokeOnConnection(connection, executeRequest));
    if (executeResponse.error != null) {
        fail(executeResponse.error.getMessage());
    }
    assertNotNull(executeResponse.rowPage);
    assertEquals(pageSize, executeResponse.rowPage.getRowCount());
    // Get the second page through the "execute" request
    ClientMessage fetchRequest = SqlFetchCodec.encodeRequest(queryId, pageSize);
    SqlFetchCodec.ResponseParameters fetchResponse = SqlFetchCodec.decodeResponse(clientService.invokeOnConnection(connection, fetchRequest));
    if (fetchResponse.error != null) {
        fail(fetchResponse.error.getMessage());
    }
    assertNotNull(fetchResponse.rowPage);
    assertEquals(pageSize, fetchResponse.rowPage.getRowCount());
}
Also used : QueryId(com.hazelcast.sql.impl.QueryId) SqlFetchCodec(com.hazelcast.client.impl.protocol.codec.SqlFetchCodec) SqlClientService(com.hazelcast.sql.impl.client.SqlClientService) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) SqlExecuteCodec(com.hazelcast.client.impl.protocol.codec.SqlExecuteCodec) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with QueryId

use of com.hazelcast.sql.impl.QueryId in project hazelcast by hazelcast.

the class SqlClientExecuteCloseRaceTest method testCloseExecute.

@Test
public void testCloseExecute() {
    QueryId queryId = QueryId.create(UUID.randomUUID());
    // Send "close"
    Connection connection = clientService.getQueryConnection();
    ClientMessage closeRequest = SqlCloseCodec.encodeRequest(queryId);
    clientService.invokeOnConnection(connection, closeRequest);
    assertEquals(1, memberService.getInternalService().getClientStateRegistry().getCursorCount());
    // Send "execute"
    ClientMessage executeResponse = sendExecuteRequest(connection, queryId);
    assertEquals(0, memberService.getInternalService().getClientStateRegistry().getCursorCount());
    checkExecuteResponse(executeResponse, false);
}
Also used : QueryId(com.hazelcast.sql.impl.QueryId) Connection(com.hazelcast.internal.nio.Connection) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

QueryId (com.hazelcast.sql.impl.QueryId)8 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)6 Test (org.junit.Test)5 Connection (com.hazelcast.internal.nio.Connection)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 ClientConnection (com.hazelcast.client.impl.connection.ClientConnection)3 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)3 QueryException (com.hazelcast.sql.impl.QueryException)3 SqlExecuteCodec (com.hazelcast.client.impl.protocol.codec.SqlExecuteCodec)2 SqlFetchCodec (com.hazelcast.client.impl.protocol.codec.SqlFetchCodec)2 Data (com.hazelcast.internal.serialization.Data)2 SqlResult (com.hazelcast.sql.SqlResult)2 AccessControlException (java.security.AccessControlException)2 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)1 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 SqlCloseCodec (com.hazelcast.client.impl.protocol.codec.SqlCloseCodec)1 SqlMappingDdlCodec (com.hazelcast.client.impl.protocol.codec.SqlMappingDdlCodec)1