All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.venky.swf.plugins.lucene.extensions.AfterCommitExtension Maven / Gradle / Ivy

package com.venky.swf.plugins.lucene.extensions;

import java.util.List;

import org.apache.lucene.document.Document;

import com.venky.cache.Cache;
import com.venky.extension.Extension;
import com.venky.extension.Registry;
import com.venky.swf.db._IDatabase._ITransaction;
import com.venky.swf.plugins.lucene.index.background.IndexManager;

public class AfterCommitExtension implements Extension{
	private static AfterCommitExtension instance = new AfterCommitExtension();
	static {
		Registry.instance().registerExtension("after.commit", instance);
	}
	public void invoke(Object... context) {
		_ITransaction completedTransaction = (_ITransaction)context[0];
		addDocuments((Cache>)completedTransaction.getAttribute("lucene.added"));
		updateDocuments((Cache>)completedTransaction.getAttribute("lucene.updated"));
		removeDocuments((Cache>)completedTransaction.getAttribute("lucene.removed"));
	
	}
	public void addDocuments(Cache> documentsByTable){
		if (documentsByTable == null){
			return;
		}
		for (String tableName: documentsByTable.keySet()){
			List documents = documentsByTable.get(tableName);
			IndexManager.instance().addDocuments(tableName, documents);
		}
	}
	public void updateDocuments(Cache> documentsByTable){
		if (documentsByTable == null){
			return;
		}
		for (String tableName: documentsByTable.keySet()){
			List documents = documentsByTable.get(tableName);
			IndexManager.instance().updateDocuments(tableName, documents);
		}
	}
	public void removeDocuments(Cache> documentsByTable){
		if (documentsByTable == null){
			return;
		}
		for (String tableName: documentsByTable.keySet()){
			List documents = documentsByTable.get(tableName);
			IndexManager.instance().removeDocuments(tableName, documents);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy