예제 #1
0
 @Override
 public Result<K, T> execute(Query<K, T> query) {
   K startKey = query.getStartKey();
   K endKey = query.getEndKey();
   if (startKey == null) {
     if (!cacheEntryList.isEmpty()) {
       startKey = (K) cacheEntryList.first();
     }
   }
   if (endKey == null) {
     if (!cacheEntryList.isEmpty()) {
       endKey = (K) cacheEntryList.last();
     }
   }
   query.setFields(getFieldsToQuery(query.getFields()));
   ConcurrentSkipListSet<K> cacheEntrySubList = null;
   try {
     cacheEntrySubList =
         (ConcurrentSkipListSet<K>) cacheEntryList.subSet(startKey, true, endKey, true);
   } catch (NullPointerException npe) {
     LOG.error(
         "NPE occurred while executing the query for JCacheStore. Hence returning empty entry set.",
         npe);
     return new JCacheResult<>(this, query, new ConcurrentSkipListSet<K>());
   }
   return new JCacheResult<>(this, query, cacheEntrySubList);
 }
예제 #2
0
  @Override
  public Result<K, T> execute(Query<K, T> query) {
    K startKey = query.getStartKey();
    K endKey = query.getEndKey();
    if (startKey == null) {
      startKey = map.firstKey();
    }
    if (endKey == null) {
      endKey = map.lastKey();
    }

    // check if query.fields is null
    query.setFields(getFieldsToQuery(query.getFields()));

    NavigableMap<K, T> submap = map.subMap(startKey, true, endKey, true);

    return new MemResult<K, T>(this, query, submap);
  }
예제 #3
0
 @Override
 public long deleteByQuery(Query<K, T> query) {
   try {
     long deletedRows = 0;
     Result<K, T> result = query.execute();
     String[] fields = getFieldsToQuery(query.getFields());
     boolean isAllFields = Arrays.equals(fields, getFields());
     while (result.next()) {
       if (isAllFields) {
         if (delete(result.getKey())) {
           deletedRows++;
         }
       } else {
         ArrayList<String> excludedFields = new ArrayList<>();
         for (String field : getFields()) {
           if (!Arrays.asList(fields).contains(field)) {
             excludedFields.add(field);
           }
         }
         T newClonedObj =
             getPersistent(
                 result.get(), excludedFields.toArray(new String[excludedFields.size()]));
         if (delete(result.getKey())) {
           put(result.getKey(), newClonedObj);
           deletedRows++;
         }
       }
     }
     LOG.info("JCache Gora datastore deleled {} rows from Persistent datastore.", deletedRows);
     return deletedRows;
   } catch (Exception e) {
     LOG.error(
         "Exception occurred while deleting entries from JCache Gora datastore. Hence returning 0.",
         e);
     return 0;
   }
 }