Example usage for org.springframework.orm.jpa SharedEntityManagerCreator createSharedEntityManager

List of usage examples for org.springframework.orm.jpa SharedEntityManagerCreator createSharedEntityManager

Introduction

In this page you can find the example usage for org.springframework.orm.jpa SharedEntityManagerCreator createSharedEntityManager.

Prototype

public static EntityManager createSharedEntityManager(EntityManagerFactory emf) 

Source Link

Document

Create a transactional EntityManager proxy for the given EntityManagerFactory.

Usage

From source file:cn.guoyukun.spring.jpa.repository.RepositoryHelper.java

public static void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
    entityManager = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
}

From source file:org.fornax.cartridges.sculptor.framework.test.AbstractDbUnitJpaTests.java

@PersistenceUnit
public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
    this.entityManager = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
}

From source file:org.jasig.cas.ticket.registry.support.JpaLockingStrategyTests.java

private LockingStrategy newLockTxProxy(final String appId, final String uniqueId, final int ttl) {
    final JpaLockingStrategy lock = new JpaLockingStrategy();
    lock.entityManager = SharedEntityManagerCreator.createSharedEntityManager(factory);
    lock.setApplicationId(appId);//from w w  w.j a  va2 s.  co  m
    lock.setUniqueId(uniqueId);
    lock.setLockTimeout(ttl);
    return (LockingStrategy) Proxy.newProxyInstance(JpaLockingStrategy.class.getClassLoader(),
            new Class[] { LockingStrategy.class }, new TransactionalLockInvocationHandler(lock));
}

From source file:edu.vt.middleware.gator.JpaConfigManager.java

/**
 * Creates an entity manager from the factory.
 *
 * @return  New entity manager.// ww  w  . ja  va 2  s. c om
 */
protected EntityManager getEntityManager() {
    // Gets the thread-bound entity manager or creates a new one
    // if none is bound to current thread
    return SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
}

From source file:org.lightadmin.core.config.bootstrap.LightAdminBeanDefinitionRegistryPostProcessor.java

private EntityManager findEntityManager(WebApplicationContext rootContext) {
    EntityManagerFactory entityManagerFactory = EntityManagerFactoryUtils.findEntityManagerFactory(rootContext,
            null);/*from w w w  . j  av  a2s.  c om*/

    return SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
}

From source file:org.kuali.student.common.util.jpa.LoadSqlListener.java

private void process(String entityKey, String sqlFileName) {
    EntityManagerFactory emf = EntityManagerFactoryUtils.findEntityManagerFactory(applicationContext,
            entityKey);//  w  ww. j  a  v  a 2 s.  c  o m
    EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);

    File sqlFile;
    BufferedReader in;
    try {
        if (sqlFileName.startsWith("classpath:")) {
            sqlFile = new ClassPathResource(sqlFileName.substring("classpath:".length())).getFile();
        } else {
            sqlFile = new File(sqlFileName);
        }
        in = new BufferedReader(new FileReader(sqlFile));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    String ln = "";

    TransactionDefinition txDefinition = new DefaultTransactionDefinition();
    TransactionStatus txStatus = jtaTxManager.getTransaction(txDefinition);

    try {
        while ((ln = in.readLine()) != null) {
            if (!ln.startsWith("/") && !ln.startsWith("--") && StringUtils.isNotBlank(ln)) {
                ln = ln.replaceFirst("[;/]\\s*$", "");
                em.createNativeQuery(ln).executeUpdate();
            }
        }
        jtaTxManager.commit(txStatus);
    } catch (Exception e) {
        logger.error("Error loading sql file " + sqlFileName + ". Failing statement was '" + ln + "'", e);
        jtaTxManager.rollback(txStatus);
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            logger.error("IO Stream closed " + e);
        }
    }
}