Example usage for javax.persistence Persistence createEntityManagerFactory

List of usage examples for javax.persistence Persistence createEntityManagerFactory

Introduction

In this page you can find the example usage for javax.persistence Persistence createEntityManagerFactory.

Prototype

public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) 

Source Link

Document

Create and return an EntityManagerFactory for the named persistence unit using the given properties.

Usage

From source file:org.apache.ode.dao.jpa.hibernate.BpelDAOConnectionFactoryImpl.java

public void init(Properties odeConfig, TransactionManager txm, Object env) {
    this._txm = txm;
    this._ds = (DataSource) env;
    Map emfProperties = HibernateUtil.buildConfig(OdeConfigProperties.PROP_DAOCF + ".", odeConfig, _txm, _ds);
    _emf = Persistence.createEntityManagerFactory("ode-bpel", emfProperties);

    // dirty hack
    odeConfig.put("ode.emf", _emf);

}

From source file:com.srotya.tau.api.dao.alertreceiver.DatabaseResource.java

@Override
protected void before() throws Throwable {
    java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.OFF);
    Properties config = new Properties(System.getProperties());
    File db = new File(TARGET_RULES_DB);
    if (db.exists()) {
        FileUtils.deleteDirectory(db);/*ww  w. ja v  a 2s  .com*/
    }
    config.setProperty("javax.persistence.jdbc.url", CONNECTION_STRING);
    try {
        emf = Persistence.createEntityManagerFactory("tau", config);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

    EntityManager em = emf.createEntityManager();

    RuleGroup ruleGroup = new RuleGroup();
    ruleGroup.setRuleGroupId("all");
    ruleGroup.setRuleGroupName("all");
    RuleGroupManager.getInstance().createRuleGroup(em, ruleGroup);
}

From source file:org.apache.ode.dao.jpa.hibernate.ConfStoreDAOConnectionFactoryImpl.java

public void init(Properties odeConfig, TransactionManager txm, Object env) {
    this._txm = txm;
    this._ds = (DataSource) env;
    Map emfProperties = HibernateUtil.buildConfig(OdeConfigProperties.PROP_DAOCF_STORE + ".", odeConfig, _txm,
            _ds);//from   w  w  w.  j a  v  a 2  s  .c  o  m
    _emf = Persistence.createEntityManagerFactory("ode-store", emfProperties);
}

From source file:org.apache.ode.dao.jpa.hibernate.SchedulerDAOConnectionFactoryImpl.java

public void init(Properties odeConfig, TransactionManager txm, Object env) {
    this._txm = txm;
    this._ds = (DataSource) env;
    Map emfProperties = HibernateUtil.buildConfig(OdeConfigProperties.PROP_DAOCF_SCHEDULER + ".", odeConfig,
            _txm, _ds);//w w w.j a  v a2 s  .  c  o m
    _emf = Persistence.createEntityManagerFactory("ode-scheduler", emfProperties);
}

From source file:com.chiralbehaviors.seurat.service.DemoScenarioTest.java

@BeforeClass
public static void createEMF() throws IOException, SQLException {
    if (emf == null) {
        InputStream is = ModelTest.class.getResourceAsStream("/jpa.properties");
        assertNotNull("jpa properties missing", is);
        Properties properties = new Properties();
        properties.load(is);// w  ww. j a v a 2  s . co  m
        System.out.println(
                String.format("Database URL: %s", properties.getProperty("javax.persistence.jdbc.url")));
        emf = Persistence.createEntityManagerFactory(WellKnownObject.CORE, properties);
    }
}

From source file:io.symcpe.hendrix.api.dao.TestTenantManager.java

@BeforeClass
public static void beforeClass() throws Exception {
    Properties config = new Properties(System.getProperties());
    File db = new File(TARGET_RULES_DB);
    if (db.exists()) {
        FileUtils.deleteDirectory(db);//w ww .jav a2s  . c  o m
    }
    config.setProperty("javax.persistence.jdbc.url", CONNECTION_STRING);
    try {
        emf = Persistence.createEntityManagerFactory("hendrix", config);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:org.seedstack.jpa.internal.JpaPluginTest.java

public void mockPersistenceCreateEntityManagerFactory() {
    mockStatic(Persistence.class);
    when(Persistence.createEntityManagerFactory("hsql-in-memory", getProperties()))
            .thenReturn(mock(EntityManagerFactory.class));
}

From source file:org.ualerts.testing.jpa.EntityManagerFactoryUtil.java

private static EntityManagerFactory createEntityManagerFactory(Properties properties, String unit,
        String propertiesResource) throws PersistenceException {
    try {/*from   w w w  .  j  a  v  a  2  s .co m*/
        return Persistence.createEntityManagerFactory(unit, properties);
    } catch (PersistenceException ex) {
        System.err.println("Cannot create persistence unit '" + unit + "'.");
        System.err.println("Make sure the '" + PERSISTENCE_UNIT_PROPERTY + "' property is specified in "
                + propertiesResource);
        System.err.println("and try cleaning the project.");
        throw ex;
    }
}

From source file:org.apache.ode.store.jpa.DbConfStoreConnectionFactory.java

@SuppressWarnings("unchecked")
public DbConfStoreConnectionFactory(DataSource ds, boolean createDatamodel, String txFactoryClassName) {
    _ds = ds;//ww w. j a v a  2  s  .c  o m
    initTxMgr(txFactoryClassName);

    HashMap<String, Object> propMap = new HashMap<String, Object>();
    propMap.put("openjpa.Log", "commons");
    propMap.put("openjpa.ManagedRuntime", new JpaTxMgrProvider(_txMgr));
    propMap.put("openjpa.ConnectionFactory", _ds);
    propMap.put("openjpa.ConnectionFactoryMode", "managed");
    propMap.put("openjpa.FlushBeforeQueries", "false");
    propMap.put("openjpa.FetchBatchSize", 1000);
    //propMap.put("openjpa.jdbc.TransactionIsolation", "read-committed");
    propMap.put("javax.persistence.provider", "org.apache.openjpa.persistence.PersistenceProviderImpl");

    if (createDatamodel)
        propMap.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=false)");

    _emf = Persistence.createEntityManagerFactory("ode-store", propMap);
}

From source file:org.apache.shindig.social.opensocial.jpa.hibernate.Bootstrap.java

public void init(String unitName) {

    Map<String, String> properties = Maps.newHashMap();

    LOG.info("Starting connection manager with properties " + properties);

    EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(unitName, properties);
    entityManager = emFactory.createEntityManager();
}