Example usage for org.hibernate SessionFactory getAllCollectionMetadata

List of usage examples for org.hibernate SessionFactory getAllCollectionMetadata

Introduction

In this page you can find the example usage for org.hibernate SessionFactory getAllCollectionMetadata.

Prototype

@Deprecated
Map getAllCollectionMetadata();

Source Link

Document

Get the CollectionMetadata for all mapped collections.

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().
 *//*  w w  w. j a  v  a2 s.  com*/
@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 w w. j  a  v a2s.  c  o  m
@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();
}

From source file:org.jbpm.db.hibernate.HibernateHelper.java

License:Open Source License

public static void clearHibernateCache(SessionFactory sessionFactory) {
    sessionFactory.evictQueries();/* w  w w.j  a va  2  s  . co m*/

    Map classMetadata = sessionFactory.getAllClassMetadata();
    Iterator iter = classMetadata.keySet().iterator();
    while (iter.hasNext()) {
        String entityName = (String) iter.next();
        log.debug("evicting entities " + entityName);
        Class entityClass = ClassLoaderUtil.loadClass(entityName);
        sessionFactory.evict(entityClass);
    }

    Map collectionMetadata = sessionFactory.getAllCollectionMetadata();
    iter = collectionMetadata.keySet().iterator();
    while (iter.hasNext()) {
        String collectionName = (String) iter.next();
        log.debug("evicting collection " + collectionName);
        sessionFactory.evictCollection(collectionName);
    }
}

From source file:org.opentaps.foundation.infrastructure.Infrastructure.java

License:Open Source License

/**
 * Clear hibernate second-level cache./*  w  w w . j av a  2s  .co  m*/
 * @param sessionFactory a <code>SessionFactory</code> instance
 */
@SuppressWarnings("unchecked")
public void evictHibernateCache(SessionFactory sessionFactory) {
    if (sessionFactory != null) {
        Map<String, CollectionMetadata> roleMap = sessionFactory.getAllCollectionMetadata();
        for (String roleName : roleMap.keySet()) {
            sessionFactory.evictCollection(roleName);
        }
        Map<String, ClassMetadata> entityMap = sessionFactory.getAllClassMetadata();
        for (String entityName : entityMap.keySet()) {
            sessionFactory.evictEntity(entityName);
        }
        sessionFactory.evictQueries();
    }
}

From source file:org.springframework.flex.core.io.HibernateConfigProcessor.java

License:Apache License

/**
 * Extracts all {@link ClassMetadata} and {@link CollectionMetadata} from a given {@link SessionFactory} to be 
 * used in determining the types that need a {@link SpringPropertyProxy} registered in {@link #findTypesToRegister()}
 * @param sessionFactory the session factory from which to read metadata
 *///  www . j ava2  s.c o m
@SuppressWarnings("unchecked")
protected void extractHibernateMetadata(SessionFactory sessionFactory) {
    this.classMetadata.addAll(sessionFactory.getAllClassMetadata().values());
    this.collectionMetadata.addAll(sessionFactory.getAllCollectionMetadata().values());
    this.hibernateConfigured = true;
}