Example usage for javax.persistence EntityManagerFactory getCache

List of usage examples for javax.persistence EntityManagerFactory getCache

Introduction

In this page you can find the example usage for javax.persistence EntityManagerFactory getCache.

Prototype

public Cache getCache();

Source Link

Document

Access the cache that is associated with the entity manager factory (the "second level cache").

Usage

From source file:com.impetus.kundera.persistence.EntityManagerImpl.java

/**
 * Instantiates a new entity manager impl.
 * /*from  w  w w  .j  a v a  2 s .  co  m*/
 * @param factory
 *            the factory
 */
EntityManagerImpl(final EntityManagerFactory factory, final PersistenceUnitTransactionType transactionType,
        final PersistenceContextType persistenceContextType) {
    this.factory = factory;

    if (logger.isDebugEnabled()) {
        logger.debug("Creating EntityManager for persistence unit : " + getPersistenceUnit());
    }
    this.persistenceContextType = persistenceContextType;

    this.persistenceCache = new PersistenceCache((Cache) factory.getCache());
    this.persistenceCache.setPersistenceContextType(this.persistenceContextType);

    this.transactionType = transactionType;
    this.persistenceDelegator = new PersistenceDelegator(
            ((EntityManagerFactoryImpl) this.factory).getKunderaMetadataInstance(), this.persistenceCache);

    for (String pu : ((EntityManagerFactoryImpl) this.factory).getPersistenceUnits()) {
        this.persistenceDelegator.loadClient(pu, discoverClient(pu));
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Created EntityManager for persistence unit : " + getPersistenceUnit());
    }
}