HHH-4910 docs, javadocs, formatting, minor refactoring

This commit is contained in:
Brett Meyer 2013-09-18 12:19:31 -04:00
parent bcd6185809
commit feaac3b917
6 changed files with 40 additions and 26 deletions

View File

@ -261,6 +261,13 @@
<entry>hibernate.cache.use_structured_entries</entry>
<entry><para><literal>true</literal> or <literal>false</literal></para></entry>
<entry>Forces Hibernate to store data in the second-level cache in a more human-readable format.</entry>
</row>
<row>
<entry>hibernate.cache.auto_evict_collection_cache</entry>
<entry><para><literal>true</literal> or <literal>false</literal> (default: false)</para></entry>
<entry>Enables the automatic eviction of a bi-directional association's collection cache when an element
in the ManyToOne collection is added/updated/removed without properly managing the change on the OneToMany
side.</entry>
</row>
<row>
<entry>hibernate.cache.use_reference_entries</entry>

View File

@ -721,6 +721,16 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQL82Dialect</programlisting>
</para></entry>
</row>
<row>
<entry><literal>hibernate.cache.auto_evict_collection_cache</literal></entry>
<entry>Enables the automatic eviction of a bi-directional association's collection cache when an element
in the ManyToOne collection is added/updated/removed without properly managing the change on the OneToMany
side. <para> <emphasis
role="strong">e.g.</emphasis> <literal>true|false</literal> (default: false)
</para></entry>
</row>
<row>
<entry><literal>hibernate.cache.default_cache_concurrency_strategy</literal></entry>

View File

@ -30,6 +30,7 @@ import java.util.Set;
import org.jboss.logging.Logger;
import org.hibernate.cache.spi.CacheKey;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry;
@ -48,35 +49,32 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/**
* @author Andreas Berger (latest modification by $Author$)
* @version $Id$
* @created 30.08.13 - 01:54
* Allows the collection cache to be automatically evicted if an element is inserted/removed/updated *without* properly
* managing both sides of the association (ie, the ManyToOne collection is changed w/o properly managing the OneToMany).
*
* For this functionality to be used, {@link AvailableSettings#AUTO_EVICT_COLLECTION_CACHE} must be enabled. For
* performance reasons, it's disabled by default.
*
* @author Andreas Berger
*/
public class CollectionCacheInvalidator implements Integrator,
PostInsertEventListener,
PostDeleteEventListener,
PostUpdateEventListener {
public class CollectionCacheInvalidator implements Integrator, PostInsertEventListener, PostDeleteEventListener,
PostUpdateEventListener {
private static final Logger LOG = Logger.getLogger( CollectionCacheInvalidator.class.getName() );
@Override
public void integrate(
Configuration configuration,
SessionFactoryImplementor sessionFactory,
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
integrate( serviceRegistry, sessionFactory );
}
@Override
public void integrate(
MetadataImplementor metadata,
SessionFactoryImplementor sessionFactory,
public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
integrate( serviceRegistry, sessionFactory );
}
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
@Override
@ -134,7 +132,8 @@ public class CollectionCacheInvalidator implements Integrator,
int i = persister.getEntityMetamodel().getPropertyIndex( mappedBy );
Serializable oldId = null;
if ( oldState != null ) {
// in case of updating an entity we perhaps have to decache 2 entity collections, this is the old one
// in case of updating an entity we perhaps have to decache 2 entity collections, this is the
// old one
oldId = session.getIdentifier( oldState[i] );
}
Object ref = persister.getPropertyValue( entity, i );
@ -156,8 +155,8 @@ public class CollectionCacheInvalidator implements Integrator,
}
}
}
catch (Exception e) {
//don't let decaching influence other logic
catch ( Exception e ) {
// don't let decaching influence other logic
LOG.error( "", e );
}
}

View File

@ -326,7 +326,8 @@ public interface AvailableSettings {
*/
public static final String USE_STRUCTURED_CACHE = "hibernate.cache.use_structured_entries";
/**
* Enables the eviction of the OneToMany-Site-Cache of a bi-directional association, when the ManyToOne site changes
* Enables the automatic eviction of a bi-directional association's collection cache when an element in the
* ManyToOne collection is added/updated/removed without properly managing the change on the OneToMany side.
*/
public static final String AUTO_EVICT_COLLECTION_CACHE = "hibernate.cache.auto_evict_collection_cache";
/**

View File

@ -321,7 +321,7 @@ public interface CollectionPersister extends CollectionDefinition {
public int getBatchSize();
/**
* @return the Name of the Property, this collection is mapped by
* @return the name of the property this collection is mapped by
*/
public String getMappedByProperty();
}

View File

@ -43,7 +43,7 @@ import static org.junit.Assert.fail;
public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {User.class, Company.class};
return new Class[] { User.class, Company.class };
}
@Override
@ -100,7 +100,6 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
@ -125,7 +124,6 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
@ -134,7 +132,7 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
try {
assertEquals( 0, company.getUsers().size() );
}
catch (ObjectNotFoundException e) {
catch ( ObjectNotFoundException e ) {
fail( "Cached element not found" );
}
s.close();
@ -158,7 +156,6 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
@ -171,7 +168,7 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
try {
assertEquals( 0, company1.getUsers().size() );
}
catch (ObjectNotFoundException e) {
catch ( ObjectNotFoundException e ) {
fail( "Cached element not found" );
}