Author: epbernard
Date: 2006-11-06 20:16:53 -0500 (Mon, 06 Nov 2006)
New Revision: 10743
Added:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/FullTextSession.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextEventListener.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/FullTextQueryImpl.java
Removed:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/LuceneSession.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/LuceneEventListener.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/LuceneQueryImpl.java
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/ScrollableResultsImpl.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/util/ContextHelper.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/TransactionTest.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/BridgeTest.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/fieldAccess/FieldAccessTest.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/session/MassIndexTest.java
Log:
ANN-488 renaming
Copied:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/FullTextSession.java
(from rev 10742,
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/LuceneSession.java)
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/LuceneSession.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/FullTextSession.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -0,0 +1,465 @@
+//$Id: $
+package org.hibernate.search;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.transaction.Status;
+
+import org.hibernate.CacheMode;
+import org.hibernate.Criteria;
+import org.hibernate.EntityMode;
+import org.hibernate.Filter;
+import org.hibernate.FlushMode;
+import org.hibernate.HibernateException;
+import org.hibernate.LockMode;
+import org.hibernate.Query;
+import org.hibernate.ReplicationMode;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.engine.query.ParameterMetadata;
+import org.hibernate.impl.SessionImpl;
+import org.hibernate.search.query.FullTextQueryImpl;
+import org.hibernate.search.event.FullTextEventListener;
+import org.hibernate.search.util.ContextHelper;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.backend.UpdateWork;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkQueue;
+import org.hibernate.search.backend.impl.BatchLuceneWorkQueue;
+import org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.stat.SessionStatistics;
+import org.hibernate.type.Type;
+import org.apache.lucene.document.Document;
+
+/**
+ * Lucene aware session that allows lucene query creations
+ *
+ * @author Emmanuel Bernard
+ */
+public class FullTextSession implements Session {
+ private final SessionImpl session;
+ private PostTransactionWorkQueueSynchronization postTransactionWorkQueueSynch;
+
+ public FullTextSession(Session session) {
+ this.session = (SessionImpl) session;
+ }
+
+ /**
+ * Execute a Lucene query and retrieve managed objects of type entities (or their
indexed subclasses)
+ * If entities is empty, include all indexed entities
+ *
+ * @param entities must be immutable for the lifetime of the query object
+ */
+ public Query createLuceneQuery(org.apache.lucene.search.Query luceneQuery, Class...
entities) {
+ return new FullTextQueryImpl( luceneQuery, entities, session, new
ParameterMetadata(null, null) );
+ }
+
+ /**
+ * (re)index an entity.
+ * Non indexable entities are ignored
+ * The entity must be associated with the session
+ *
+ * @param entity must not be null
+ */
+ public void index(Object entity) {
+ if (entity == null) return;
+ Class clazz = entity.getClass();
+ FullTextEventListener listener = ContextHelper.getLuceneEventListener( session );
+ DocumentBuilder<Object> builder = listener.getDocumentBuilders().get( clazz );
+ if ( builder != null ) {
+ Serializable id = session.getIdentifier( entity );
+ Document doc = builder.getDocument( entity, id );
+ UpdateWork work = new UpdateWork( id, entity.getClass(), doc );
+ processWork( work, listener.getDocumentBuilders(),
listener.getLockableDirectoryProviders() );
+ }
+ //TODO
+ //need to add elements in a queue kept at the Session level
+ //the queue will be processed by a Lucene(Auto)FlushEventListener
+ //note that we could keep this queue somewhere in the event listener in the mean time
but that requires
+ // a synchronized hashmap holding this queue on a per session basis plus some session
house keeping (yuk)
+ //an other solution would be to subclass SessionImpl instead of having this
LuceneSession delecation model
+ // this is an open discussion
+ }
+
+ private void processWork(Work work, Map<Class, DocumentBuilder<Object>>
documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ if ( session.isTransactionInProgress() ) {
+ if ( postTransactionWorkQueueSynch == null ||
postTransactionWorkQueueSynch.isConsumed() ) {
+ postTransactionWorkQueueSynch = createWorkQueueSync( documentBuilders,
lockableDirectoryProviders);
+ session.getTransaction().registerSynchronization( postTransactionWorkQueueSynch );
+ }
+ postTransactionWorkQueueSynch.add( work );
+ }
+ else {
+ //no transaction work right away
+ PostTransactionWorkQueueSynchronization sync =
+ createWorkQueueSync( documentBuilders, lockableDirectoryProviders );
+ sync.add( work );
+ sync.afterCompletion( Status.STATUS_COMMITTED );
+ }
+ }
+
+ private PostTransactionWorkQueueSynchronization createWorkQueueSync(
+ Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders,
lockableDirectoryProviders );
+ return new PostTransactionWorkQueueSynchronization( workQueue );
+ }
+
+ public Query createSQLQuery(String sql, String returnAlias, Class returnClass) {
+ return session.createSQLQuery( sql, returnAlias, returnClass );
+ }
+
+ public Query createSQLQuery(String sql, String[] returnAliases, Class[] returnClasses)
{
+ return session.createSQLQuery( sql, returnAliases, returnClasses );
+ }
+
+ public int delete(String query) throws HibernateException {
+ return session.delete( query );
+ }
+
+ public int delete(String query, Object value, Type type) throws HibernateException {
+ return session.delete( query, value, type );
+ }
+
+ public int delete(String query, Object[] values, Type[] types) throws HibernateException
{
+ return session.delete( query, values, types );
+ }
+
+ public Collection filter(Object collection, String filter) throws HibernateException {
+ return session.filter( collection, filter );
+ }
+
+ public Collection filter(Object collection, String filter, Object value, Type type)
throws HibernateException {
+ return session.filter( collection, filter, value, type );
+ }
+
+ public Collection filter(Object collection, String filter, Object[] values, Type[]
types) throws HibernateException {
+ return session.filter( collection, filter, values, types );
+ }
+
+ public List find(String query) throws HibernateException {
+ return session.find( query );
+ }
+
+ public List find(String query, Object value, Type type) throws HibernateException {
+ return session.find( query, value, type );
+ }
+
+ public List find(String query, Object[] values, Type[] types) throws HibernateException
{
+ return session.find( query, values, types );
+ }
+
+ public Iterator iterate(String query) throws HibernateException {
+ return session.iterate( query );
+ }
+
+ public Iterator iterate(String query, Object value, Type type) throws HibernateException
{
+ return session.iterate( query, value, type );
+ }
+
+ public Iterator iterate(String query, Object[] values, Type[] types) throws
HibernateException {
+ return session.iterate( query, values, types );
+ }
+
+ public void save(String entityName, Object object, Serializable id) throws
HibernateException {
+ session.save( entityName, object, id );
+ }
+
+ public void save(Object object, Serializable id) throws HibernateException {
+ session.save( object, id );
+ }
+
+ public Object saveOrUpdateCopy(String entityName, Object object) throws
HibernateException {
+ return session.saveOrUpdateCopy( entityName, object );
+ }
+
+ public Object saveOrUpdateCopy(String entityName, Object object, Serializable id) throws
HibernateException {
+ return session.saveOrUpdateCopy( entityName, object, id );
+ }
+
+ public Object saveOrUpdateCopy(Object object) throws HibernateException {
+ return session.saveOrUpdateCopy( object );
+ }
+
+ public Object saveOrUpdateCopy(Object object, Serializable id) throws HibernateException
{
+ return session.saveOrUpdateCopy( object, id );
+ }
+
+ public void update(String entityName, Object object, Serializable id) throws
HibernateException {
+ session.update( entityName, object, id );
+ }
+
+ public void update(Object object, Serializable id) throws HibernateException {
+ session.update( object, id );
+ }
+
+ public Transaction beginTransaction() throws HibernateException {
+ return session.beginTransaction();
+ }
+
+ public void cancelQuery() throws HibernateException {
+ session.cancelQuery();
+ }
+
+ public void clear() {
+ session.clear();
+ }
+
+ public Connection close() throws HibernateException {
+ return session.close();
+ }
+
+ public Connection connection() throws HibernateException {
+ return session.connection();
+ }
+
+ public boolean contains(Object object) {
+ return session.contains( object );
+ }
+
+ public Criteria createCriteria(String entityName) {
+ return session.createCriteria( entityName );
+ }
+
+ public Criteria createCriteria(String entityName, String alias) {
+ return session.createCriteria( entityName, alias );
+ }
+
+ public Criteria createCriteria(Class persistentClass) {
+ return session.createCriteria( persistentClass );
+ }
+
+ public Criteria createCriteria(Class persistentClass, String alias) {
+ return session.createCriteria( persistentClass, alias );
+ }
+
+ public Query createFilter(Object collection, String queryString) throws
HibernateException {
+ return session.createFilter( collection, queryString );
+ }
+
+ public Query createQuery(String queryString) throws HibernateException {
+ return session.createQuery( queryString );
+ }
+
+ public SQLQuery createSQLQuery(String queryString) throws HibernateException {
+ return session.createSQLQuery( queryString );
+ }
+
+ public void delete(String entityName, Object object) throws HibernateException {
+ session.delete( entityName, object );
+ }
+
+ public void delete(Object object) throws HibernateException {
+ session.delete( object );
+ }
+
+ public void disableFilter(String filterName) {
+ session.disableFilter( filterName );
+ }
+
+ public Connection disconnect() throws HibernateException {
+ return session.disconnect();
+ }
+
+ public Filter enableFilter(String filterName) {
+ return session.enableFilter( filterName );
+ }
+
+ public void evict(Object object) throws HibernateException {
+ session.evict( object );
+ }
+
+ public void flush() throws HibernateException {
+ session.flush();
+ }
+
+ public Object get(Class clazz, Serializable id) throws HibernateException {
+ return session.get( clazz, id );
+ }
+
+ public Object get(Class clazz, Serializable id, LockMode lockMode) throws
HibernateException {
+ return session.get( clazz, id, lockMode );
+ }
+
+ public Object get(String entityName, Serializable id) throws HibernateException {
+ return session.get( entityName, id );
+ }
+
+ public Object get(String entityName, Serializable id, LockMode lockMode) throws
HibernateException {
+ return session.get( entityName, id, lockMode );
+ }
+
+ public CacheMode getCacheMode() {
+ return session.getCacheMode();
+ }
+
+ public LockMode getCurrentLockMode(Object object) throws HibernateException {
+ return session.getCurrentLockMode( object );
+ }
+
+ public Filter getEnabledFilter(String filterName) {
+ return session.getEnabledFilter( filterName );
+ }
+
+ public EntityMode getEntityMode() {
+ return session.getEntityMode();
+ }
+
+ public String getEntityName(Object object) throws HibernateException {
+ return session.getEntityName( object );
+ }
+
+ public FlushMode getFlushMode() {
+ return session.getFlushMode();
+ }
+
+ public Serializable getIdentifier(Object object) throws HibernateException {
+ return session.getIdentifier( object );
+ }
+
+ public Query getNamedQuery(String queryName) throws HibernateException {
+ return session.getNamedQuery( queryName );
+ }
+
+ public org.hibernate.Session getSession(EntityMode entityMode) {
+ return session.getSession( entityMode );
+ }
+
+ public SessionFactory getSessionFactory() {
+ return session.getSessionFactory();
+ }
+
+ public SessionStatistics getStatistics() {
+ return session.getStatistics();
+ }
+
+ public Transaction getTransaction() {
+ return session.getTransaction();
+ }
+
+ public boolean isConnected() {
+ return session.isConnected();
+ }
+
+ public boolean isDirty() throws HibernateException {
+ return session.isDirty();
+ }
+
+ public boolean isOpen() {
+ return session.isOpen();
+ }
+
+ public Object load(String entityName, Serializable id) throws HibernateException {
+ return session.load( entityName, id );
+ }
+
+ public Object load(String entityName, Serializable id, LockMode lockMode) throws
HibernateException {
+ return session.load( entityName, id, lockMode );
+ }
+
+ public void load(Object object, Serializable id) throws HibernateException {
+ session.load( object, id );
+ }
+
+ public Object load(Class theClass, Serializable id) throws HibernateException {
+ return session.load( theClass, id );
+ }
+
+ public Object load(Class theClass, Serializable id, LockMode lockMode) throws
HibernateException {
+ return session.load( theClass, id, lockMode );
+ }
+
+ public void lock(String entityName, Object object, LockMode lockMode) throws
HibernateException {
+ session.lock( entityName, object, lockMode );
+ }
+
+ public void lock(Object object, LockMode lockMode) throws HibernateException {
+ session.lock( object, lockMode );
+ }
+
+ public Object merge(String entityName, Object object) throws HibernateException {
+ return session.merge( entityName, object );
+ }
+
+ public Object merge(Object object) throws HibernateException {
+ return session.merge( object );
+ }
+
+ public void persist(String entityName, Object object) throws HibernateException {
+ session.persist( entityName, object );
+ }
+
+ public void persist(Object object) throws HibernateException {
+ session.persist( object );
+ }
+
+ public void reconnect() throws HibernateException {
+ session.reconnect();
+ }
+
+ public void reconnect(Connection connection) throws HibernateException {
+ session.reconnect( connection );
+ }
+
+ public void refresh(Object object) throws HibernateException {
+ session.refresh( object );
+ }
+
+ public void refresh(Object object, LockMode lockMode) throws HibernateException {
+ session.refresh( object, lockMode );
+ }
+
+ public void replicate(String entityName, Object object, ReplicationMode replicationMode)
throws HibernateException {
+ session.replicate( entityName, object, replicationMode );
+ }
+
+ public void replicate(Object object, ReplicationMode replicationMode) throws
HibernateException {
+ session.replicate( object, replicationMode );
+ }
+
+ public Serializable save(String entityName, Object object) throws HibernateException {
+ return session.save( entityName, object );
+ }
+
+ public Serializable save(Object object) throws HibernateException {
+ return session.save( object );
+ }
+
+ public void saveOrUpdate(String entityName, Object object) throws HibernateException {
+ session.saveOrUpdate( entityName, object );
+ }
+
+ public void saveOrUpdate(Object object) throws HibernateException {
+ session.saveOrUpdate( object );
+ }
+
+ public void setCacheMode(CacheMode cacheMode) {
+ session.setCacheMode( cacheMode );
+ }
+
+ public void setFlushMode(FlushMode flushMode) {
+ session.setFlushMode( flushMode );
+ }
+
+ public void setReadOnly(Object entity, boolean readOnly) {
+ session.setReadOnly( entity, readOnly );
+ }
+
+ public void update(String entityName, Object object) throws HibernateException {
+ session.update( entityName, object );
+ }
+
+ public void update(Object object) throws HibernateException {
+ session.update( object );
+ }
+}
Deleted:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/LuceneSession.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/LuceneSession.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/LuceneSession.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -1,466 +0,0 @@
-//$Id: $
-package org.hibernate.search;
-
-import java.io.Serializable;
-import java.sql.Connection;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.ReentrantLock;
-
-import javax.transaction.Status;
-
-import org.hibernate.CacheMode;
-import org.hibernate.Criteria;
-import org.hibernate.EntityMode;
-import org.hibernate.Filter;
-import org.hibernate.FlushMode;
-import org.hibernate.HibernateException;
-import org.hibernate.LockMode;
-import org.hibernate.Query;
-import org.hibernate.ReplicationMode;
-import org.hibernate.SQLQuery;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.engine.query.ParameterMetadata;
-import org.hibernate.impl.SessionImpl;
-import org.hibernate.search.query.LuceneQueryImpl;
-import org.hibernate.search.event.LuceneEventListener;
-import org.hibernate.search.util.ContextHelper;
-import org.hibernate.search.engine.DocumentBuilder;
-import org.hibernate.search.backend.UpdateWork;
-import org.hibernate.search.backend.Work;
-import org.hibernate.search.backend.WorkQueue;
-import org.hibernate.search.backend.impl.BatchLuceneWorkQueue;
-import org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization;
-import org.hibernate.search.store.DirectoryProvider;
-import org.hibernate.stat.SessionStatistics;
-import org.hibernate.type.Type;
-import org.apache.lucene.document.Document;
-
-/**
- * Lucene aware session that allows lucene query creations
- *
- * @author Emmanuel Bernard
- */
-public class LuceneSession implements Session {
- private final SessionImpl session;
- private PostTransactionWorkQueueSynchronization postTransactionWorkQueueSynch;
-
- public LuceneSession(Session session) {
- this.session = (SessionImpl) session;
- }
-
- /**
- * Execute a Lucene query and retrieve managed objects of type entities (or their
indexed subclasses)
- * If entities is empty, include all indexed entities
- *
- * @param entities must be immutable for the lifetime of the query object
- */
- public Query createLuceneQuery(org.apache.lucene.search.Query luceneQuery, Class...
entities) {
- return new LuceneQueryImpl( luceneQuery, entities, session, new ParameterMetadata(null,
null) );
- }
-
- /**
- * (re)index an entity.
- * Non indexable entities are ignored
- * The entity must be associated with the session
- *
- * @param entity must not be null
- */
- public void index(Object entity) {
- if (entity == null) return;
- Class clazz = entity.getClass();
- LuceneEventListener listener = ContextHelper.getLuceneEventListener( session );
- DocumentBuilder<Object> builder = listener.getDocumentBuilders().get( clazz );
- if ( builder != null ) {
- Serializable id = session.getIdentifier( entity );
- Document doc = builder.getDocument( entity, id );
- UpdateWork work = new UpdateWork( id, entity.getClass(), doc );
- processWork( work, listener.getDocumentBuilders(),
listener.getLockableDirectoryProviders() );
- }
- //TODO
- //need to add elements in a queue kept at the Session level
- //the queue will be processed by a Lucene(Auto)FlushEventListener
- //note that we could keep this queue somewhere in the event listener in the mean time
but that requires
- // a synchronized hashmap holding this queue on a per session basis plus some session
house keeping (yuk)
- //an other solution would be to subclass SessionImpl instead of having this
LuceneSession delecation model
- // this is an open discussion
- }
-
- private void processWork(Work work, Map<Class, DocumentBuilder<Object>>
documentBuilders,
- Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
- if ( session.isTransactionInProgress() ) {
- if ( postTransactionWorkQueueSynch == null ||
postTransactionWorkQueueSynch.isConsumed() ) {
- postTransactionWorkQueueSynch = createWorkQueueSync( documentBuilders,
lockableDirectoryProviders);
- session.getTransaction().registerSynchronization( postTransactionWorkQueueSynch );
- }
- postTransactionWorkQueueSynch.add( work );
- }
- else {
- //no transaction work right away
- PostTransactionWorkQueueSynchronization sync =
- createWorkQueueSync( documentBuilders, lockableDirectoryProviders );
- sync.add( work );
- sync.afterCompletion( Status.STATUS_COMMITTED );
- }
- }
-
- private PostTransactionWorkQueueSynchronization createWorkQueueSync(
- Map<Class, DocumentBuilder<Object>> documentBuilders,
- Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
- WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders,
lockableDirectoryProviders );
- return new PostTransactionWorkQueueSynchronization( workQueue );
- }
-
- public Query createSQLQuery(String sql, String returnAlias, Class returnClass) {
- return session.createSQLQuery( sql, returnAlias, returnClass );
- }
-
- public Query createSQLQuery(String sql, String[] returnAliases, Class[] returnClasses)
{
- return session.createSQLQuery( sql, returnAliases, returnClasses );
- }
-
- public int delete(String query) throws HibernateException {
- return session.delete( query );
- }
-
- public int delete(String query, Object value, Type type) throws HibernateException {
- return session.delete( query, value, type );
- }
-
- public int delete(String query, Object[] values, Type[] types) throws HibernateException
{
- return session.delete( query, values, types );
- }
-
- public Collection filter(Object collection, String filter) throws HibernateException {
- return session.filter( collection, filter );
- }
-
- public Collection filter(Object collection, String filter, Object value, Type type)
throws HibernateException {
- return session.filter( collection, filter, value, type );
- }
-
- public Collection filter(Object collection, String filter, Object[] values, Type[]
types) throws HibernateException {
- return session.filter( collection, filter, values, types );
- }
-
- public List find(String query) throws HibernateException {
- return session.find( query );
- }
-
- public List find(String query, Object value, Type type) throws HibernateException {
- return session.find( query, value, type );
- }
-
- public List find(String query, Object[] values, Type[] types) throws HibernateException
{
- return session.find( query, values, types );
- }
-
- public Iterator iterate(String query) throws HibernateException {
- return session.iterate( query );
- }
-
- public Iterator iterate(String query, Object value, Type type) throws HibernateException
{
- return session.iterate( query, value, type );
- }
-
- public Iterator iterate(String query, Object[] values, Type[] types) throws
HibernateException {
- return session.iterate( query, values, types );
- }
-
- public void save(String entityName, Object object, Serializable id) throws
HibernateException {
- session.save( entityName, object, id );
- }
-
- public void save(Object object, Serializable id) throws HibernateException {
- session.save( object, id );
- }
-
- public Object saveOrUpdateCopy(String entityName, Object object) throws
HibernateException {
- return session.saveOrUpdateCopy( entityName, object );
- }
-
- public Object saveOrUpdateCopy(String entityName, Object object, Serializable id) throws
HibernateException {
- return session.saveOrUpdateCopy( entityName, object, id );
- }
-
- public Object saveOrUpdateCopy(Object object) throws HibernateException {
- return session.saveOrUpdateCopy( object );
- }
-
- public Object saveOrUpdateCopy(Object object, Serializable id) throws HibernateException
{
- return session.saveOrUpdateCopy( object, id );
- }
-
- public void update(String entityName, Object object, Serializable id) throws
HibernateException {
- session.update( entityName, object, id );
- }
-
- public void update(Object object, Serializable id) throws HibernateException {
- session.update( object, id );
- }
-
- public Transaction beginTransaction() throws HibernateException {
- return session.beginTransaction();
- }
-
- public void cancelQuery() throws HibernateException {
- session.cancelQuery();
- }
-
- public void clear() {
- session.clear();
- }
-
- public Connection close() throws HibernateException {
- return session.close();
- }
-
- public Connection connection() throws HibernateException {
- return session.connection();
- }
-
- public boolean contains(Object object) {
- return session.contains( object );
- }
-
- public Criteria createCriteria(String entityName) {
- return session.createCriteria( entityName );
- }
-
- public Criteria createCriteria(String entityName, String alias) {
- return session.createCriteria( entityName, alias );
- }
-
- public Criteria createCriteria(Class persistentClass) {
- return session.createCriteria( persistentClass );
- }
-
- public Criteria createCriteria(Class persistentClass, String alias) {
- return session.createCriteria( persistentClass, alias );
- }
-
- public Query createFilter(Object collection, String queryString) throws
HibernateException {
- return session.createFilter( collection, queryString );
- }
-
- public Query createQuery(String queryString) throws HibernateException {
- return session.createQuery( queryString );
- }
-
- public SQLQuery createSQLQuery(String queryString) throws HibernateException {
- return session.createSQLQuery( queryString );
- }
-
- public void delete(String entityName, Object object) throws HibernateException {
- session.delete( entityName, object );
- }
-
- public void delete(Object object) throws HibernateException {
- session.delete( object );
- }
-
- public void disableFilter(String filterName) {
- session.disableFilter( filterName );
- }
-
- public Connection disconnect() throws HibernateException {
- return session.disconnect();
- }
-
- public Filter enableFilter(String filterName) {
- return session.enableFilter( filterName );
- }
-
- public void evict(Object object) throws HibernateException {
- session.evict( object );
- }
-
- public void flush() throws HibernateException {
- session.flush();
- }
-
- public Object get(Class clazz, Serializable id) throws HibernateException {
- return session.get( clazz, id );
- }
-
- public Object get(Class clazz, Serializable id, LockMode lockMode) throws
HibernateException {
- return session.get( clazz, id, lockMode );
- }
-
- public Object get(String entityName, Serializable id) throws HibernateException {
- return session.get( entityName, id );
- }
-
- public Object get(String entityName, Serializable id, LockMode lockMode) throws
HibernateException {
- return session.get( entityName, id, lockMode );
- }
-
- public CacheMode getCacheMode() {
- return session.getCacheMode();
- }
-
- public LockMode getCurrentLockMode(Object object) throws HibernateException {
- return session.getCurrentLockMode( object );
- }
-
- public Filter getEnabledFilter(String filterName) {
- return session.getEnabledFilter( filterName );
- }
-
- public EntityMode getEntityMode() {
- return session.getEntityMode();
- }
-
- public String getEntityName(Object object) throws HibernateException {
- return session.getEntityName( object );
- }
-
- public FlushMode getFlushMode() {
- return session.getFlushMode();
- }
-
- public Serializable getIdentifier(Object object) throws HibernateException {
- return session.getIdentifier( object );
- }
-
- public Query getNamedQuery(String queryName) throws HibernateException {
- return session.getNamedQuery( queryName );
- }
-
- public org.hibernate.Session getSession(EntityMode entityMode) {
- return session.getSession( entityMode );
- }
-
- public SessionFactory getSessionFactory() {
- return session.getSessionFactory();
- }
-
- public SessionStatistics getStatistics() {
- return session.getStatistics();
- }
-
- public Transaction getTransaction() {
- return session.getTransaction();
- }
-
- public boolean isConnected() {
- return session.isConnected();
- }
-
- public boolean isDirty() throws HibernateException {
- return session.isDirty();
- }
-
- public boolean isOpen() {
- return session.isOpen();
- }
-
- public Object load(String entityName, Serializable id) throws HibernateException {
- return session.load( entityName, id );
- }
-
- public Object load(String entityName, Serializable id, LockMode lockMode) throws
HibernateException {
- return session.load( entityName, id, lockMode );
- }
-
- public void load(Object object, Serializable id) throws HibernateException {
- session.load( object, id );
- }
-
- public Object load(Class theClass, Serializable id) throws HibernateException {
- return session.load( theClass, id );
- }
-
- public Object load(Class theClass, Serializable id, LockMode lockMode) throws
HibernateException {
- return session.load( theClass, id, lockMode );
- }
-
- public void lock(String entityName, Object object, LockMode lockMode) throws
HibernateException {
- session.lock( entityName, object, lockMode );
- }
-
- public void lock(Object object, LockMode lockMode) throws HibernateException {
- session.lock( object, lockMode );
- }
-
- public Object merge(String entityName, Object object) throws HibernateException {
- return session.merge( entityName, object );
- }
-
- public Object merge(Object object) throws HibernateException {
- return session.merge( object );
- }
-
- public void persist(String entityName, Object object) throws HibernateException {
- session.persist( entityName, object );
- }
-
- public void persist(Object object) throws HibernateException {
- session.persist( object );
- }
-
- public void reconnect() throws HibernateException {
- session.reconnect();
- }
-
- public void reconnect(Connection connection) throws HibernateException {
- session.reconnect( connection );
- }
-
- public void refresh(Object object) throws HibernateException {
- session.refresh( object );
- }
-
- public void refresh(Object object, LockMode lockMode) throws HibernateException {
- session.refresh( object, lockMode );
- }
-
- public void replicate(String entityName, Object object, ReplicationMode replicationMode)
throws HibernateException {
- session.replicate( entityName, object, replicationMode );
- }
-
- public void replicate(Object object, ReplicationMode replicationMode) throws
HibernateException {
- session.replicate( object, replicationMode );
- }
-
- public Serializable save(String entityName, Object object) throws HibernateException {
- return session.save( entityName, object );
- }
-
- public Serializable save(Object object) throws HibernateException {
- return session.save( object );
- }
-
- public void saveOrUpdate(String entityName, Object object) throws HibernateException {
- session.saveOrUpdate( entityName, object );
- }
-
- public void saveOrUpdate(Object object) throws HibernateException {
- session.saveOrUpdate( object );
- }
-
- public void setCacheMode(CacheMode cacheMode) {
- session.setCacheMode( cacheMode );
- }
-
- public void setFlushMode(FlushMode flushMode) {
- session.setFlushMode( flushMode );
- }
-
- public void setReadOnly(Object entity, boolean readOnly) {
- session.setReadOnly( entity, readOnly );
- }
-
- public void update(String entityName, Object object) throws HibernateException {
- session.update( entityName, object );
- }
-
- public void update(Object object) throws HibernateException {
- session.update( object );
- }
-}
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -26,7 +26,7 @@
import org.hibernate.search.bridge.BridgeFactory;
import org.hibernate.search.bridge.FieldBridge;
import org.hibernate.search.bridge.IdFieldBridge;
-import org.hibernate.search.event.LuceneEventListener;
+import org.hibernate.search.event.FullTextEventListener;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.util.BinderHelper;
import org.hibernate.reflection.ReflectionManager;
@@ -305,7 +305,7 @@
}
}
- public static Serializable getDocumentId(LuceneEventListener listener, Class clazz,
Document document) {
+ public static Serializable getDocumentId(FullTextEventListener listener, Class clazz,
Document document) {
DocumentBuilder builder = listener.getDocumentBuilders().get( clazz );
if ( builder == null ) throw new HibernateException( "No Lucene configuration set
up for: " + clazz.getName() );
return (Serializable) builder.getIdBridge().get( builder.getIdKeywordName(), document
);
Copied:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextEventListener.java
(from rev 10742,
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/LuceneEventListener.java)
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/LuceneEventListener.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextEventListener.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -0,0 +1,180 @@
+//$Id$
+package org.hibernate.search.event;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.ReentrantLock;
+import javax.transaction.Status;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.event.AbstractEvent;
+import org.hibernate.event.Initializable;
+import org.hibernate.event.PostDeleteEvent;
+import org.hibernate.event.PostDeleteEventListener;
+import org.hibernate.event.PostInsertEvent;
+import org.hibernate.event.PostInsertEventListener;
+import org.hibernate.event.PostUpdateEvent;
+import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.search.Environment;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.backend.AddWork;
+import org.hibernate.search.backend.DeleteWork;
+import org.hibernate.search.backend.UpdateWork;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkQueue;
+import org.hibernate.search.backend.impl.BatchLuceneWorkQueue;
+import org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.store.DirectoryProviderFactory;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.reflection.ReflectionManager;
+import org.hibernate.reflection.XClass;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * This listener supports setting a parent directory for all generated index files.
+ * It also supports setting the analyzer class to be used.
+ *
+ * @author Gavin King
+ * @author Emmanuel Bernard
+ * @author Mattias Arbin
+ */
+//TODO work on sharing the same indexWriters and readers across a single post
operation...
+//TODO implement and use a LockableDirectoryProvider that wraps a DP to handle the lock
inside the LDP
+public class FullTextEventListener implements PostDeleteEventListener,
PostInsertEventListener,
+ PostUpdateEventListener, Initializable {
+ ReflectionManager reflectionManager;
+
+ //FIXME keeping this here is a bad decision since you might want to search indexes wo
maintain it
+ @Deprecated
+ public Map<Class, DocumentBuilder<Object>> getDocumentBuilders() {
+ return documentBuilders;
+ }
+
+
+ private Map<Class, DocumentBuilder<Object>> documentBuilders = new
HashMap<Class, DocumentBuilder<Object>>();
+ //keep track of the index modifiers per DirectoryProvider since multiple entity can use
the same directory provider
+ private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders =
+ new HashMap<DirectoryProvider, ReentrantLock>();
+ private boolean initialized;
+
+ private static final Log log = LogFactory.getLog( FullTextEventListener.class );
+
+ public void initialize(Configuration cfg) {
+ if ( initialized ) return;
+ //yuk
+ reflectionManager = ( (AnnotationConfiguration) cfg
).createExtendedMappings().getReflectionManager();
+
+ Class analyzerClass;
+ String analyzerClassName = cfg.getProperty( Environment.ANALYZER_CLASS );
+ if ( analyzerClassName != null ) {
+ try {
+ analyzerClass = ReflectHelper.classForName( analyzerClassName );
+ }
+ catch (Exception e) {
+ throw new HibernateException(
+ "Lucene analyzer class '" + analyzerClassName + "' defined
in property '" + Environment.ANALYZER_CLASS + "' could not be
found.",
+ e
+ );
+ }
+ }
+ else {
+ analyzerClass = StandardAnalyzer.class;
+ }
+ // Initialize analyzer
+ Analyzer analyzer;
+ try {
+ analyzer = (Analyzer) analyzerClass.newInstance();
+ }
+ catch (ClassCastException e) {
+ throw new HibernateException(
+ "Lucene analyzer does not implement " + Analyzer.class.getName() + ":
" + analyzerClassName
+ );
+ }
+ catch (Exception e) {
+ throw new HibernateException( "Failed to instantiate lucene analyzer with type
" + analyzerClassName );
+ }
+
+ Iterator iter = cfg.getClassMappings();
+ DirectoryProviderFactory factory = new DirectoryProviderFactory();
+ while ( iter.hasNext() ) {
+ PersistentClass clazz = (PersistentClass) iter.next();
+ Class<?> mappedClass = clazz.getMappedClass();
+ if ( mappedClass != null ) {
+ XClass mappedXClass = reflectionManager.toXClass( mappedClass );
+ if ( mappedXClass != null && mappedXClass.isAnnotationPresent( Indexed.class
) ) {
+ DirectoryProvider provider = factory.createDirectoryProvider( mappedXClass, cfg );
+ if ( !lockableDirectoryProviders.containsKey( provider ) ) {
+ lockableDirectoryProviders.put( provider, new ReentrantLock() );
+ }
+ final DocumentBuilder<Object> documentBuilder = new
DocumentBuilder<Object>(
+ mappedXClass, analyzer, provider, reflectionManager
+ );
+
+ documentBuilders.put( mappedClass, documentBuilder );
+ }
+ }
+ }
+ Set<Class> indexedClasses = documentBuilders.keySet();
+ for ( DocumentBuilder builder : documentBuilders.values() ) {
+ builder.postInitialize( indexedClasses );
+ }
+ initialized = true;
+ }
+
+ public void onPostDelete(PostDeleteEvent event) {
+ if ( documentBuilders.containsKey( event.getEntity().getClass() ) ) {
+ DeleteWork work = new DeleteWork( event.getId(), event.getEntity().getClass() );
+ processWork( work, event );
+ }
+ }
+
+ public void onPostInsert(PostInsertEvent event) {
+ final Object entity = event.getEntity();
+ DocumentBuilder<Object> builder = documentBuilders.get( entity.getClass() );
+ if ( builder != null ) {
+ Serializable id = event.getId();
+ Document doc = builder.getDocument( entity, id );
+ AddWork work = new AddWork( id, entity.getClass(), doc );
+ processWork( work, event );
+ }
+ }
+
+ public void onPostUpdate(PostUpdateEvent event) {
+ final Object entity = event.getEntity();
+ DocumentBuilder<Object> builder = documentBuilders.get( entity.getClass() );
+ if ( builder != null ) {
+ Serializable id = event.getId();
+ Document doc = builder.getDocument( entity, id );
+ UpdateWork work = new UpdateWork( id, entity.getClass(), doc );
+ processWork( work, event );
+ }
+ }
+
+ private void processWork(Work work, AbstractEvent event) {
+ WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders,
lockableDirectoryProviders );
+ workQueue.add( work );
+ PostTransactionWorkQueueSynchronization sync = new
PostTransactionWorkQueueSynchronization( workQueue );
+ if ( event.getSession().isTransactionInProgress() ) {
+ event.getSession().getTransaction().registerSynchronization( sync );
+ }
+ else {
+ sync.afterCompletion( Status.STATUS_COMMITTED );
+ }
+ }
+
+ public Map<DirectoryProvider, ReentrantLock> getLockableDirectoryProviders() {
+ return lockableDirectoryProviders;
+ }
+}
Property changes on:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/FullTextEventListener.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Deleted:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/LuceneEventListener.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/LuceneEventListener.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/event/LuceneEventListener.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -1,180 +0,0 @@
-//$Id$
-package org.hibernate.search.event;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.ReentrantLock;
-import javax.transaction.Status;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.hibernate.HibernateException;
-import org.hibernate.cfg.AnnotationConfiguration;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.event.AbstractEvent;
-import org.hibernate.event.Initializable;
-import org.hibernate.event.PostDeleteEvent;
-import org.hibernate.event.PostDeleteEventListener;
-import org.hibernate.event.PostInsertEvent;
-import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.event.PostUpdateEvent;
-import org.hibernate.event.PostUpdateEventListener;
-import org.hibernate.search.Environment;
-import org.hibernate.search.annotations.Indexed;
-import org.hibernate.search.backend.AddWork;
-import org.hibernate.search.backend.DeleteWork;
-import org.hibernate.search.backend.UpdateWork;
-import org.hibernate.search.backend.Work;
-import org.hibernate.search.backend.WorkQueue;
-import org.hibernate.search.backend.impl.BatchLuceneWorkQueue;
-import org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization;
-import org.hibernate.search.engine.DocumentBuilder;
-import org.hibernate.search.store.DirectoryProvider;
-import org.hibernate.search.store.DirectoryProviderFactory;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.reflection.ReflectionManager;
-import org.hibernate.reflection.XClass;
-import org.hibernate.util.ReflectHelper;
-
-/**
- * This listener supports setting a parent directory for all generated index files.
- * It also supports setting the analyzer class to be used.
- *
- * @author Gavin King
- * @author Emmanuel Bernard
- * @author Mattias Arbin
- */
-//TODO work on sharing the same indexWriters and readers across a single post
operation...
-//TODO implement and use a LockableDirectoryProvider that wraps a DP to handle the lock
inside the LDP
-public class LuceneEventListener implements PostDeleteEventListener,
PostInsertEventListener,
- PostUpdateEventListener, Initializable {
- ReflectionManager reflectionManager;
-
- //FIXME keeping this here is a bad decision since you might want to search indexes wo
maintain it
- @Deprecated
- public Map<Class, DocumentBuilder<Object>> getDocumentBuilders() {
- return documentBuilders;
- }
-
-
- private Map<Class, DocumentBuilder<Object>> documentBuilders = new
HashMap<Class, DocumentBuilder<Object>>();
- //keep track of the index modifiers per DirectoryProvider since multiple entity can use
the same directory provider
- private Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders =
- new HashMap<DirectoryProvider, ReentrantLock>();
- private boolean initialized;
-
- private static final Log log = LogFactory.getLog( LuceneEventListener.class );
-
- public void initialize(Configuration cfg) {
- if ( initialized ) return;
- //yuk
- reflectionManager = ( (AnnotationConfiguration) cfg
).createExtendedMappings().getReflectionManager();
-
- Class analyzerClass;
- String analyzerClassName = cfg.getProperty( Environment.ANALYZER_CLASS );
- if ( analyzerClassName != null ) {
- try {
- analyzerClass = ReflectHelper.classForName( analyzerClassName );
- }
- catch (Exception e) {
- throw new HibernateException(
- "Lucene analyzer class '" + analyzerClassName + "' defined
in property '" + Environment.ANALYZER_CLASS + "' could not be
found.",
- e
- );
- }
- }
- else {
- analyzerClass = StandardAnalyzer.class;
- }
- // Initialize analyzer
- Analyzer analyzer;
- try {
- analyzer = (Analyzer) analyzerClass.newInstance();
- }
- catch (ClassCastException e) {
- throw new HibernateException(
- "Lucene analyzer does not implement " + Analyzer.class.getName() + ":
" + analyzerClassName
- );
- }
- catch (Exception e) {
- throw new HibernateException( "Failed to instantiate lucene analyzer with type
" + analyzerClassName );
- }
-
- Iterator iter = cfg.getClassMappings();
- DirectoryProviderFactory factory = new DirectoryProviderFactory();
- while ( iter.hasNext() ) {
- PersistentClass clazz = (PersistentClass) iter.next();
- Class<?> mappedClass = clazz.getMappedClass();
- if ( mappedClass != null ) {
- XClass mappedXClass = reflectionManager.toXClass( mappedClass );
- if ( mappedXClass != null && mappedXClass.isAnnotationPresent( Indexed.class
) ) {
- DirectoryProvider provider = factory.createDirectoryProvider( mappedXClass, cfg );
- if ( !lockableDirectoryProviders.containsKey( provider ) ) {
- lockableDirectoryProviders.put( provider, new ReentrantLock() );
- }
- final DocumentBuilder<Object> documentBuilder = new
DocumentBuilder<Object>(
- mappedXClass, analyzer, provider, reflectionManager
- );
-
- documentBuilders.put( mappedClass, documentBuilder );
- }
- }
- }
- Set<Class> indexedClasses = documentBuilders.keySet();
- for ( DocumentBuilder builder : documentBuilders.values() ) {
- builder.postInitialize( indexedClasses );
- }
- initialized = true;
- }
-
- public void onPostDelete(PostDeleteEvent event) {
- if ( documentBuilders.containsKey( event.getEntity().getClass() ) ) {
- DeleteWork work = new DeleteWork( event.getId(), event.getEntity().getClass() );
- processWork( work, event );
- }
- }
-
- public void onPostInsert(PostInsertEvent event) {
- final Object entity = event.getEntity();
- DocumentBuilder<Object> builder = documentBuilders.get( entity.getClass() );
- if ( builder != null ) {
- Serializable id = event.getId();
- Document doc = builder.getDocument( entity, id );
- AddWork work = new AddWork( id, entity.getClass(), doc );
- processWork( work, event );
- }
- }
-
- public void onPostUpdate(PostUpdateEvent event) {
- final Object entity = event.getEntity();
- DocumentBuilder<Object> builder = documentBuilders.get( entity.getClass() );
- if ( builder != null ) {
- Serializable id = event.getId();
- Document doc = builder.getDocument( entity, id );
- UpdateWork work = new UpdateWork( id, entity.getClass(), doc );
- processWork( work, event );
- }
- }
-
- private void processWork(Work work, AbstractEvent event) {
- WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders,
lockableDirectoryProviders );
- workQueue.add( work );
- PostTransactionWorkQueueSynchronization sync = new
PostTransactionWorkQueueSynchronization( workQueue );
- if ( event.getSession().isTransactionInProgress() ) {
- event.getSession().getTransaction().registerSynchronization( sync );
- }
- else {
- sync.afterCompletion( Status.STATUS_COMMITTED );
- }
- }
-
- public Map<DirectoryProvider, ReentrantLock> getLockableDirectoryProviders() {
- return lockableDirectoryProviders;
- }
-}
Copied:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/FullTextQueryImpl.java
(from rev 10742,
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/LuceneQueryImpl.java)
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/LuceneQueryImpl.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -0,0 +1,296 @@
+//$Id: $
+package org.hibernate.search.query;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MultiSearcher;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.Directory;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.LockMode;
+import org.hibernate.Query;
+import org.hibernate.ScrollMode;
+import org.hibernate.ScrollableResults;
+import org.hibernate.Session;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.query.ParameterMetadata;
+import org.hibernate.impl.AbstractQueryImpl;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.event.FullTextEventListener;
+import org.hibernate.search.util.ContextHelper;
+
+/**
+ * @author Emmanuel Bernard
+ */
+//TODO implements setParameter()
+public class FullTextQueryImpl extends AbstractQueryImpl {
+ private static final Log log = LogFactory.getLog( FullTextQueryImpl.class );
+ private org.apache.lucene.search.Query luceneQuery;
+ private Class[] classes;
+ private Set<Class> classesAndSubclasses;
+ private Integer firstResult;
+ private Integer maxResults;
+ private int resultSize;
+
+ /**
+ * classes must be immutable
+ */
+ public FullTextQueryImpl(org.apache.lucene.search.Query query, Class[] classes,
SessionImplementor session,
+ ParameterMetadata parameterMetadata) {
+ //TODO handle flushMode
+ super( query.toString(), null, session, parameterMetadata );
+ this.luceneQuery = query;
+ this.classes = classes;
+ }
+
+ /**
+ * Return an interator on the results.
+ * Retrieve the object one by one (initialize it during the next() operation)
+ */
+ public Iterator iterate() throws HibernateException {
+ //implement an interator which keep the id/class for each hit and get the object on
demand
+ //cause I can't keep the searcher and hence the hit opened. I dont have any hook to
know when the
+ //user stop using it
+ //scrollable is better in this area
+
+ FullTextEventListener listener = ContextHelper.getLuceneEventListener( session );
+ //find the directories
+ Searcher searcher = buildSearcher( listener );
+ try {
+ org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
+ Hits hits = searcher.search( query );
+ setResultSize( hits );
+ int first = first();
+ int max = max( first, hits );
+ List<EntityInfo> entityInfos = new ArrayList<EntityInfo>( max - first + 1
);
+ for ( int index = first; index <= max; index++ ) {
+ Document document = hits.doc( index );
+ EntityInfo entityInfo = new EntityInfo();
+ entityInfo.clazz = DocumentBuilder.getDocumentClass( document );
+ entityInfo.id = DocumentBuilder.getDocumentId( listener, entityInfo.clazz, document
);
+ entityInfos.add( entityInfo );
+ }
+ return new IteratorImpl( entityInfos, (Session) this.session );
+ }
+ catch (IOException e) {
+ throw new HibernateException( "Unable to query Lucene index", e );
+ }
+ finally {
+ if ( searcher != null ) try {
+ searcher.close();
+ }
+ catch (IOException e) {
+ log.warn( "Unable to properly close searcher during lucene query: " +
getQueryString(), e );
+ }
+ }
+ }
+
+ public ScrollableResults scroll() throws HibernateException {
+ //keep the searcher open until the resultset is closed
+ FullTextEventListener listener = ContextHelper.getLuceneEventListener( session );;
+ //find the directories
+ Searcher searcher = buildSearcher( listener );
+ Hits hits;
+ try {
+ org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
+ hits = searcher.search( query );
+ setResultSize( hits );
+ int first = first();
+ int max = max( first, hits );
+ return new ScrollableResultsImpl( searcher, hits, first, max, (Session) this.session,
listener );
+ }
+ catch (IOException e) {
+ try {
+ if ( searcher != null ) searcher.close();
+ }
+ catch (IOException ee) {
+ //we have the initial issue already
+ }
+ throw new HibernateException( "Unable to query Lucene index", e );
+ }
+ }
+
+ public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException {
+ //TODO think about this scrollmode
+ return scroll();
+ }
+
+ public List list() throws HibernateException {
+ FullTextEventListener listener = ContextHelper.getLuceneEventListener( session );;
+ //find the directories
+ Searcher searcher = buildSearcher( listener );
+ Hits hits;
+ try {
+ org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
+ hits = searcher.search( query );
+ setResultSize( hits );
+ int first = first();
+ int max = max( first, hits );
+ List result = new ArrayList( max - first + 1 );
+ Session sess = (Session) this.session;
+ for ( int index = first; index <= max; index++ ) {
+ Document document = hits.doc( index );
+ Class clazz = DocumentBuilder.getDocumentClass( document );
+ Serializable id = DocumentBuilder.getDocumentId( listener, clazz, document );
+ result.add( sess.load( clazz, id ) );
+ //use load to benefit from the batch-size
+ //we don't face proxy casting issues since the exact class is extracted from the
index
+ }
+ //then initialize the objects
+ for ( Object element : result ) {
+ Hibernate.initialize( element );
+ }
+ return result;
+ }
+ catch (IOException e) {
+ throw new HibernateException( "Unable to query Lucene index", e );
+ }
+ finally {
+ if ( searcher != null ) try {
+ searcher.close();
+ }
+ catch (IOException e) {
+ log.warn( "Unable to properly close searcher during lucene query: " +
getQueryString(), e );
+ }
+ }
+ }
+
+ private org.apache.lucene.search.Query
filterQueryByClasses(org.apache.lucene.search.Query luceneQuery) {
+ //A query filter is more practical than a manual class filtering post query (esp on
scrollable resultsets)
+ //it also probably minimise the memory footprint
+ if ( classesAndSubclasses == null ) {
+ return luceneQuery;
+ }
+ else {
+ BooleanQuery classFilter = new BooleanQuery();
+ //annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
+ classFilter.setBoost( 0 );
+ for ( Class clazz : classesAndSubclasses ) {
+ Term t = new Term( DocumentBuilder.CLASS_FIELDNAME, clazz.getName() );
+ TermQuery termQuery = new TermQuery( t );
+ classFilter.add( termQuery, BooleanClause.Occur.SHOULD );
+ }
+ BooleanQuery filteredQuery = new BooleanQuery();
+ filteredQuery.add( luceneQuery, BooleanClause.Occur.MUST );
+ filteredQuery.add( classFilter, BooleanClause.Occur.MUST );
+ return filteredQuery;
+ }
+ }
+
+ private int max(int first, Hits hits) {
+ return maxResults == null ?
+ hits.length() - 1 :
+ maxResults + first < hits.length() ?
+ first + maxResults - 1 :
+ hits.length() - 1;
+ }
+
+ private int first() {
+ return firstResult != null ?
+ firstResult :
+ 0;
+ }
+
+ //TODO change classesAndSubclasses by side effect, which is a mismatch with the Searcher
return, fix that.
+ private Searcher buildSearcher(FullTextEventListener listener) {
+ Map<Class, DocumentBuilder<Object>> builders =
listener.getDocumentBuilders();
+ Set<Directory> directories = new HashSet<Directory>();
+ if ( classes == null || classes.length == 0 ) {
+ //no class means all classes
+ for ( DocumentBuilder builder : builders.values() ) {
+ directories.add( builder.getDirectoryProvider().getDirectory() );
+ }
+ classesAndSubclasses = null;
+ }
+ else {
+ Set<Class> involvedClasses = new HashSet<Class>( classes.length );
+ Collections.addAll( involvedClasses, classes );
+ for ( Class clazz : classes ) {
+ DocumentBuilder builder = builders.get( clazz );
+ if ( builder != null ) involvedClasses.addAll( builder.getMappedSubclasses() );
+ }
+ for ( Class clazz : involvedClasses ) {
+ DocumentBuilder builder = builders.get( clazz );
+ //TODO should we rather choose a polymorphic path and allow non mapped entities
+ if ( builder == null ) throw new HibernateException( "Not a mapped entity:
" + clazz );
+ directories.add( builder.getDirectoryProvider().getDirectory() );
+ }
+ classesAndSubclasses = involvedClasses;
+ }
+
+ //set up the searcher
+ Searcher searcher;
+ int dirNbr = directories.size();
+ if ( dirNbr > 1 ) {
+ try {
+ IndexSearcher[] searchers = new IndexSearcher[dirNbr];
+ Iterator<Directory> it = directories.iterator();
+ for ( int index = 0; index < dirNbr; index++ ) {
+ searchers[index] = new IndexSearcher( it.next() );
+ }
+ searcher = new MultiSearcher( searchers );
+ }
+ catch (IOException e) {
+ throw new HibernateException( "Unable to read Lucene directory", e );
+ }
+ }
+ else {
+ try {
+ searcher = new IndexSearcher( directories.iterator().next() );
+ }
+ catch (IOException e) {
+ throw new HibernateException( "Unable to read Lucene directory", e );
+ }
+ }
+ return searcher;
+ }
+
+ private void setResultSize(Hits hits) {
+ resultSize = hits.length();
+ }
+
+ //FIXME does it make sense
+ public int resultSize() {
+ return this.resultSize;
+ }
+
+ public Query setFirstResult(int firstResult) {
+ this.firstResult = firstResult;
+ return this;
+ }
+
+ public Query setMaxResults(int maxResults) {
+ this.maxResults = maxResults;
+ return this;
+ }
+
+ public int executeUpdate() throws HibernateException {
+ throw new HibernateException( "Not supported operation" );
+ }
+
+ public Query setLockMode(String alias, LockMode lockMode) {
+ return null;
+ }
+
+ protected Map getLockModes() {
+ return null;
+ }
+}
Deleted:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/LuceneQueryImpl.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/LuceneQueryImpl.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/LuceneQueryImpl.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -1,297 +0,0 @@
-//$Id: $
-package org.hibernate.search.query;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.MultiSearcher;
-import org.apache.lucene.search.Searcher;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.store.Directory;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.LockMode;
-import org.hibernate.Query;
-import org.hibernate.ScrollMode;
-import org.hibernate.ScrollableResults;
-import org.hibernate.Session;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.query.ParameterMetadata;
-import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.impl.AbstractQueryImpl;
-import org.hibernate.search.engine.DocumentBuilder;
-import org.hibernate.search.event.LuceneEventListener;
-import org.hibernate.search.util.ContextHelper;
-
-/**
- * @author Emmanuel Bernard
- */
-//implements setParameter()
-public class LuceneQueryImpl extends AbstractQueryImpl {
- private static final Log log = LogFactory.getLog( LuceneQueryImpl.class );
- private org.apache.lucene.search.Query luceneQuery;
- private Class[] classes;
- private Set<Class> classesAndSubclasses;
- private Integer firstResult;
- private Integer maxResults;
- private int resultSize;
-
- /**
- * classes must be immutable
- */
- public LuceneQueryImpl(org.apache.lucene.search.Query query, Class[] classes,
SessionImplementor session,
- ParameterMetadata parameterMetadata) {
- //TODO handle flushMode
- super( query.toString(), null, session, parameterMetadata );
- this.luceneQuery = query;
- this.classes = classes;
- }
-
- /**
- * Return an interator on the results.
- * Retrieve the object one by one (initialize it during the next() operation)
- */
- public Iterator iterate() throws HibernateException {
- //implement an interator which keep the id/class for each hit and get the object on
demand
- //cause I can't keep the searcher and hence the hit opened. I dont have any hook to
know when the
- //user stop using it
- //scrollable is better in this area
-
- LuceneEventListener listener = ContextHelper.getLuceneEventListener( session );
- //find the directories
- Searcher searcher = buildSearcher( listener );
- try {
- org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
- Hits hits = searcher.search( query );
- setResultSize( hits );
- int first = first();
- int max = max( first, hits );
- List<EntityInfo> entityInfos = new ArrayList<EntityInfo>( max - first + 1
);
- for ( int index = first; index <= max; index++ ) {
- Document document = hits.doc( index );
- EntityInfo entityInfo = new EntityInfo();
- entityInfo.clazz = DocumentBuilder.getDocumentClass( document );
- entityInfo.id = DocumentBuilder.getDocumentId( listener, entityInfo.clazz, document
);
- entityInfos.add( entityInfo );
- }
- return new IteratorImpl( entityInfos, (Session) this.session );
- }
- catch (IOException e) {
- throw new HibernateException( "Unable to query Lucene index", e );
- }
- finally {
- if ( searcher != null ) try {
- searcher.close();
- }
- catch (IOException e) {
- log.warn( "Unable to properly close searcher during lucene query: " +
getQueryString(), e );
- }
- }
- }
-
- public ScrollableResults scroll() throws HibernateException {
- //keep the searcher open until the resultset is closed
- LuceneEventListener listener = ContextHelper.getLuceneEventListener( session );;
- //find the directories
- Searcher searcher = buildSearcher( listener );
- Hits hits;
- try {
- org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
- hits = searcher.search( query );
- setResultSize( hits );
- int first = first();
- int max = max( first, hits );
- return new ScrollableResultsImpl( searcher, hits, first, max, (Session) this.session,
listener );
- }
- catch (IOException e) {
- try {
- if ( searcher != null ) searcher.close();
- }
- catch (IOException ee) {
- //we have the initial issue already
- }
- throw new HibernateException( "Unable to query Lucene index", e );
- }
- }
-
- public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException {
- //TODO think about this scrollmode
- return scroll();
- }
-
- public List list() throws HibernateException {
- LuceneEventListener listener = ContextHelper.getLuceneEventListener( session );;
- //find the directories
- Searcher searcher = buildSearcher( listener );
- Hits hits;
- try {
- org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
- hits = searcher.search( query );
- setResultSize( hits );
- int first = first();
- int max = max( first, hits );
- List result = new ArrayList( max - first + 1 );
- Session sess = (Session) this.session;
- for ( int index = first; index <= max; index++ ) {
- Document document = hits.doc( index );
- Class clazz = DocumentBuilder.getDocumentClass( document );
- Serializable id = DocumentBuilder.getDocumentId( listener, clazz, document );
- result.add( sess.load( clazz, id ) );
- //use load to benefit from the batch-size
- //we don't face proxy casting issues since the exact class is extracted from the
index
- }
- //then initialize the objects
- for ( Object element : result ) {
- Hibernate.initialize( element );
- }
- return result;
- }
- catch (IOException e) {
- throw new HibernateException( "Unable to query Lucene index", e );
- }
- finally {
- if ( searcher != null ) try {
- searcher.close();
- }
- catch (IOException e) {
- log.warn( "Unable to properly close searcher during lucene query: " +
getQueryString(), e );
- }
- }
- }
-
- private org.apache.lucene.search.Query
filterQueryByClasses(org.apache.lucene.search.Query luceneQuery) {
- //A query filter is more practical than a manual class filtering post query (esp on
scrollable resultsets)
- //it also probably minimise the memory footprint
- if ( classesAndSubclasses == null ) {
- return luceneQuery;
- }
- else {
- BooleanQuery classFilter = new BooleanQuery();
- //annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
- classFilter.setBoost( 0 );
- for ( Class clazz : classesAndSubclasses ) {
- Term t = new Term( DocumentBuilder.CLASS_FIELDNAME, clazz.getName() );
- TermQuery termQuery = new TermQuery( t );
- classFilter.add( termQuery, BooleanClause.Occur.SHOULD );
- }
- BooleanQuery filteredQuery = new BooleanQuery();
- filteredQuery.add( luceneQuery, BooleanClause.Occur.MUST );
- filteredQuery.add( classFilter, BooleanClause.Occur.MUST );
- return filteredQuery;
- }
- }
-
- private int max(int first, Hits hits) {
- return maxResults == null ?
- hits.length() - 1 :
- maxResults + first < hits.length() ?
- first + maxResults - 1 :
- hits.length() - 1;
- }
-
- private int first() {
- return firstResult != null ?
- firstResult :
- 0;
- }
-
- //TODO change classesAndSubclasses by side effect, which is a mismatch with the Searcher
return, fix that.
- private Searcher buildSearcher(LuceneEventListener listener) {
- Map<Class, DocumentBuilder<Object>> builders =
listener.getDocumentBuilders();
- Set<Directory> directories = new HashSet<Directory>();
- if ( classes == null || classes.length == 0 ) {
- //no class means all classes
- for ( DocumentBuilder builder : builders.values() ) {
- directories.add( builder.getDirectoryProvider().getDirectory() );
- }
- classesAndSubclasses = null;
- }
- else {
- Set<Class> involvedClasses = new HashSet<Class>( classes.length );
- Collections.addAll( involvedClasses, classes );
- for ( Class clazz : classes ) {
- DocumentBuilder builder = builders.get( clazz );
- if ( builder != null ) involvedClasses.addAll( builder.getMappedSubclasses() );
- }
- for ( Class clazz : involvedClasses ) {
- DocumentBuilder builder = builders.get( clazz );
- //TODO should we rather choose a polymorphic path and allow non mapped entities
- if ( builder == null ) throw new HibernateException( "Not a mapped entity:
" + clazz );
- directories.add( builder.getDirectoryProvider().getDirectory() );
- }
- classesAndSubclasses = involvedClasses;
- }
-
- //set up the searcher
- Searcher searcher;
- int dirNbr = directories.size();
- if ( dirNbr > 1 ) {
- try {
- IndexSearcher[] searchers = new IndexSearcher[dirNbr];
- Iterator<Directory> it = directories.iterator();
- for ( int index = 0; index < dirNbr; index++ ) {
- searchers[index] = new IndexSearcher( it.next() );
- }
- searcher = new MultiSearcher( searchers );
- }
- catch (IOException e) {
- throw new HibernateException( "Unable to read Lucene directory", e );
- }
- }
- else {
- try {
- searcher = new IndexSearcher( directories.iterator().next() );
- }
- catch (IOException e) {
- throw new HibernateException( "Unable to read Lucene directory", e );
- }
- }
- return searcher;
- }
-
- private void setResultSize(Hits hits) {
- resultSize = hits.length();
- }
-
- //FIXME does it make sense
- public int resultSize() {
- return this.resultSize;
- }
-
- public Query setFirstResult(int firstResult) {
- this.firstResult = firstResult;
- return this;
- }
-
- public Query setMaxResults(int maxResults) {
- this.maxResults = maxResults;
- return this;
- }
-
- public int executeUpdate() throws HibernateException {
- throw new HibernateException( "Not supported operation" );
- }
-
- public Query setLockMode(String alias, LockMode lockMode) {
- return null;
- }
-
- protected Map getLockModes() {
- return null;
- }
-}
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/ScrollableResultsImpl.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/ScrollableResultsImpl.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/query/ScrollableResultsImpl.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -18,7 +18,7 @@
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.search.engine.DocumentBuilder;
-import org.hibernate.search.event.LuceneEventListener;
+import org.hibernate.search.event.FullTextEventListener;
import org.hibernate.type.Type;
/**
@@ -31,11 +31,11 @@
private final int max;
private int current;
private final Session session;
- private final LuceneEventListener listener;
+ private final FullTextEventListener listener;
private EntityInfo[] entityInfos;
public ScrollableResultsImpl(
- Searcher searcher, Hits hits, int first, int max, Session session, LuceneEventListener
listener
+ Searcher searcher, Hits hits, int first, int max, Session session,
FullTextEventListener listener
) {
this.searcher = searcher;
this.hits = hits;
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/util/ContextHelper.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/util/ContextHelper.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/util/ContextHelper.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -4,20 +4,20 @@
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.search.event.LuceneEventListener;
+import org.hibernate.search.event.FullTextEventListener;
/**
* @author Emmanuel Bernard
*/
public abstract class ContextHelper {
- public static LuceneEventListener getLuceneEventListener(SessionImplementor session) {
+ public static FullTextEventListener getLuceneEventListener(SessionImplementor session)
{
PostInsertEventListener[] listeners =
session.getListeners().getPostInsertEventListeners();
- LuceneEventListener listener = null;
+ FullTextEventListener listener = null;
//FIXME this sucks since we mandante the event listener use
for ( PostInsertEventListener candidate : listeners ) {
- if ( candidate instanceof LuceneEventListener ) {
- listener = (LuceneEventListener) candidate;
+ if ( candidate instanceof FullTextEventListener ) {
+ listener = (FullTextEventListener) candidate;
break;
}
}
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/FSDirectoryTest.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -19,7 +19,7 @@
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.search.Environment;
import org.hibernate.search.store.FSDirectoryProvider;
-import org.hibernate.search.event.LuceneEventListener;
+import org.hibernate.search.event.FullTextEventListener;
/**
* @author Gavin King
@@ -183,7 +183,7 @@
cfg.setProperty( "hibernate.search.default.indexBase", sub.getAbsolutePath()
);
cfg.setProperty( "hibernate.search.Clock.directory_provider",
FSDirectoryProvider.class.getName() );
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- LuceneEventListener del = new LuceneEventListener();
+ FullTextEventListener del = new FullTextEventListener();
cfg.getEventListeners().setPostDeleteEventListeners( new PostDeleteEventListener[]{del}
);
cfg.getEventListeners().setPostUpdateEventListeners( new PostUpdateEventListener[]{del}
);
cfg.getEventListeners().setPostInsertEventListeners( new PostInsertEventListener[]{del}
);
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/TestCase.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -8,12 +8,9 @@
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.search.Environment;
import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.search.event.LuceneEventListener;
+import org.hibernate.search.event.FullTextEventListener;
import org.hibernate.HibernateException;
-import org.hibernate.SessionFactory;
import org.hibernate.impl.SessionFactoryImpl;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.SessionFactoryImplementor;
/**
* @author Emmanuel Bernard
@@ -28,13 +25,13 @@
return getLuceneEventListener().getDocumentBuilders().get( clazz
).getDirectoryProvider().getDirectory();
}
- private LuceneEventListener getLuceneEventListener() {
+ private FullTextEventListener getLuceneEventListener() {
PostInsertEventListener[] listeners = ( (SessionFactoryImpl) getSessions()
).getEventListeners().getPostInsertEventListeners();
- LuceneEventListener listener = null;
+ FullTextEventListener listener = null;
//FIXME this sucks since we mandante the event listener use
for (PostInsertEventListener candidate : listeners) {
- if (candidate instanceof LuceneEventListener) {
- listener = (LuceneEventListener) candidate;
+ if (candidate instanceof FullTextEventListener ) {
+ listener = (FullTextEventListener) candidate;
break;
}
}
@@ -45,7 +42,7 @@
protected void configure(org.hibernate.cfg.Configuration cfg) {
cfg.setProperty( "hibernate.search.default.directory_provider",
RAMDirectoryProvider.class.getName() );
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- LuceneEventListener del = new LuceneEventListener();
+ FullTextEventListener del = new FullTextEventListener();
cfg.getEventListeners().setPostDeleteEventListeners( new PostDeleteEventListener[]{del}
);
cfg.getEventListeners().setPostUpdateEventListeners( new PostUpdateEventListener[]{del}
);
cfg.getEventListeners().setPostInsertEventListeners( new PostInsertEventListener[]{del}
);
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/TransactionTest.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/TransactionTest.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/TransactionTest.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -1,21 +1,10 @@
//$Id: $
package org.hibernate.search.test;
-import java.io.File;
import java.io.IOException;
import org.hibernate.Session;
-import org.hibernate.HibernateException;
-import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.search.LuceneSession;
-import org.hibernate.search.event.LuceneEventListener;
import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.store.Directory;
/**
* @author Emmanuel Bernard
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/BridgeTest.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/BridgeTest.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/BridgeTest.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -11,13 +11,11 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.search.test.TestCase;
-import org.hibernate.search.LuceneSession;
+import org.hibernate.search.FullTextSession;
import org.hibernate.search.Environment;
-import org.hsqldb.Session;
import org.apache.lucene.search.Query;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.analysis.SimpleAnalyzer;
/**
@@ -43,7 +41,7 @@
tx.commit();
tx = s.beginTransaction();
- LuceneSession session = new LuceneSession(s);
+ FullTextSession session = new FullTextSession(s);
QueryParser parser = new QueryParser("id", new StandardAnalyzer() );
Query query;
List result;
@@ -73,7 +71,7 @@
tx.commit();
tx = s.beginTransaction();
- LuceneSession session = new LuceneSession(s);
+ FullTextSession session = new FullTextSession(s);
QueryParser parser = new QueryParser("id", new SimpleAnalyzer() );
Query query;
List result;
@@ -115,7 +113,7 @@
tx.commit();
tx = s.beginTransaction();
- LuceneSession session = new LuceneSession(s);
+ FullTextSession session = new FullTextSession(s);
QueryParser parser = new QueryParser("id", new StandardAnalyzer() );
Query query;
List result;
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/fieldAccess/FieldAccessTest.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/fieldAccess/FieldAccessTest.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/fieldAccess/FieldAccessTest.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -4,7 +4,7 @@
import java.util.List;
import org.hibernate.search.test.TestCase;
-import org.hibernate.search.LuceneSession;
+import org.hibernate.search.FullTextSession;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.apache.lucene.queryParser.QueryParser;
@@ -24,7 +24,7 @@
s.clear();
- LuceneSession session = new LuceneSession(s);
+ FullTextSession session = new FullTextSession(s);
tx = session.beginTransaction();
QueryParser p = new QueryParser("id", new StandardAnalyzer( ) );
List result = session.createLuceneQuery( p.parse( "Abstract:Hibernate"
) ).list();
@@ -48,7 +48,7 @@
s.clear();
- LuceneSession session = new LuceneSession(s);
+ FullTextSession session = new FullTextSession(s);
tx = session.beginTransaction();
QueryParser p = new QueryParser("id", new StandardAnalyzer( ) );
List result = session.createLuceneQuery( p.parse( "title:Action OR
Abstract:Action" ) ).list();
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -2,18 +2,13 @@
package org.hibernate.search.test.inheritance;
import org.hibernate.search.test.TestCase;
-import org.hibernate.search.test.query.Clock;
-import org.hibernate.search.test.query.Book;
-import org.hibernate.search.LuceneSession;
+import org.hibernate.search.FullTextSession;
import org.hibernate.Transaction;
-import org.hibernate.Hibernate;
-import org.hibernate.ScrollableResults;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.search.Query;
import java.util.List;
-import java.util.Iterator;
/**
* @author Emmanuel Bernard
@@ -21,7 +16,7 @@
public class InheritanceTest extends TestCase {
public void testInheritance() throws Exception {
- LuceneSession s = new LuceneSession( openSession() );
+ FullTextSession s = new FullTextSession( openSession() );
Transaction tx = s.beginTransaction();
Animal a = new Animal();
a.setName("Shark Jr");
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -5,7 +5,7 @@
import java.util.Iterator;
import org.hibernate.search.test.TestCase;
-import org.hibernate.search.LuceneSession;
+import org.hibernate.search.FullTextSession;
import org.hibernate.Transaction;
import org.hibernate.Hibernate;
import org.hibernate.ScrollableResults;
@@ -20,7 +20,7 @@
public class LuceneQueryTest extends TestCase {
public void testList() throws Exception {
- LuceneSession s = new LuceneSession( openSession() );
+ FullTextSession s = new FullTextSession( openSession() );
Transaction tx = s.beginTransaction();
Clock clock = new Clock(1, "Seiko");
s.save( clock );
@@ -62,7 +62,7 @@
}
public void testFirstMax() throws Exception {
- LuceneSession s = new LuceneSession( openSession() );
+ FullTextSession s = new FullTextSession( openSession() );
Transaction tx = s.beginTransaction();
Clock clock = new Clock(1, "Seiko");
s.save( clock );
@@ -108,7 +108,7 @@
}
public void testIterator() throws Exception {
- LuceneSession s = new LuceneSession( openSession() );
+ FullTextSession s = new FullTextSession( openSession() );
Transaction tx = s.beginTransaction();
Clock clock = new Clock(1, "Seiko");
s.save( clock );
@@ -145,7 +145,7 @@
}
public void testScrollableResultSet() throws Exception {
- LuceneSession s = new LuceneSession( openSession() );
+ FullTextSession s = new FullTextSession( openSession() );
Transaction tx = s.beginTransaction();
Clock clock = new Clock(1, "Seiko");
s.save( clock );
@@ -188,7 +188,7 @@
}
public void testMultipleEntityPerIndex() throws Exception {
- LuceneSession s = new LuceneSession( openSession() );
+ FullTextSession s = new FullTextSession( openSession() );
Transaction tx = s.beginTransaction();
Clock clock = new Clock(1, "Seiko");
s.save( clock );
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/session/MassIndexTest.java
===================================================================
---
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/session/MassIndexTest.java 2006-11-07
01:03:16 UTC (rev 10742)
+++
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/session/MassIndexTest.java 2006-11-07
01:16:53 UTC (rev 10743)
@@ -1,12 +1,10 @@
//$Id: $
package org.hibernate.search.test.session;
-import java.sql.SQLException;
import java.util.List;
import org.hibernate.search.test.TestCase;
-import org.hibernate.search.LuceneSession;
-import org.hibernate.Session;
+import org.hibernate.search.FullTextSession;
import org.hibernate.Transaction;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.analysis.StopAnalyzer;
@@ -17,7 +15,7 @@
public class MassIndexTest extends TestCase {
public void testTransactional() throws Exception {
- LuceneSession s = new LuceneSession( openSession() );
+ FullTextSession s = new FullTextSession( openSession() );
Transaction tx = s.beginTransaction();
int loop = 4;
for (int i = 0 ; i < loop; i++) {
@@ -29,13 +27,13 @@
tx.commit();
s.close();
- s = new LuceneSession( openSession() );
+ s = new FullTextSession( openSession() );
s.getTransaction().begin();
s.connection().createStatement().executeUpdate( "update Email set body='Meet
the guys who write the software'");
s.getTransaction().commit();
s.close();
- s = new LuceneSession( openSession() );
+ s = new FullTextSession( openSession() );
tx = s.beginTransaction();
QueryParser parser = new QueryParser("id", new StopAnalyzer() );
List result = s.createLuceneQuery( parser.parse( "body:write" ) ).list();
@@ -51,7 +49,7 @@
tx.commit(); //do the process
s.close();
- s = new LuceneSession( openSession() );
+ s = new FullTextSession( openSession() );
tx = s.beginTransaction();
result = s.createLuceneQuery( parser.parse( "body:write" ) ).list();
assertEquals( loop, result.size() );