@Override public OIndexTxAware<T> clear() { database.getMicroOrRegularTransaction().addIndexEntry(delegate, super.getName(), OPERATION.CLEAR, null, null); return this; }
/** * @return this transaction ID as seen by the client of this transaction. */ default int getClientTransactionId() { return getId(); }
@Override public long getSize() { long tot = delegate.getSize(); final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction().getIndexChanges(delegate.getName()); if (indexChanges != null) { if (indexChanges.cleared) // BEGIN FROM 0 tot = 0; for (final Entry<Object, OTransactionIndexChangesPerKey> entry : indexChanges.changesPerKey.entrySet()) { for (final OTransactionIndexEntry e : entry.getValue().entries) { if (e.operation == OPERATION.REMOVE) { if (e.value == null) // KEY REMOVED tot--; } } } for (final OTransactionIndexEntry e : indexChanges.nullKeyChanges.entries) { if (e.operation == OPERATION.REMOVE) { if (e.value == null) // KEY REMOVED tot--; } } } return tot; }
@Override public boolean remove(final Object key, final OIdentifiable value) { if (key != null) { OBasicTransaction transaction = getDatabase().getMicroOrRegularTransaction(); if (transaction.isActive()) { transaction.addIndexEntry(this, super.getName(), OTransactionIndexChanges.OPERATION.REMOVE, encodeKey(key), value); OLuceneTxChanges transactionChanges = getTransactionChanges(transaction); transactionChanges.remove(key, value); return true; } else { while (true) { try { return storage.callIndexEngine(false, false, indexId, engine -> { OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine; return indexEngine.remove(key, value); }); } catch (OInvalidIndexEngineIdException e) { doReloadIndexEngine(); } } } } return true; }
@Override public OIndexCursor iterateEntries(Collection<?> keys, boolean ascSortOrder) { final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction() .getIndexChangesInternal(delegate.getName()); if (indexChanges == null) return super.iterateEntries(keys, ascSortOrder);
private OLuceneTxChanges getTransactionChanges(OBasicTransaction transaction) { OLuceneTxChanges changes = (OLuceneTxChanges) transaction.getCustomData(getName()); if (changes == null) { while (true) try { changes = storage.callIndexEngine(false, false, indexId, engine -> { OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine; try { return indexEngine.buildTxChanges(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Cannot get searcher from index " + getName()), e); } }); break; } catch (OInvalidIndexEngineIdException e) { doReloadIndexEngine(); } transaction.setCustomData(getName(), changes); } return changes; }
private void resetTransactionChanges(OBasicTransaction transaction) { transaction.setCustomData(getName(), null); }
@Override public Set<OIdentifiable> get(final Object key) { final OBasicTransaction transaction = getDatabase().getMicroOrRegularTransaction(); if (transaction.isActive()) { while (true) { try { return storage.callIndexEngine(false, false, indexId, engine -> { OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine; return indexEngine.getInTx(key, getTransactionChanges(transaction)); }); } catch (OInvalidIndexEngineIdException e) { doReloadIndexEngine(); } } } else { while (true) { try { return (Set<OIdentifiable>) storage.getIndexValue(indexId, key); } catch (OInvalidIndexEngineIdException e) { doReloadIndexEngine(); } } } }
transaction.addChangedDocument(this);
OBasicTransaction transaction = getDatabase().getMicroOrRegularTransaction(); if (transaction.isActive()) { OLuceneTxChanges transactionChanges = getTransactionChanges(transaction); transaction.addIndexEntry(this, super.getName(), OTransactionIndexChanges.OPERATION.PUT, encodeKey(key), singleValue);
@Override public Collection<OIdentifiable> get(Object key) { final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction() .getIndexChangesInternal(delegate.getName()); if (indexChanges == null) { Collection<OIdentifiable> res = super.get(key);
@Override public boolean remove(Object key) { key = getCollatingValue(key); database.getMicroOrRegularTransaction().addIndexEntry(delegate, super.getName(), OPERATION.REMOVE, key, null); return true; }
@Override public OIndexCursor iterateEntries(Collection<?> keys, boolean ascSortOrder) { final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction() .getIndexChangesInternal(delegate.getName()); if (indexChanges == null) return super.iterateEntries(keys, ascSortOrder);
@Override public Object getLastKey() { final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction().getIndexChanges(delegate.getName()); if (indexChanges == null) return delegate.getLastKey();
@Override public boolean remove(Object iKey, final OIdentifiable iRID) { iKey = getCollatingValue(iKey); database.getMicroOrRegularTransaction().addIndexEntry(delegate, super.getName(), OPERATION.REMOVE, iKey, iRID); return true; }
@Override public OIdentifiable get(Object key) { final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction() .getIndexChangesInternal(delegate.getName()); if (indexChanges == null) return super.get(key); key = getCollatingValue(key); OIdentifiable result; if (!indexChanges.cleared) // BEGIN FROM THE UNDERLYING RESULT SET result = super.get(key); else // BEGIN FROM EMPTY RESULT SET result = null; // FILTER RESULT SET WITH TRANSACTIONAL CHANGES final Map.Entry<Object, OIdentifiable> entry = calculateTxIndexEntry(key, result, indexChanges); if (entry == null) return null; return entry.getValue(); }
@Override public Object getFirstKey() { final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction().getIndexChanges(delegate.getName()); if (indexChanges == null) return delegate.getFirstKey();
@Override public OIndexTxAware<T> put(Object iKey, final OIdentifiable iValue) { checkForKeyType(iKey); final ORID rid = iValue.getIdentity(); if (!rid.isValid()) if (iValue instanceof ORecord) // EARLY SAVE IT ((ORecord) iValue).save(); else throw new IllegalArgumentException("Cannot store non persistent RID as index value for key '" + iKey + "'"); iKey = getCollatingValue(iKey); database.getMicroOrRegularTransaction().addIndexEntry(delegate, super.getName(), OPERATION.PUT, iKey, iValue); return this; }
@Override public OIndexCursor iterateEntriesMinor(Object toKey, boolean toInclusive, boolean ascOrder) { final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction() .getIndexChangesInternal(delegate.getName()); if (indexChanges == null) return super.iterateEntriesMinor(toKey, toInclusive, ascOrder); toKey = getCollatingValue(toKey); final OIndexCursor txCursor; final Object firstKey = indexChanges.getFirstKey(); if (ascOrder) txCursor = new PureTxBetweenIndexForwardCursor(firstKey, true, toKey, toInclusive, indexChanges); else txCursor = new PureTxBetweenIndexBackwardCursor(firstKey, true, toKey, toInclusive, indexChanges); if (indexChanges.cleared) return txCursor; final OIndexCursor backedCursor = super.iterateEntriesMinor(toKey, toInclusive, ascOrder); return new OIndexTxCursor(txCursor, backedCursor, ascOrder, indexChanges); }
@Override public OIndexCursor iterateEntriesMinor(Object toKey, boolean toInclusive, boolean ascOrder) { final OTransactionIndexChanges indexChanges = database.getMicroOrRegularTransaction() .getIndexChangesInternal(delegate.getName()); if (indexChanges == null) return super.iterateEntriesMinor(toKey, toInclusive, ascOrder); toKey = getCollatingValue(toKey); final OIndexCursor txCursor; final Object firstKey = indexChanges.getFirstKey(); if (ascOrder) txCursor = new PureTxBetweenIndexForwardCursor(firstKey, true, toKey, toInclusive, indexChanges); else txCursor = new PureTxBetweenIndexBackwardCursor(firstKey, true, toKey, toInclusive, indexChanges); if (indexChanges.cleared) return txCursor; final OIndexCursor backedCursor = super.iterateEntriesMinor(toKey, toInclusive, ascOrder); return new OIndexTxCursor(txCursor, backedCursor, ascOrder, indexChanges); }