Search in sources :

Example 6 with QueryResult

use of com.hazelcast.map.impl.query.QueryResult in project hazelcast by hazelcast.

the class NodeQueryCacheEndToEndConstructor method populateWithoutValues.

private void populateWithoutValues(InternalQueryCache queryCache, Collection<QueryResult> resultSets) {
    for (QueryResult queryResult : resultSets) {
        try {
            if (queryResult == null) {
                continue;
            }
            for (QueryResultRow row : queryResult) {
                Data dataKey = row.getKey();
                queryCache.setInternal(dataKey, null, false, EntryEventType.ADDED);
            }
        } catch (Throwable t) {
            throw ExceptionUtil.rethrow(t);
        }
    }
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) QueryResultRow(com.hazelcast.map.impl.query.QueryResultRow) Data(com.hazelcast.nio.serialization.Data)

Example 7 with QueryResult

use of com.hazelcast.map.impl.query.QueryResult in project hazelcast by hazelcast.

the class NodeQueryCacheEndToEndConstructor method populateWithValues.

private void populateWithValues(InternalQueryCache queryCache, Collection<QueryResult> resultSets) {
    for (QueryResult queryResult : resultSets) {
        try {
            if (queryResult == null) {
                continue;
            }
            for (QueryResultRow row : queryResult) {
                Data keyData = row.getKey();
                Data valueData = row.getValue();
                queryCache.setInternal(keyData, valueData, false, EntryEventType.ADDED);
            }
        } catch (Throwable t) {
            throw ExceptionUtil.rethrow(t);
        }
    }
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) QueryResultRow(com.hazelcast.map.impl.query.QueryResultRow) Data(com.hazelcast.nio.serialization.Data)

Example 8 with QueryResult

use of com.hazelcast.map.impl.query.QueryResult in project hazelcast by hazelcast.

the class MapPublisherCreateMessageTask method getQueryResults.

private Set<Data> getQueryResults(List<Future> futures) {
    Set<Data> results = new HashSet<Data>(futures.size());
    for (Future future : futures) {
        Object result = null;
        try {
            result = future.get();
        } catch (Throwable t) {
            ExceptionUtil.rethrow(t);
        }
        if (result == null) {
            continue;
        }
        QueryResult queryResult = (QueryResult) result;
        for (QueryResultRow row : queryResult) {
            results.add(row.getKey());
        }
    }
    return results;
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult) QueryResultRow(com.hazelcast.map.impl.query.QueryResultRow) Future(java.util.concurrent.Future) Data(com.hazelcast.nio.serialization.Data) HashSet(java.util.HashSet)

Example 9 with QueryResult

use of com.hazelcast.map.impl.query.QueryResult in project hazelcast by hazelcast.

the class TransactionalMapProxy method keySet.

@Override
@SuppressWarnings("unchecked")
public Set keySet(Predicate predicate) {
    checkTransactionState();
    checkNotNull(predicate, "Predicate should not be null!");
    checkNotInstanceOf(PagingPredicate.class, predicate, "Paging is not supported for Transactional queries!");
    MapQueryEngine queryEngine = mapServiceContext.getMapQueryEngine(name);
    SerializationService serializationService = getNodeEngine().getSerializationService();
    Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.KEY).build();
    QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
    Set result = QueryResultUtils.transformToSet(serializationService, queryResult, predicate, IterationType.KEY, true);
    // TODO: Can't we just use the original set?
    Set<Object> keySet = new HashSet<Object>(result);
    Extractors extractors = mapServiceContext.getExtractors(name);
    for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
        Data keyData = entry.getKey();
        if (!Type.REMOVED.equals(entry.getValue().type)) {
            Object value = (entry.getValue().value instanceof Data) ? toObjectIfNeeded(entry.getValue().value) : entry.getValue().value;
            QueryableEntry queryEntry = new CachedQueryEntry((InternalSerializationService) serializationService, keyData, value, extractors);
            // apply predicate on txMap
            if (predicate.apply(queryEntry)) {
                Object keyObject = serializationService.toObject(keyData);
                keySet.add(keyObject);
            }
        } else {
            // meanwhile remove keys which are not in txMap
            Object keyObject = serializationService.toObject(keyData);
            keySet.remove(keyObject);
        }
    }
    return keySet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Query(com.hazelcast.map.impl.query.Query) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) QueryResult(com.hazelcast.map.impl.query.QueryResult) Extractors(com.hazelcast.query.impl.getters.Extractors) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) HashMap(java.util.HashMap) Map(java.util.Map) TransactionalMap(com.hazelcast.core.TransactionalMap) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) HashSet(java.util.HashSet)

Example 10 with QueryResult

use of com.hazelcast.map.impl.query.QueryResult in project hazelcast by hazelcast.

the class PublisherCreateOperation method createSnapshot.

private QueryResult createSnapshot() throws Exception {
    QueryResult queryResult = runInitialQuery();
    replayEventsOnResultSet(queryResult);
    return queryResult;
}
Also used : QueryResult(com.hazelcast.map.impl.query.QueryResult)

Aggregations

QueryResult (com.hazelcast.map.impl.query.QueryResult)13 Query (com.hazelcast.map.impl.query.Query)7 Data (com.hazelcast.nio.serialization.Data)7 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)6 QueryResultRow (com.hazelcast.map.impl.query.QueryResultRow)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 TransactionalMap (com.hazelcast.core.TransactionalMap)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 SerializationService (com.hazelcast.spi.serialization.SerializationService)2 Set (java.util.Set)2 MapAssignAndGetUuidsOperation (com.hazelcast.client.impl.protocol.task.map.MapAssignAndGetUuidsOperation)1 MapAssignAndGetUuidsOperationFactory (com.hazelcast.client.impl.protocol.task.map.MapAssignAndGetUuidsOperationFactory)1 Member (com.hazelcast.core.Member)1 BatchNearCacheInvalidation (com.hazelcast.internal.nearcache.impl.invalidation.BatchNearCacheInvalidation)1 SingleNearCacheInvalidation (com.hazelcast.internal.nearcache.impl.invalidation.SingleNearCacheInvalidation)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 MapEntriesWithCursor (com.hazelcast.map.impl.iterator.MapEntriesWithCursor)1 MapKeysWithCursor (com.hazelcast.map.impl.iterator.MapKeysWithCursor)1 UuidFilter (com.hazelcast.map.impl.nearcache.invalidation.UuidFilter)1