Author: hardy.ferentschik
Date: 2010-07-14 12:47:30 -0400 (Wed, 14 Jul 2010)
New Revision: 19946
Removed:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/ContextHolder.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/FullTextIndexCollectionEventListener.java
Modified:
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/EventListenerRegister.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/EventListenerRegisterTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/EventListenerSerializationTest.java
search/trunk/pom.xml
Log:
HSEARCH-558
* Aligned Search with Core 3.6 (currently SNAPSHOT)
* Deprecated default constructor in EventListenerRegister and let it throw an Exception in
case it is called
* Deleted ContextHolder and FullTextIndexCollectionEventListener
Deleted:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/ContextHolder.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/ContextHolder.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/ContextHolder.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -1,84 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.search.event;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.hibernate.cfg.Configuration;
-import org.hibernate.search.cfg.SearchConfigurationFromHibernateCore;
-import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.search.impl.SearchFactoryBuilder;
-
-/**
- * Holds already built SearchFactory per Hibernate Configuration object
- * concurrent threads do not share this information
- *
- * This code uses ThreadLocal and despite the weak hashMap use, some users claim to see
- * memory leaks (in Tomcat as usual). So if that can be avoided, do not use this class.
- *
- * There is no clean hook to always remove the SearchFactory from the map.
- *
- * @author Emmanuel Bernard
- */
-public class ContextHolder {
- private static final ThreadLocal<WeakHashMap<Configuration,
SearchFactoryImplementor>> contexts =
- new ThreadLocal<WeakHashMap<Configuration, SearchFactoryImplementor>>();
-
- //code doesn't have to be multithreaded because SF creation is not.
- //this is not a public API, should really only be used during the SessionFactory
building
- public static SearchFactoryImplementor getOrBuildSearchFactory(Configuration cfg) {
- WeakHashMap<Configuration, SearchFactoryImplementor> contextMap =
contexts.get();
- if ( contextMap == null ) {
- contextMap = new WeakHashMap<Configuration, SearchFactoryImplementor>( 2 );
- contexts.set( contextMap );
- }
- SearchFactoryImplementor searchFactory = contextMap.get( cfg );
- if ( searchFactory == null ) {
- searchFactory = new SearchFactoryBuilder()
- .configuration( new SearchConfigurationFromHibernateCore( cfg ) )
- .buildSearchFactory();
- contextMap.put( cfg, searchFactory );
- }
- return searchFactory;
- }
-
- //code doesn't have to be multithreaded because SF creation is not.
- //this is not a public API, should really only be used by the same
- public static void removeSearchFactoryFromCache(SearchFactoryImplementor factory) {
- WeakHashMap<Configuration, SearchFactoryImplementor> contextMap =
contexts.get();
- if ( contextMap != null ) {
- for ( Map.Entry<Configuration, SearchFactoryImplementor> entry :
contextMap.entrySet() ) {
- if ( entry.getValue() == factory ) {
- contextMap.remove( entry.getKey() );
- }
- }
- //clear the thread local
- if ( contextMap.size() == 0 ) {
- contexts.remove();
- }
- }
- }
-}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/EventListenerRegister.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/EventListenerRegister.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/EventListenerRegister.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -1,26 +1,25 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
*/
package org.hibernate.search.event;
@@ -58,7 +57,7 @@
* @param properties the Search configuration
*/
public static void enableHibernateSearch(EventListeners listeners, Properties
properties) {
- // check whether search is explicitly disabled - if so there is nothing to do
+ // check whether search is explicitly disabled - if so there is nothing to do
String enableSearchListeners = properties.getProperty(
Environment.AUTOREGISTER_LISTENERS );
if ( "false".equalsIgnoreCase( enableSearchListeners ) ) {
log.info(
@@ -69,7 +68,7 @@
}
final FullTextIndexEventListener searchListener =
new FullTextIndexEventListener(
FullTextIndexEventListener.Installation.SINGLE_INSTANCE );
-
+
// PostInsertEventListener
listeners.setPostInsertEventListeners(
addIfNeeded(
@@ -185,11 +184,7 @@
if ( FullTextIndexEventListener.class == eventListener.getClass() ) {
return true;
}
- if ( FullTextIndexCollectionEventListener.class == eventListener.getClass() ) {
- return true;
- }
}
return false;
}
-
}
Deleted:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/FullTextIndexCollectionEventListener.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/FullTextIndexCollectionEventListener.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/FullTextIndexCollectionEventListener.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -1,68 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.search.event;
-
-import org.hibernate.event.PostCollectionRecreateEvent;
-import org.hibernate.event.PostCollectionRecreateEventListener;
-import org.hibernate.event.PostCollectionRemoveEvent;
-import org.hibernate.event.PostCollectionRemoveEventListener;
-import org.hibernate.event.PostCollectionUpdateEvent;
-import org.hibernate.event.PostCollectionUpdateEventListener;
-
-/**
- * @author Emmanuel Bernard
- * @deprecated As of release 3.1.0, replaced by {@link FullTextIndexEventListener}
- */
-@SuppressWarnings("serial")
-@Deprecated
-public class FullTextIndexCollectionEventListener extends FullTextIndexEventListener
- implements PostCollectionRecreateEventListener,
- PostCollectionRemoveEventListener,
- PostCollectionUpdateEventListener {
-
- /**
- * @deprecated As of release 3.1.0, replaced by {@link
FullTextIndexEventListener#onPostRecreateCollection(PostCollectionRecreateEvent)}
- */
- @Deprecated
- public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
- processCollectionEvent( event );
- }
-
- /**
- * @deprecated As of release 3.1.0, replaced by {@link
FullTextIndexEventListener#onPostRemoveCollection(PostCollectionRemoveEvent)}
- */
- @Deprecated
- public void onPostRemoveCollection(PostCollectionRemoveEvent event) {
- processCollectionEvent( event );
- }
-
- /**
- * @deprecated As of release 3.1.0, replaced by {@link
FullTextIndexEventListener#onPostUpdateCollection(PostCollectionUpdateEvent)}
- */
- @Deprecated
- public void onPostUpdateCollection(PostCollectionUpdateEvent event) {
- processCollectionEvent( event );
- }
-}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/event/FullTextIndexEventListener.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -1,26 +1,25 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
*/
package org.hibernate.search.event;
@@ -57,6 +56,7 @@
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.event.PostUpdateEvent;
import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.search.SearchException;
import org.hibernate.search.Version;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkType;
@@ -68,7 +68,6 @@
import org.hibernate.search.util.ReflectionHelper;
import org.hibernate.search.util.WeakIdentityHashMap;
-import static
org.hibernate.search.event.FullTextIndexEventListener.Installation.MULTIPLE_INSTANCE;
import static
org.hibernate.search.event.FullTextIndexEventListener.Installation.SINGLE_INSTANCE;
/**
@@ -79,34 +78,46 @@
* @author Emmanuel Bernard
* @author Mattias Arbin
* @author Sanne Grinovero
+ * @author Hardy Ferentschik
*/
//TODO implement and use a LockableDirectoryProvider that wraps a DP to handle the lock
inside the LDP
//TODO make this class final as soon as FullTextIndexCollectionEventListener is removed.
-@SuppressWarnings( "serial" )
+@SuppressWarnings("serial")
public class FullTextIndexEventListener implements PostDeleteEventListener,
PostInsertEventListener, PostUpdateEventListener,
PostCollectionRecreateEventListener, PostCollectionRemoveEventListener,
PostCollectionUpdateEventListener, FlushEventListener, Initializable, Destructible {
- static {
- Version.touch();
- }
-
private static final Logger log = LoggerFactory.make();
+ private final Installation installation;
protected boolean used;
protected SearchFactoryImplementor searchFactoryImplementor;
- private final Installation installation;
-
+
+ static {
+ Version.touch();
+ }
+
//only used by the FullTextIndexEventListener instance playing in the FlushEventListener
role.
// transient because it's not serializable (and state doesn't need to live
longer than a flush).
// final because it's initialization should be published to other threads.
// ! update the readObject() method in case of name changes !
// make sure the Synchronization doesn't contain references to Session, otherwise
we'll leak memory.
- private transient final Map<Session,Synchronization> flushSynch = new
WeakIdentityHashMap<Session,Synchronization>(0);
+ private transient final Map<Session, Synchronization> flushSynch = new
WeakIdentityHashMap<Session, Synchronization>(
+ 0
+ );
+ /**
+ * @deprecated As of Hibernate Search 3.3. This method was used for instantiating the
event listener when configured
+ * in a configuration file. Since Hibernate Core 3.6 Hibernate Search will
always be automatically enabled if available
+ * on the classpath.
+ */
public FullTextIndexEventListener() {
- this.installation = MULTIPLE_INSTANCE;
+ String msg = "FullTextIndexEventListener default constructor is obsolete. Remove
all explicit" +
+ "event listener configuration. As of Hibernate Core 3.6 Hibernate Search will be
automatically enabled " +
+ "if it is detected on the classpath.";
+ log.error( msg );
+ throw new SearchException( msg );
}
public FullTextIndexEventListener(Installation installation) {
@@ -118,22 +129,16 @@
*/
public void initialize(Configuration cfg) {
- /*
- * if we know we pass the same instance, we can actually ensure that
- * - initialize() is a no op if already run
- * - avoid ContextHolder altogether
- */
- if ( installation != SINGLE_INSTANCE ) {
- log.debug( "Storing SearchFactory in ThreadLocal" );
- searchFactoryImplementor = ContextHolder.getOrBuildSearchFactory( cfg );
+ if(installation != SINGLE_INSTANCE) {
+ throw new SearchException( "Only Installation.SINGLE_INSTANCE is supported"
);
}
- else {
- if ( searchFactoryImplementor == null ) {
- searchFactoryImplementor = new SearchFactoryBuilder()
- .configuration( new SearchConfigurationFromHibernateCore( cfg ) )
- .buildSearchFactory();
- }
+
+ if ( searchFactoryImplementor == null ) {
+ searchFactoryImplementor = new SearchFactoryBuilder()
+ .configuration( new SearchConfigurationFromHibernateCore( cfg ) )
+ .buildSearchFactory();
}
+
String indexingStrategy = searchFactoryImplementor.getIndexingStrategy();
if ( "event".equals( indexingStrategy ) ) {
used = searchFactoryImplementor.getDocumentBuildersIndexedEntities().size() != 0;
@@ -141,7 +146,7 @@
else if ( "manual".equals( indexingStrategy ) ) {
used = false;
}
- log.debug( "Hibernate Search event listeners " + (used ?
"activated" : "desactivated") );
+ log.debug( "Hibernate Search event listeners " + ( used ?
"activated" : "deactivated" ) );
}
public SearchFactoryImplementor getSearchFactoryImplementor() {
@@ -188,17 +193,8 @@
public void cleanup() {
searchFactoryImplementor.close();
- temptativeContextCleaning();
-
}
- private void temptativeContextCleaning() {
- if ( installation != SINGLE_INSTANCE ) {
- //unlikely to work: the thread used for closing is unlikely the thread used for
initializing
- ContextHolder.removeSearchFactoryFromCache( searchFactoryImplementor );
- }
- }
-
public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
processCollectionEvent( event );
}
@@ -270,38 +266,38 @@
* Warning: if the synchronization contains a hard reference
* to the Session proper cleanup is not guaranteed and memory leaks
* will happen.
+ *
* @param eventSource should be the Session doing the flush
- * @param synchronization
+ * @param synchronization the synchronisation instance
*/
public void addSynchronization(EventSource eventSource, Synchronization synchronization)
{
this.flushSynch.put( eventSource, synchronization );
}
- /* Might want to implement AutoFlushEventListener in future?
- public void onAutoFlush(AutoFlushEvent event) throws HibernateException {
- // Currently not needed as auto-flush is not happening
- // when out of transaction.
- }
- */
-
private void writeObject(ObjectOutputStream os) throws IOException {
os.defaultWriteObject();
- temptativeContextCleaning();
}
//needs to implement custom readObject to restore the transient fields
- private void readObject(ObjectInputStream is) throws IOException,
ClassNotFoundException, SecurityException, NoSuchFieldException, IllegalArgumentException,
IllegalAccessException {
+
+ private void readObject(ObjectInputStream is)
+ throws IOException, ClassNotFoundException, SecurityException, NoSuchFieldException,
IllegalArgumentException, IllegalAccessException {
is.defaultReadObject();
Class<FullTextIndexEventListener> cl = FullTextIndexEventListener.class;
- Field f = cl.getDeclaredField("flushSynch");
+ Field f = cl.getDeclaredField( "flushSynch" );
ReflectionHelper.setAccessible( f );
- Map<Session,Synchronization> flushSynch = new
WeakIdentityHashMap<Session,Synchronization>(0);
+ Map<Session, Synchronization> flushSynch = new WeakIdentityHashMap<Session,
Synchronization>( 0 );
// setting a final field by reflection during a readObject is considered as safe as in
a constructor:
f.set( this, flushSynch );
}
public static enum Installation {
SINGLE_INSTANCE,
+
+ /**
+ * @deprecated As of Hibernate Search 3.3.
+ * @see #FullTextIndexEventListener()
+ */
MULTIPLE_INSTANCE
}
}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -39,6 +39,7 @@
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
+import org.hibernate.LobHelper;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.ReplicationMode;
@@ -47,6 +48,7 @@
import org.hibernate.ScrollableResults;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
+import org.hibernate.TypeHelper;
import org.hibernate.UnknownProfileException;
import org.hibernate.LockOptions;
import org.hibernate.classic.Session;
@@ -805,4 +807,12 @@
public void disableFetchProfile(String name) throws UnknownProfileException {
session.disableFetchProfile( name );
}
+
+ public TypeHelper getTypeHelper() {
+ return session.getTypeHelper();
+ }
+
+ public LobHelper getLobHelper() {
+ return session.getLobHelper();
+ }
}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -52,7 +52,7 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.event.FullTextIndexEventListener;
import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.test.annotations.HibernateTestCase;
+import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
/**
* Base class for Hibernate Search unit tests.
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/EventListenerRegisterTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/EventListenerRegisterTest.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/EventListenerRegisterTest.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -1,31 +1,32 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
*/
package org.hibernate.search.test.configuration;
import java.util.Properties;
+import junit.framework.TestCase;
+
import org.hibernate.event.EventListeners;
import org.hibernate.event.PostCollectionRecreateEvent;
import org.hibernate.event.PostCollectionRecreateEventListener;
@@ -42,23 +43,20 @@
import org.hibernate.search.Environment;
import org.hibernate.search.event.EventListenerRegister;
import org.hibernate.search.event.FullTextIndexEventListener;
-import org.hibernate.search.event.FullTextIndexCollectionEventListener;
-import junit.framework.TestCase;
-
/**
* @author Sanne Grinovero
*/
@SuppressWarnings("deprecation")
public class EventListenerRegisterTest extends TestCase {
-
+
public void testRegisterOnEmptyListeners_CfgDisabled() {
EventListeners evListeners = new EventListeners();
EventListenerRegister.enableHibernateSearch( evListeners, makeConfiguration( false )
);
EventListenerRegister.enableHibernateSearch( evListeners, makeConfiguration( false )
);
assertPresence( false, evListeners );
}
-
+
public void testRegisterOnEmptyListeners_CfgEnabled() {
EventListeners evListeners = new EventListeners();
//tests registering multiple times is idempotent:
@@ -66,77 +64,85 @@
EventListenerRegister.enableHibernateSearch( evListeners, makeConfiguration( true ) );
assertPresence( true, evListeners );
}
-
+
public void testRegisterOnEmptyListeners_CfgAuto() {
EventListeners evListeners = new EventListeners();
EventListenerRegister.enableHibernateSearch( evListeners, new Properties() );
EventListenerRegister.enableHibernateSearch( evListeners, new Properties() );
assertPresence( true, evListeners );
}
-
+
public void testOnAlreadyRegistered() {
- helperOnAlreadyRegistered( new FullTextIndexEventListener() );
+ helperOnAlreadyRegistered( new
FullTextIndexEventListener(FullTextIndexEventListener.Installation.SINGLE_INSTANCE) );
}
-
- public void testOnAlreadyRegisteredDeprecated() {
- helperOnAlreadyRegistered( new FullTextIndexCollectionEventListener() );
- }
-
+
public void testOnPopulatedEventListeners() {
EventListeners evListeners = makeSomeEventListeners();
EventListenerRegister.enableHibernateSearch( evListeners, new Properties() );
EventListenerRegister.enableHibernateSearch( evListeners, new Properties() );
assertPresence( true, evListeners );
}
-
+
private void helperOnAlreadyRegistered(FullTextIndexEventListener listenerFullText) {
-
+
AnotherListener listenerA = new AnotherListener();
AnotherListener listenerB = new AnotherListener();
-
+
EventListeners evListeners = new EventListeners();
evListeners.setPostInsertEventListeners(
- new PostInsertEventListener[]{ listenerA, listenerB, listenerFullText } );
+ new PostInsertEventListener[] { listenerA, listenerB, listenerFullText }
+ );
evListeners.setPostUpdateEventListeners(
- new PostUpdateEventListener[]{ listenerA, listenerB, listenerFullText } );
+ new PostUpdateEventListener[] { listenerA, listenerB, listenerFullText }
+ );
evListeners.setPostDeleteEventListeners(
- new PostDeleteEventListener[]{ listenerA, listenerB, listenerFullText } );
+ new PostDeleteEventListener[] { listenerA, listenerB, listenerFullText }
+ );
evListeners.setPostCollectionRecreateEventListeners(
- new PostCollectionRecreateEventListener[]{ listenerA, listenerB, listenerFullText }
);
+ new PostCollectionRecreateEventListener[] { listenerA, listenerB, listenerFullText }
+ );
evListeners.setPostCollectionRemoveEventListeners(
- new PostCollectionRemoveEventListener[]{ listenerA, listenerB, listenerFullText } );
+ new PostCollectionRemoveEventListener[] { listenerA, listenerB, listenerFullText }
+ );
evListeners.setPostCollectionUpdateEventListeners(
- new PostCollectionUpdateEventListener[]{ listenerA, listenerB, listenerFullText } );
-
+ new PostCollectionUpdateEventListener[] { listenerA, listenerB, listenerFullText }
+ );
+
EventListenerRegister.enableHibernateSearch( evListeners, makeConfiguration( false )
);
EventListenerRegister.enableHibernateSearch( evListeners, makeConfiguration( false )
);
EventListenerRegister.enableHibernateSearch( evListeners, makeConfiguration( false )
);
assertPresence( true, evListeners );
}
-
+
private EventListeners makeSomeEventListeners() {
-
+
AnotherListener listenerA = new AnotherListener();
AnotherListener listenerB = new AnotherListener();
AnotherListener listenerC = new AnotherListener();
-
+
EventListeners evListeners = new EventListeners();
evListeners.setPostInsertEventListeners(
- new PostInsertEventListener[]{ listenerA, listenerB, listenerC } );
+ new PostInsertEventListener[] { listenerA, listenerB, listenerC }
+ );
evListeners.setPostUpdateEventListeners(
- new PostUpdateEventListener[]{ listenerA, listenerB, listenerC } );
+ new PostUpdateEventListener[] { listenerA, listenerB, listenerC }
+ );
evListeners.setPostDeleteEventListeners(
- new PostDeleteEventListener[]{ listenerA, listenerB, listenerC } );
+ new PostDeleteEventListener[] { listenerA, listenerB, listenerC }
+ );
evListeners.setPostCollectionRecreateEventListeners(
- new PostCollectionRecreateEventListener[]{ listenerA, listenerB, listenerC } );
+ new PostCollectionRecreateEventListener[] { listenerA, listenerB, listenerC }
+ );
evListeners.setPostCollectionRemoveEventListeners(
- new PostCollectionRemoveEventListener[]{ listenerA, listenerB, listenerC } );
+ new PostCollectionRemoveEventListener[] { listenerA, listenerB, listenerC }
+ );
evListeners.setPostCollectionUpdateEventListeners(
- new PostCollectionUpdateEventListener[]{ listenerA, listenerB, listenerC } );
-
+ new PostCollectionUpdateEventListener[] { listenerA, listenerB, listenerC }
+ );
+
return evListeners;
}
-
+
private void assertPresence(boolean expected, EventListeners evListeners) {
assertEquals( expected, isPresent( evListeners.getPostInsertEventListeners() ) );
assertEquals( expected, isPresent( evListeners.getPostUpdateEventListeners() ) );
@@ -153,27 +159,24 @@
}
private static boolean isPresent(Object[] listeners) {
- if (listeners==null)
+ if ( listeners == null ) {
return false;
+ }
boolean found = false; // to verify class present at most once.
- for (Object eventListener : listeners) {
+ for ( Object eventListener : listeners ) {
if ( FullTextIndexEventListener.class == eventListener.getClass() ) {
assertFalse( found );
found = true;
}
- if ( FullTextIndexCollectionEventListener.class == eventListener.getClass() ) {
- assertFalse( found );
- found = true;
- }
}
return found;
}
-
+
private static class AnotherListener implements PostDeleteEventListener,
- PostInsertEventListener, PostUpdateEventListener,
- PostCollectionRecreateEventListener, PostCollectionRemoveEventListener,
- PostCollectionUpdateEventListener {
-
+ PostInsertEventListener, PostUpdateEventListener,
+ PostCollectionRecreateEventListener, PostCollectionRemoveEventListener,
+ PostCollectionUpdateEventListener {
+
//empty methods: just needing any implementation of these listeners.
public void onPostDelete(PostDeleteEvent event) {
@@ -193,7 +196,5 @@
public void onPostUpdateCollection(PostCollectionUpdateEvent event) {
}
-
}
-
}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/EventListenerSerializationTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/EventListenerSerializationTest.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/EventListenerSerializationTest.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -1,26 +1,25 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
*/
package org.hibernate.search.test.engine;
@@ -33,18 +32,17 @@
/**
* Tests that the FullTextIndexEventListener is Serializable
- *
+ *
* @author Sanne Grinovero
*/
public class EventListenerSerializationTest extends TestCase {
public void testEventListenerSerializable() throws IOException, ClassNotFoundException
{
- FullTextIndexEventListener eventListener = new FullTextIndexEventListener();
+ FullTextIndexEventListener eventListener = new
FullTextIndexEventListener(FullTextIndexEventListener.Installation.SINGLE_INSTANCE);
eventListener.addSynchronization( null, null );
Object secondListener = SerializationTestHelper
.duplicateBySerialization(eventListener);
assertNotNull(secondListener);
assertFalse(secondListener == eventListener);
}
-
}
Modified:
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java
===================================================================
---
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java 2010-07-14
14:21:00 UTC (rev 19945)
+++
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java 2010-07-14
16:47:30 UTC (rev 19946)
@@ -52,7 +52,7 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.event.FullTextIndexEventListener;
import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.test.annotations.HibernateTestCase;
+import org.hibernate.testing.junit.functional.annotations.HibernateTestCase;
/**
* Base class for Hibernate Search unit tests.
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2010-07-14 14:21:00 UTC (rev 19945)
+++ search/trunk/pom.xml 2010-07-14 16:47:30 UTC (rev 19946)
@@ -129,7 +129,7 @@
<properties>
<slf4jVersion>1.5.8</slf4jVersion>
<luceneVersion>2.9.2</luceneVersion>
- <hibernateVersion>3.5.1-Final</hibernateVersion>
+ <hibernateVersion>3.6.0-SNAPSHOT</hibernateVersion>
<hibernateCommonsAnnotationVersion>3.2.0.Final</hibernateCommonsAnnotationVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>