Example usage for org.hibernate.persister.collection AbstractCollectionPersister getCacheAccessStrategy

List of usage examples for org.hibernate.persister.collection AbstractCollectionPersister getCacheAccessStrategy

Introduction

In this page you can find the example usage for org.hibernate.persister.collection AbstractCollectionPersister getCacheAccessStrategy.

Prototype

@Override
    public CollectionDataAccess getCacheAccessStrategy() 

Source Link

Usage

From source file:com.fiveamsolutions.nci.commons.test.AbstractHibernateTestCase.java

License:Open Source License

/**
 * In JUnit3x you would normally override the setUp() and add your own functionality locally however, in JUnit4 to
 * override simply define your method and give it the <code>@Before annotation</code>. Doing so will cause that
 * method to be invoked after the parent class's setUp().
 *///from  ww w  .  j  a v a  2  s.  c o  m
@SuppressWarnings("unchecked")
@Before
public final void setUp() {

    Transaction tx = HibernateUtil.getHibernateHelper().beginTransaction();
    SchemaExport se = new SchemaExport(HibernateUtil.getHibernateHelper().getConfiguration());
    se.drop(false, true);
    se.create(false, true);
    tx.commit();

    // clean up the hibernate second level cache between runs
    SessionFactory sf = getCurrentSession().getSessionFactory();
    Map<?, EntityPersister> classMetadata = sf.getAllClassMetadata();
    for (EntityPersister ep : classMetadata.values()) {
        if (ep.hasCache()) {
            sf.evictEntity(ep.getCacheAccessStrategy().getRegion().getName());
        }
    }

    Map<?, AbstractCollectionPersister> collMetadata = sf.getAllCollectionMetadata();
    for (AbstractCollectionPersister acp : collMetadata.values()) {
        if (acp.hasCache()) {
            sf.evictCollection(acp.getCacheAccessStrategy().getRegion().getName());
        }
    }
    transaction = HibernateUtil.getHibernateHelper().beginTransaction();

}

From source file:gov.nih.nci.firebird.test.AbstractHibernateTestCase.java

License:Open Source License

/**
 * Method that runs before the test to clean up the db and start the transaction.
 *//*  w  ww.jav a2 s  .  com*/
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    // clean up the hibernate second level cache between runs
    SessionFactory sf = getCurrentSession().getSessionFactory();
    Map<String, EntityPersister> classMetadata = sf.getAllClassMetadata();
    for (EntityPersister ep : classMetadata.values()) {
        if (ep.hasCache()) {
            sf.evictEntity(ep.getCacheAccessStrategy().getRegion().getName());
        }
    }

    Map<?, AbstractCollectionPersister> collMetadata = sf.getAllCollectionMetadata();
    for (AbstractCollectionPersister acp : collMetadata.values()) {
        if (acp.hasCache()) {
            sf.evictCollection(acp.getCacheAccessStrategy().getRegion().getName());
        }
    }
    transaction = helper.beginTransaction();
}