@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();
        QueryResult result = queryEngine.invokeQueryAllPartitions(name, predicate, IterationType.KEY);
        Set<Object> queryResult = new QueryResultCollection(serializationService, IterationType.KEY, false, true, result);
        // TODO: Can't we just use the original set?
        Set<Object> keySet = new HashSet<Object>(queryResult);
        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;
    }
@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();
        QueryResult result = queryEngine.invokeQueryAllPartitions(name, predicate, IterationType.KEY);
        Set<Object> queryResult = new QueryResultCollection(serializationService, IterationType.KEY, false, true, result);
       
        Set<Object> keySet = new HashSet<Object>(queryResult);
        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);
               
                if (predicate.apply(queryEntry)) {
                    Object keyObject = serializationService.toObject(keyData);
                    keySet.add(keyObject);
                }
            } else {
               
                Object keyObject = serializationService.toObject(keyData);
                keySet.remove(keyObject);
            }
        }
        return 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(); queryresult result = queryengine.invokequeryallpartitions(name, predicate, iterationtype.key); set<object> queryresult = new queryresultcollection(serializationservice, iterationtype.key, false, true, result); set<object> keyset = new hashset<object>(queryresult); 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); if (predicate.apply(queryentry)) { object keyobject = serializationservice.toobject(keydata); keyset.add(keyobject); } } else { object keyobject = serializationservice.toobject(keydata); keyset.remove(keyobject); } } return keyset; }