private SearchCondition handleEqualsToRange(EqualsCondition equalsCondition) { int nrOfKeys = keyInfo.getKeyFields().size(); if(nrOfKeys > 1) { //composite keys always use range search return new RangeCondition(equalsCondition.getKey(), true, equalsCondition.getKey(), true); } else { return equalsCondition; } }
private static void generateEqualsCondition(StringBuilder builder, String field, EqualsCondition equalsCondition) { Key key = equalsCondition.getKey(); builder.append(field).append("="); handleValueAppend(builder, key); }
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 IndexSearchResultIteratorCollection search(SearchCondition condition, SearchLimit limit) throws JasDBStorageException { EqualsCondition equalsCondition = validateCondition(keyInfo, condition); Key desiredKey = equalsCondition.getKey(); lockManager.startLockChain(); lockManager.acquireLock(LockIntentType.READ, rootBlock); try { LeaveBlock leaveBlock = rootBlock.findLeaveBlock(LockIntentType.READ, equalsCondition.getKey()); return doLeaveSearch(leaveBlock, desiredKey); } finally { lockManager.releaseLockChain(); } }
@Override public IndexSearchResultIteratorCollection search(SearchCondition condition, SearchLimit limit) throws JasDBStorageException { IndexIterator indexIterator = new FullIndexIterator(rootBlock, lockManager, blockPersister); EqualsCondition equalsCondition = EqualsSearchOperation.validateCondition(keyInfo, condition); Key undesiredKey = equalsCondition.getKey(); List<Key> results = new LinkedList<>(); for(Key key : indexIterator) { if(key.compare(undesiredKey, CompareMethod.EQUALS).getCompare() != 0) { results.add(key); } if(limit.isMaxReached(results.size())) { break; } } return new IndexSearchResultIteratorImpl(results, keyInfo.getKeyNameMapper()); } }
@Override public SearchCondition mergeCondition(KeyNameMapper nameMapper, String sourceField, String mergeField, SearchCondition condition) { if(condition instanceof NotEqualsCondition) { CompositeKey compositeKey; Key key = getKey(); if(key instanceof CompositeKey) { compositeKey = (CompositeKey) key; } else { compositeKey = new CompositeKey(); compositeKey.addKey(nameMapper, sourceField, key); } return new NotEqualsCondition(compositeKey.addKey(nameMapper, mergeField, ((EqualsCondition) condition).getKey())); } return null; }
@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; }