コード例 #1
0
  @Override
  public Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable {

    // This method is called when somebody calls a cache.clear() and we will need to wipe everything
    // in the indexes.
    Object returnValue = invokeNextInterceptor(ctx, command);

    if (shouldModifyIndexes(ctx)) {
      if (getLog().isTraceEnabled())
        getLog().trace("shouldModifyIndexes() is true and we can clear the indexes");

      for (Class c : this.knownClasses.keySet()) {
        EntityIndexBinder binder = this.searchFactory.getIndexBindingForEntity(c);
        if (binder != null) { // check as not all known classes are indexed
          searchFactory
              .getWorker()
              .performWork(
                  new Work<Object>(c, (Serializable) null, WorkType.PURGE_ALL),
                  new TransactionalEventTransactionContext(
                      transactionManager, transactionSynchronizationRegistry));
        }
      }
    }
    return returnValue;
  }
コード例 #2
0
 protected void updateIndexes(Object value, Object key) {
   // The key here is the String representation of the key that is stored in the cache.
   // The key is going to be the documentID for Lucene.
   // The object parameter is the actual value that needs to be removed from lucene.
   if (value == null) throw new NullPointerException("Cannot handle a null value!");
   TransactionContext transactionContext =
       new TransactionalEventTransactionContext(
           transactionManager, transactionSynchronizationRegistry);
   searchFactory
       .getWorker()
       .performWork(
           new Work<Object>(value, keyToString(key), WorkType.UPDATE), transactionContext);
 }