private Optional<Long> getRecordPointer(UUIDKey documentId) { try { IndexSearchResultIterator resultIterator = index.searchIndex(new EqualsCondition(documentId), Index.NO_SEARCH_LIMIT); if (!resultIterator.isEmpty()) { Key key = resultIterator.next(); LongKey longKey = (LongKey) key.getKey(keyInfo.getKeyNameMapper(), "RECORD_POINTER"); return Optional.of(longKey.getKey()); } else { throw new RecordNotFoundException("Unable to read record: " + documentId + ", could not be found"); } } catch(JasDBStorageException e) { LOG.error("Unable lookup data record for document: {}", documentId); } return Optional.empty(); }
Set<Key> keys = keyFactory.createMultivalueKeys(indexableItem); for(Key key : keys) { if(index.searchIndex(new EqualsCondition(key), Index.NO_SEARCH_LIMIT).isEmpty()) { isInIndex = false; break; isInIndex = !index.searchIndex(new EqualsCondition(keyFactory.createKey(indexableItem)), Index.NO_SEARCH_LIMIT).isEmpty();
protected static EqualsCondition validateCondition(KeyInfo keyInfo, SearchCondition condition) throws JasDBStorageException { if(condition instanceof EqualsCondition) { EqualsCondition equalsCondition = (EqualsCondition) condition; KeyFactory keyFactory = keyInfo.getKeyFactory(); if(!keyFactory.supportsKey(equalsCondition.getKey())) { Key supportedKey = keyFactory.convertKey(equalsCondition.getKey()); return new EqualsCondition(supportedKey); } else { return equalsCondition; } } else { throw new JasDBStorageException("Invalid Equals condition input: " + condition); } }
@Override public RecordResult readRecord(UUIDKey documentId) throws JasDBStorageException { IndexSearchResultIterator resultIterator = index.searchIndex(new EqualsCondition(documentId), Index.NO_SEARCH_LIMIT); if(!resultIterator.isEmpty()) { Key key = resultIterator.next(); DataKey dataKey = (DataKey) key.getKey(keyInfo.getKeyNameMapper(), "data"); return new BtreeRecordResult(dataKey); } else { return new BtreeRecordResult(); } }
private static SearchCondition createCondition(QueryField queryField) { Key searchKey = valueToKey(queryField.getSearchKey()); switch(queryField.getOperator()) { case LARGER_THAN: return new RangeCondition(searchKey, false, null, false); case LARGER_THAN_OR_EQUALS: return new RangeCondition(searchKey, true, null, false); case SMALLER_THAN: return new RangeCondition(null, false, searchKey, false); case SMALLER_THAN_OR_EQUALS: return new RangeCondition(null, false, searchKey, true); case NOT_EQUALS: return new NotEqualsCondition(searchKey); case EQUALS: default: return new EqualsCondition(searchKey); } }
@Override public SearchCondition mergeCondition(KeyNameMapper nameMapper, String sourceField, String mergeField, SearchCondition condition) { if(condition instanceof EqualsCondition) { CompositeKey compositeKey; if(key instanceof CompositeKey) { compositeKey = (CompositeKey) key; } else { compositeKey = new CompositeKey(); compositeKey.addKey(nameMapper, sourceField, key); } return new EqualsCondition(compositeKey.addKey(nameMapper, mergeField, ((EqualsCondition) condition).getKey())); } else if(condition instanceof RangeCondition) { RangeCondition rangeCondition = (RangeCondition) condition; Key startKey = null, endKey = null; if(rangeCondition.getStart() != null) { startKey = new CompositeKey() .addKey(nameMapper, sourceField, key) .addKey(nameMapper, mergeField, rangeCondition.getStart()); } if(rangeCondition.getEnd() != null) { endKey = new CompositeKey() .addKey(nameMapper, sourceField, key) .addKey(nameMapper, mergeField, rangeCondition.getEnd()); } return new RangeCondition(startKey, rangeCondition.isStartIncluded(), endKey, rangeCondition.isEndIncluded()); } return null; }