/** * Indexing management of a PutKeyValueCommand * * @param command the visited PutKeyValueCommand * @param ctx the InvocationContext of the PutKeyValueCommand * @param previousValue the value being replaced by the put operation * @param transactionContext Optional for lazy initialization, or reuse an existing context. */ private void processPutKeyValueCommand( final PutKeyValueCommand command, final InvocationContext ctx, final Object previousValue, TransactionContext transactionContext) { final boolean usingSkipIndexCleanupFlag = usingSkipIndexCleanup(command); // whatever the new type, we might still need to cleanup for the previous value (and schedule // removal first!) Object value = extractValue(command.getValue()); if (!usingSkipIndexCleanupFlag && updateKnownTypesIfNeeded(previousValue) && shouldRemove(value, previousValue)) { if (shouldModifyIndexes(command, ctx)) { transactionContext = transactionContext == null ? makeTransactionalEventContext() : transactionContext; removeFromIndexes(previousValue, extractValue(command.getKey()), transactionContext); } } if (updateKnownTypesIfNeeded(value)) { if (shouldModifyIndexes(command, ctx)) { // This means that the entry is just modified so we need to update the indexes and not add // to them. transactionContext = transactionContext == null ? makeTransactionalEventContext() : transactionContext; updateIndexes( usingSkipIndexCleanupFlag, value, extractValue(command.getKey()), transactionContext); } } }
/** * Indexing management of a PutMapCommand * * @param command the visited PutMapCommand * @param ctx the InvocationContext of the PutMapCommand * @param previousValues a map with the previous values, before processing the given PutMapCommand * @param transactionContext */ private void processPutMapCommand( final PutMapCommand command, final InvocationContext ctx, final Map<Object, Object> previousValues, TransactionContext transactionContext) { if (shouldModifyIndexes(command, ctx)) { Map<Object, Object> dataMap = command.getMap(); final boolean usingSkipIndexCleanupFlag = usingSkipIndexCleanup(command); // Loop through all the keys and put those key-value pairings into lucene. for (Map.Entry<Object, Object> entry : dataMap.entrySet()) { final Object key = extractValue(entry.getKey()); final Object value = extractValue(entry.getValue()); final Object previousValue = previousValues.get(key); if (!usingSkipIndexCleanupFlag && updateKnownTypesIfNeeded(previousValue)) { transactionContext = transactionContext == null ? makeTransactionalEventContext() : transactionContext; removeFromIndexes(previousValue, key, transactionContext); } if (updateKnownTypesIfNeeded(value)) { transactionContext = transactionContext == null ? makeTransactionalEventContext() : transactionContext; updateIndexes(usingSkipIndexCleanupFlag, value, key, transactionContext); } } } }
/** * Indexing management of a ReplaceCommand * * @param command the ReplaceCommand * @param ctx the InvocationContext * @param valueReplaced the previous value on this key * @param transactionContext Optional for lazy initialization, or reuse an existing context. */ private void processReplaceCommand( final ReplaceCommand command, final InvocationContext ctx, final Object valueReplaced, TransactionContext transactionContext) { if (valueReplaced != null && command.isSuccessful() && shouldModifyIndexes(command, ctx)) { final boolean usingSkipIndexCleanupFlag = usingSkipIndexCleanup(command); Object[] parameters = command.getParameters(); Object p2 = extractValue(parameters[2]); final boolean newValueIsIndexed = updateKnownTypesIfNeeded(p2); Object key = extractValue(command.getKey()); if (!usingSkipIndexCleanupFlag) { final Object p1 = extractValue(parameters[1]); final boolean originalIsIndexed = updateKnownTypesIfNeeded(p1); if (p1 != null && originalIsIndexed) { transactionContext = transactionContext == null ? makeTransactionalEventContext() : transactionContext; removeFromIndexes(p1, key, transactionContext); } } if (newValueIsIndexed) { transactionContext = transactionContext == null ? makeTransactionalEventContext() : transactionContext; updateIndexes(usingSkipIndexCleanupFlag, p2, key, transactionContext); } } }
@Override public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable { // This method will get the put() calls on the cache and then send them into Lucene once it's // successful. // do the actual put first. Object toReturn = invokeNextInterceptor(ctx, command); if (shouldModifyIndexes(ctx)) { // First making a check to see if the key is already in the cache or not. If it isn't we can // add the key no problem, // otherwise we need to be updating the indexes as opposed to simply adding to the indexes. getLog().debug("Infinispan Query indexing is triggered"); Object key = command.getKey(); Object value = extractValue(command.getValue()); if (updateKnownTypesIfNeeded(value)) { // This means that the entry is just modified so we need to update the indexes and not add // to them. updateIndexes(value, extractValue(key)); } else { if (updateKnownTypesIfNeeded(toReturn)) { removeFromIndexes(toReturn, extractValue(command.getKey())); } } } return toReturn; }
@Override public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable { Object mapPut = invokeNextInterceptor(ctx, command); if (shouldModifyIndexes(ctx)) { Map<Object, Object> dataMap = command.getMap(); // Loop through all the keys and put those key, value pairings into lucene. for (Map.Entry entry : dataMap.entrySet()) { Object value = extractValue(entry.getValue()); if (updateKnownTypesIfNeeded(value)) { updateIndexes(value, extractValue(entry.getKey())); } } } return mapPut; }
@Override public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable { Object valueReplaced = invokeNextInterceptor(ctx, command); if (valueReplaced != null && command.isSuccessful() && shouldModifyIndexes(ctx)) { Object[] parameters = command.getParameters(); Object p1 = extractValue(parameters[1]); Object p2 = extractValue(parameters[2]); boolean originalIsIndexed = updateKnownTypesIfNeeded(p1); boolean newValueIsIndexed = updateKnownTypesIfNeeded(p2); Object key = extractValue(command.getKey()); if (p1 != null && originalIsIndexed) { removeFromIndexes(p1, key); } if (newValueIsIndexed) { updateIndexes(p2, key); } } return valueReplaced; }