Skip to content

Commit

Permalink
HSEARCH-361 Applied some formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hferentschik committed Dec 31, 2010
1 parent 7d23a58 commit ac466ee
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import javax.transaction.Status;
import javax.transaction.Synchronization;

import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.search.spi.SearchFactoryBuilder;
import org.slf4j.Logger;

import org.hibernate.Session;
Expand All @@ -58,6 +56,7 @@
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.event.PostUpdateEvent;
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.search.SearchException;
import org.hibernate.search.Version;
import org.hibernate.search.backend.Work;
Expand All @@ -66,6 +65,7 @@
import org.hibernate.search.cfg.SearchConfigurationFromHibernateCore;
import org.hibernate.search.engine.AbstractDocumentBuilder;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.spi.SearchFactoryBuilder;
import org.hibernate.search.util.LoggerFactory;
import org.hibernate.search.util.ReflectionHelper;
import org.hibernate.search.util.WeakIdentityHashMap;
Expand Down Expand Up @@ -132,10 +132,10 @@ public FullTextIndexEventListener(Installation installation) {
*/

public void initialize(Configuration cfg) {
if(installation != SINGLE_INSTANCE) {
if ( installation != SINGLE_INSTANCE ) {
throw new SearchException( "Only Installation.SINGLE_INSTANCE is supported" );
}

if ( searchFactoryImplementor == null ) {
searchFactoryImplementor = new SearchFactoryBuilder()
.configuration( new SearchConfigurationFromHibernateCore( cfg ) )
Expand All @@ -150,10 +150,10 @@ else if ( "manual".equals( indexingStrategy ) ) {
used = false;
}

log.debug( "Hibernate Search event listeners " + (used ? "activated" : "deactivated") );
skipDirtyChecks = ! searchFactoryImplementor.isDirtyChecksEnabled();
log.debug( "Hibernate Search dirty checks " + (skipDirtyChecks ? "disabled" : "enabled") );
log.debug( "Hibernate Search event listeners " + ( used ? "activated" : "deactivated" ) );

skipDirtyChecks = !searchFactoryImplementor.isDirtyChecksEnabled();
log.debug( "Hibernate Search dirty checks " + ( skipDirtyChecks ? "disabled" : "enabled" ) );
}

public SearchFactoryImplementor getSearchFactoryImplementor() {
Expand All @@ -166,7 +166,10 @@ public void onPostDelete(PostDeleteEvent event) {
if ( getDocumentBuilder( entity ) != null ) {
// FIXME The engine currently needs to know about details such as identifierRollbackEnabled
// but we should not move the responsibility to figure out the proper id to the engine
boolean identifierRollbackEnabled = event.getSession().getFactory().getSettings().isIdentifierRollbackEnabled();
boolean identifierRollbackEnabled = event.getSession()
.getFactory()
.getSettings()
.isIdentifierRollbackEnabled();
processWork( entity, event.getId(), WorkType.DELETE, event, identifierRollbackEnabled );
}
}
Expand Down Expand Up @@ -201,7 +204,9 @@ private String[] getDirtyPropertyNames(PostUpdateEvent event) {
EntityPersister persister = event.getPersister();
Object[] oldState = event.getOldState();
if ( oldState != null ) {
int[] dirtyProperties = persister.findDirty( event.getState(), oldState, event.getEntity(), event.getSession() );
int[] dirtyProperties = persister.findDirty(
event.getState(), oldState, event.getEntity(), event.getSession()
);
String[] propertyNames = persister.getPropertyNames();
int length = dirtyProperties.length;
String[] dirtyPropertyNames = new String[length];
Expand Down Expand Up @@ -263,7 +268,7 @@ protected void processCollectionEvent(AbstractCollectionEvent event) {
private Serializable getId(Object entity, AbstractCollectionEvent event) {
Serializable id = event.getAffectedOwnerIdOrNull();
if ( id == null ) {
//most likely this recovery is unnecessary since Hibernate Core probably try that
// most likely this recovery is unnecessary since Hibernate Core probably try that
EntityEntry entityEntry = event.getSession().getPersistenceContext().getEntry( entity );
id = entityEntry == null ? null : entityEntry.getId();
}
Expand Down Expand Up @@ -319,10 +324,12 @@ private void readObject(ObjectInputStream is)
// setting a final field by reflection during a readObject is considered as safe as in a constructor:
f.set( this, flushSynch );
}

private AbstractDocumentBuilder getDocumentBuilder(final Object entity) {
Class<?> clazz = entity.getClass();
AbstractDocumentBuilder documentBuilderIndexedEntity = searchFactoryImplementor.getDocumentBuilderIndexedEntity( clazz );
AbstractDocumentBuilder documentBuilderIndexedEntity = searchFactoryImplementor.getDocumentBuilderIndexedEntity(
clazz
);
if ( documentBuilderIndexedEntity != null ) {
return documentBuilderIndexedEntity;
}
Expand All @@ -335,8 +342,8 @@ public static enum Installation {
SINGLE_INSTANCE,

/**
* @deprecated As of Hibernate Search 3.3.
* @see #FullTextIndexEventListener()
* @deprecated As of Hibernate Search 3.3.
*/
MULTIPLE_INSTANCE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.Similarity;

import org.hibernate.search.engine.ServiceManager;
import org.hibernate.search.spi.ServiceProvider;
import org.hibernate.search.spi.internals.SearchFactoryImplementorWithShareableState;
import org.hibernate.search.spi.internals.SearchFactoryState;
import org.slf4j.Logger;

import org.hibernate.annotations.common.AssertionFailure;
Expand All @@ -60,6 +55,7 @@
import org.hibernate.search.engine.DocumentBuilderIndexedEntity;
import org.hibernate.search.engine.FilterDef;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.engine.ServiceManager;
import org.hibernate.search.exception.ErrorHandler;
import org.hibernate.search.filter.FilterCachingStrategy;
import org.hibernate.search.jmx.JMXRegistrar;
Expand All @@ -68,9 +64,12 @@
import org.hibernate.search.query.dsl.QueryContextBuilder;
import org.hibernate.search.query.dsl.impl.ConnectedQueryContextBuilder;
import org.hibernate.search.reader.ReaderProvider;
import org.hibernate.search.spi.ServiceProvider;
import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.spi.internals.DirectoryProviderData;
import org.hibernate.search.spi.internals.PolymorphicIndexHierarchy;
import org.hibernate.search.spi.internals.SearchFactoryImplementorWithShareableState;
import org.hibernate.search.spi.internals.SearchFactoryState;
import org.hibernate.search.stat.Statistics;
import org.hibernate.search.stat.StatisticsImpl;
import org.hibernate.search.stat.StatisticsImplementor;
Expand Down Expand Up @@ -134,14 +133,16 @@ public ImmutableSearchFactory(SearchFactoryState state) {
this.readerProvider = state.getReaderProvider();
this.worker = state.getWorker();
this.serviceManager = state.getServiceManager();

this.statistics = new StatisticsImpl( this );
boolean statsEnabled = ConfigurationParseHelper.getBooleanValue(
configurationProperties, Environment.GENERATE_STATS, false );
configurationProperties, Environment.GENERATE_STATS, false
);
statistics.setStatisticsEnabled( statsEnabled );

this.enableDirtyChecks = ConfigurationParseHelper.getBooleanValue(
configurationProperties, Environment.ENABLE_DIRTY_CHECK, true );
configurationProperties, Environment.ENABLE_DIRTY_CHECK, true
);

if ( isJMXEnabled() ) {
// since the SearchFactory is mutable we might have an already existing MBean which we have to unregister first
Expand Down Expand Up @@ -214,12 +215,12 @@ public Map<Class<?>, DocumentBuilderIndexedEntity<?>> getDocumentBuildersIndexed

@SuppressWarnings("unchecked")
public <T> DocumentBuilderIndexedEntity<T> getDocumentBuilderIndexedEntity(Class<T> entityType) {
return ( DocumentBuilderIndexedEntity<T> ) documentBuildersIndexedEntities.get( entityType );
return (DocumentBuilderIndexedEntity<T>) documentBuildersIndexedEntities.get( entityType );
}

@SuppressWarnings("unchecked")
public <T> DocumentBuilderContainedEntity<T> getDocumentBuilderContainedEntity(Class<T> entityType) {
return ( DocumentBuilderContainedEntity<T> ) documentBuildersContainedEntities.get( entityType );
return (DocumentBuilderContainedEntity<T>) documentBuildersContainedEntities.get( entityType );
}

public Set<DirectoryProvider<?>> getDirectoryProviders() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/

package org.hibernate.search.test.engine;

import org.hibernate.search.Environment;

/**
* Verify functionality of Environment.ENABLE_DIRTY_CHECK
* @since 3.4
*
* @author Sanne Grinovero
* @since 3.4
*/
public class DirtyChecksDisabledTest extends SkipIndexingWorkForUnaffectingChangesTest {

@Override
protected boolean isDirtyCheckEnabled() {
return false;
}

@Override
protected void configure(org.hibernate.cfg.Configuration configuration) {
super.configure( configuration );
cfg.setProperty( Environment.ENABLE_DIRTY_CHECK, " false" ); //intentional space in the value
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package org.hibernate.search.test.engine;

import junit.framework.Assert;

import org.apache.lucene.analysis.SimpleAnalyzer;

import org.hibernate.Transaction;
import org.hibernate.search.Environment;
import org.hibernate.search.FullTextSession;
Expand All @@ -36,31 +36,31 @@
/**
* See HSEARCH-361 and HSEARCH-5 : avoid reindexing objects for which
* changes where made in hibernate but not affecting the index state.
*
*
* @author Sanne Grinovero
*/
public class SkipIndexingWorkForUnaffectingChangesTest extends SearchTestCase {

public void testUnindexedFieldsDontTriggerEngine() {
// first, normal storage of new indexed graph:
FullTextSession fullTextSession = Search.getFullTextSession( openSession() );
Transaction tx = fullTextSession.beginTransaction();
BusLine line1 = new BusLine();
line1.setBusLineCode( Integer.valueOf( 1 ) );
line1.setBusLineCode( 1 );
line1.setBusLineName( "Line Uno" );
LazyCollectionsUpdatingTest.addBusStop( line1, "Gateshead" );
LazyCollectionsUpdatingTest.addBusStop( line1, "The Sage" );
session.persist( line1 );
tx.commit();

Assert.assertEquals( 1, LeakingLuceneBackend.getLastProcessedQueue().size() );
LeakingLuceneBackend.reset();
fullTextSession.clear();

// now change the BusLine in some way which does not affect the index:
tx = fullTextSession.beginTransaction();
line1 = (BusLine) fullTextSession.load( BusLine.class, line1.getId() );
line1.setBusLineCode( Integer.valueOf( 2 ) );
line1.setBusLineCode( 2 );
line1.setOperating( true ); // boolean set to same value: might receive a different instance of Boolean
BusStop busStop = line1.getStops().iterator().next();
busStop.setServiceComments( "please clean the garbage after the football match" );
Expand All @@ -71,7 +71,7 @@ public void testUnindexedFieldsDontTriggerEngine() {
else {
Assert.assertEquals( 2, LeakingLuceneBackend.getLastProcessedQueue().size() );
}

// now we make an indexing affecting change in the embedded object only,
// parent should still be updated
LeakingLuceneBackend.reset();
Expand All @@ -81,27 +81,28 @@ public void testUnindexedFieldsDontTriggerEngine() {
busStop.setRoadName( "Mill Road" );
tx.commit();
Assert.assertEquals( 2, LeakingLuceneBackend.getLastProcessedQueue().size() ); //2 = delete+add

fullTextSession.close();
}

// Test setup options - Entities
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { BusLine.class, BusStop.class };
}

// Test setup options - SessionFactory Properties
@Override
protected void configure(org.hibernate.cfg.Configuration configuration) {
super.configure( configuration );
cfg.setProperty( "hibernate.search.default.directory_provider", "ram" );
cfg.setProperty( Environment.ANALYZER_CLASS, SimpleAnalyzer.class.getName() );
cfg.setProperty( "hibernate.search.worker.backend", org.hibernate.search.test.embedded.depth.LeakingLuceneBackend.class.getName() );
cfg.setProperty(
"hibernate.search.worker.backend",
org.hibernate.search.test.embedded.depth.LeakingLuceneBackend.class.getName()
);
}

protected boolean isDirtyCheckEnabled() {
return true;
}

}

0 comments on commit ac466ee

Please sign in to comment.