Java 类org.hibernate.ejb.Ejb3Configuration 实例源码

项目:eid-applet    文件:PersistenceTest.java   
@Before
public void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Ejb3Configuration configuration = new Ejb3Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    configuration.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
    configuration.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:beta");
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");
    configuration.addAnnotatedClass(SessionContextEntity.class);
    configuration.addAnnotatedClass(TestResultEntity.class);
    configuration.addAnnotatedClass(TestReportEntity.class);
    EntityManagerFactory entityManagerFactory = configuration.buildEntityManagerFactory();

    this.entityManager = entityManagerFactory.createEntityManager();
    this.entityManager.getTransaction().begin();
}
项目:ds4p    文件:SchemaExporter.java   
public static void export(Ejb3Configuration jpaConfiguration, boolean drop,
        boolean create, String outFile, String delimiter,
        Formatter formatter) {

    SchemaGenerator schemaGenerator = new SchemaGenerator(jpaConfiguration);

    if (create) {
        String[] createSQL = schemaGenerator.generateSchemaCreationScript();
        StringArrayFileExporter.export(outFile, delimiter, formatter,
                createSQL);
    }

    if (drop) {
        String[] dropSQL = schemaGenerator.generateDropSchemaScript();
        StringArrayFileExporter.export(outFile, delimiter, formatter,
                dropSQL);
    }
}
项目:mobile-starting-framework    文件:HomeController.java   
/**
 * Controller method to download a ddl.
 */
@Deprecated
@SuppressWarnings({"unchecked", "rawtypes"})
@RequestMapping(value = "ddl", method = RequestMethod.GET)
public void exportDatabaseSchema(HttpServletRequest request, HttpServletResponse response, Model uiModel) {
    PersistenceUnitInfo persistenceUnitInfo = getEntityManagerFactory().getPersistenceUnitInfo();

    Map jpaPropertyMap = getEntityManagerFactory().getJpaPropertyMap();
    jpaPropertyMap.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
    Configuration configuration = new Ejb3Configuration().configure(persistenceUnitInfo, jpaPropertyMap).getHibernateConfiguration();

    SchemaExport schema = new SchemaExport(configuration);
    schema.setFormat(true);
    schema.setDelimiter(";");
    schema.setOutputFile("/tmp/schema.sql");
    schema.create(false, false);
}
项目:billy    文件:SchemaExport.java   
private static void exportSchema(String persistenceUnit, String outputDir, Boolean drop, Boolean create,
        String delemiter) {
    File file = new File(outputDir);
    new File(file.getParent()).mkdirs();

    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure(persistenceUnit, null);
    jpaConfiguration.buildMappings();
    Configuration hibernateConfiguration = jpaConfiguration.getHibernateConfiguration();
    AuditConfiguration.getFor(hibernateConfiguration);
    EnversSchemaGenerator esg = new EnversSchemaGenerator(hibernateConfiguration);
    org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export();
    se.setOutputFile(outputDir);
    se.setFormat(true);
    se.setDelimiter(delemiter);
    se.drop(drop, false);
    se.create(create, false);
}
项目:billy    文件:SchemaExport.java   
private static void exportSchema(String persistenceUnit, String outputDir, Boolean drop, Boolean create,
        String delemiter) {
    File file = new File(outputDir);
    new File(file.getParent()).mkdirs();

    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure(persistenceUnit, null);
    jpaConfiguration.buildMappings();
    Configuration hibernateConfiguration = jpaConfiguration.getHibernateConfiguration();
    AuditConfiguration.getFor(hibernateConfiguration);
    EnversSchemaGenerator esg = new EnversSchemaGenerator(hibernateConfiguration);
    org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export();
    se.setOutputFile(outputDir);
    se.setFormat(true);
    se.setDelimiter(delemiter);
    se.drop(drop, false);
    se.create(create, false);
}
项目:billy    文件:SchemaExport.java   
private static void exportSchema(String persistenceUnit, String outputDir, Boolean drop, Boolean create,
        String delemiter) {
    File file = new File(outputDir);
    new File(file.getParent()).mkdirs();

    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure(persistenceUnit, null);
    jpaConfiguration.buildMappings();
    Configuration hibernateConfiguration = jpaConfiguration.getHibernateConfiguration();
    AuditConfiguration.getFor(hibernateConfiguration);
    EnversSchemaGenerator esg = new EnversSchemaGenerator(hibernateConfiguration);
    org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export();
    se.setOutputFile(outputDir);
    se.setFormat(true);
    se.setDelimiter(delemiter);
    se.drop(drop, false);
    se.create(create, false);
}
项目:fiware-ppl    文件:DaoInitializer.java   
@Override
protected Ejb3Configuration configure(String persistenceUnitName){
    Ejb3Configuration ejb = super.configure(persistenceUnitName);
    ejb 
            .addAnnotatedClass(com.sap.research.primelife.dc.dao.DCResource.class)
            .addAnnotatedClass(com.sap.research.primelife.dc.entity.EventLog.class)
            .addAnnotatedClass(com.sap.research.primelife.dc.entity.OEEStatus.class)
            .addAnnotatedClass(eu.primelife.ppl.pii.impl.PiiUniqueId.class)
            .addAnnotatedClass(eu.primelife.ppl.piih.impl.EventLogged.class)
            .addAnnotatedClass(eu.primelife.ppl.piih.impl.EventLoggedUpdate.class)
            .addAnnotatedClass(eu.primelife.ppl.piih.impl.EventLoggedCreate.class)
            .addAnnotatedClass(eu.primelife.ppl.piih.impl.EventLoggedDownstream.class)
            .addAnnotatedClass(eu.primelife.ppl.piih.impl.EventLoggedDelete.class)
            .addAnnotatedClass(eu.primelife.ppl.piih.impl.EventLoggedAccess.class)
            .addAnnotatedClass(eu.primelife.ppl.piih.impl.PiiLogged.class);

    return ejb;
}
项目:openhds-server    文件:Ejb3SchemaExport.java   
public static void main(String[] args) {
    Ejb3Configuration ejb3Cfg = new Ejb3Configuration();

    // set propeties (these were set based on the persistence.xml file)
    Properties props = new Properties();
    props.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    ejb3Cfg.addProperties(props);

    ejb3Cfg.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);

    // add annotated classes
    ejb3Cfg.addAnnotatedClass(EndUser.class);
    ejb3Cfg.addAnnotatedClass(Individual.class);
    ejb3Cfg.addAnnotatedClass(Location.class);
    ejb3Cfg.addAnnotatedClass(SocialGroup.class);
    ejb3Cfg.addAnnotatedClass(Visit.class);

    Configuration cfg = ejb3Cfg.getHibernateConfiguration();

    SchemaExport se = new SchemaExport(cfg).setOutputFile(RESOURCES_PATH + "specialstudy-schema-ddl.sql");
    se.execute(false, false, false, true);
}
项目:spring4-understanding    文件:SpringHibernateEjbPersistenceProvider.java   
@SuppressWarnings("rawtypes")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
    Ejb3Configuration cfg = new Ejb3Configuration();
    if (info instanceof SmartPersistenceUnitInfo) {
        for (String managedPackage : ((SmartPersistenceUnitInfo) info).getManagedPackages()) {
            cfg.addPackage(managedPackage);
        }
    }
    Ejb3Configuration configured = cfg.configure(info, properties);
    return (configured != null ? configured.buildEntityManagerFactory() : null);
}
项目:unitils    文件:UnitilsHibernatePersistenceProvider.java   
@Override
@SuppressWarnings("unchecked")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) {
    Ejb3Configuration configuration = new Ejb3Configuration();
    hibernateConfiguration = configuration.configure( info, map );
    return hibernateConfiguration != null ? hibernateConfiguration.buildEntityManagerFactory() : null;
}
项目:unitils    文件:HibernateJpaProviderSupport.java   
/**
 * Checks if the mapping of the JPA entities with the database is still correct.
 */
public void assertMappingWithDatabaseConsistent(EntityManager entityManager, Object configurationObject) {
    Ejb3Configuration configuration = (Ejb3Configuration) configurationObject;
    Dialect databaseDialect = getHibernateDatabaseDialect(configuration);

    HibernateAssert.assertMappingWithDatabaseConsistent(configuration.getHibernateConfiguration(), (Session) entityManager.getDelegate(), databaseDialect);
}
项目:unitils    文件:HibernateJpaProviderSupport.java   
/**
 * Gets the database dialect from the Hibernate <code>Ejb3Configuration</code.
 *
 * @param configuration The hibernate config, not null
 * @return the database Dialect, not null
 */
protected Dialect getHibernateDatabaseDialect(Ejb3Configuration configuration) {
    String dialectClassName = configuration.getProperties().getProperty("hibernate.dialect");
    if (isEmpty(dialectClassName)) {
        throw new UnitilsException("Property hibernate.dialect not specified");
    }
    try {
        return (Dialect) Class.forName(dialectClassName).newInstance();
    } catch (Exception e) {
        throw new UnitilsException("Could not instantiate dialect class " + dialectClassName, e);
    }
}
项目:metaworks_framework    文件:EJB3ConfigurationDaoImpl.java   
public Ejb3Configuration getConfiguration() {
    synchronized(this) {
        if (configuration == null) {
            Ejb3Configuration temp = new Ejb3Configuration();
            String previousValue = persistenceUnitInfo.getProperties().getProperty("hibernate.hbm2ddl.auto");
            persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", "none");
            configuration = temp.configure(persistenceUnitInfo, new HashMap());
            configuration.getHibernateConfiguration().buildSessionFactory();
            if (previousValue != null) {
                persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", previousValue);
            }
        }
    }
    return configuration;
}
项目:SparkCommerce    文件:EJB3ConfigurationDaoImpl.java   
public Ejb3Configuration getConfiguration() {
    synchronized(this) {
        if (configuration == null) {
            Ejb3Configuration temp = new Ejb3Configuration();
            String previousValue = persistenceUnitInfo.getProperties().getProperty("hibernate.hbm2ddl.auto");
            persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", "none");
            configuration = temp.configure(persistenceUnitInfo, new HashMap());
            configuration.getHibernateConfiguration().buildSessionFactory();
            if (previousValue != null) {
                persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", previousValue);
            }
        }
    }
    return configuration;
}
项目:blcdemo    文件:EJB3ConfigurationDaoImpl.java   
public Ejb3Configuration getConfiguration() {
    synchronized(this) {
        if (configuration == null) {
            Ejb3Configuration temp = new Ejb3Configuration();
            String previousValue = persistenceUnitInfo.getProperties().getProperty("hibernate.hbm2ddl.auto");
            persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", "none");
            configuration = temp.configure(persistenceUnitInfo, new HashMap());
            configuration.getHibernateConfiguration().buildSessionFactory();
            if (previousValue != null) {
                persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", previousValue);
            }
        }
    }
    return configuration;
}
项目:ds4p    文件:SchemaGenerator.java   
public SchemaGenerator(Ejb3Configuration jpaConfiguration) {
    Assert.notNull(jpaConfiguration, "JpaConfiguration is required.");
    this.jpaConfiguration = jpaConfiguration;

    // This line of code must be called to further do the configuration, so
    // that JSR 303 validation annotations on Entity class can be honored
    jpaConfiguration.buildEntityManagerFactory();

    this.hibernateConfiguration = jpaConfiguration
            .getHibernateConfiguration();

    this.dialect = Dialect.getDialect(hibernateConfiguration
            .getProperties());
}
项目:ds4p    文件:PersistenceXmlConfigSchemaExporter.java   
public static void main(String[] args) {
    boolean drop = false;
    boolean create = false;
    String outFile = null;
    String delimiter = "";
    String persistenceUnitName = null;

    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("--")) {
            if (args[i].equals("--drop")) {
                drop = true;
            } else if (args[i].equals("--create")) {
                create = true;
            } else if (args[i].startsWith("--output=")) {
                outFile = args[i].substring(9);
            } else if (args[i].startsWith("--delimiter=")) {
                delimiter = args[i].substring(12);
            } else if (args[i].startsWith("--persistenceUnitName=")){
                persistenceUnitName = args[i].substring(22);
            }
        }
    }

    Formatter formatter = FormatStyle.DDL.getFormatter();

    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure(
            persistenceUnitName, null);

    SchemaExporter.export(jpaConfiguration, drop, create, outFile, delimiter, formatter);
}
项目:carbon-business-process    文件:HTCoordinationDAOConnectionFactoryImpl.java   
@Override
public void init() {

    JPAVendorAdapter vendorAdapter = getJPAVendorAdapter();
    Ejb3Configuration cfg = new Ejb3Configuration();
    cfg.addAnnotatedClass(HTProtocolHandler.class);
    this.entityManagerFactory = cfg.createEntityManagerFactory(vendorAdapter.getJpaPropertyMap(null));

}
项目:carbon-business-process    文件:AttachmentMgtDAOConnectionFactoryImpl.java   
@Override
public void init() {
    if (transactionManager == null) {
        log.debug("Transaction-Manager is not initialized before initializing entityManager. So internal " +
                "transaction-manager in entity manager will be used.");
    }

    org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.JPAVendorAdapter vendorAdapter = getJPAVendorAdapter();
    // Note: It is recommended to use javax.persistence.Persistence.createEntityManagerFactory() to create
    // EntityManagerFactory. But it is failing in OSGI environment. So we used Ejb3Configuration, but it is deprecated.
    Ejb3Configuration cfg = new Ejb3Configuration();
    cfg.addAnnotatedClass(AttachmentDAOImpl.class);
    this.entityManagerFactory = cfg.createEntityManagerFactory(vendorAdapter.getJpaPropertyMap(null));
}
项目:TechnologyReadinessTool    文件:HibernateExtendedPersistenceProvider.java   
@Override
public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
    Ejb3Configuration cfg = new Ejb3Configuration();
    setupConfiguration(cfg);
    Ejb3Configuration configured = cfg.configure(persistenceUnitName, properties);
    return configured != null ? configured.buildEntityManagerFactory() : null;
}
项目:TechnologyReadinessTool    文件:HibernateExtendedPersistenceProvider.java   
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
    Ejb3Configuration cfg = new Ejb3Configuration();
    setupConfiguration(cfg);
    Ejb3Configuration configured = cfg.configure(info, properties);
    return configured != null ? configured.buildEntityManagerFactory() : null;
}
项目:gort-public    文件:GortEntityManager.java   
public synchronized EntityManagerFactory getEntityManagerFactory() {
    if (factory == null) {
        //factory = Persistence.createEntityManagerFactory(unitName, properties);

        // removed the reliance on hibernate.cfg.xml completely as we sometimes
        // hibernate could not fine the file
        // .configure("org/cmuchimps/gort/modules/dataobject/hibernate.cfg.xml")
        Ejb3Configuration cfg = new Ejb3Configuration();
        factory = cfg.addProperties(properties).addAnnotatedClass(Activity.class)
                .addAnnotatedClass(Annotation.class)
                .addAnnotatedClass(App.class)
                .addAnnotatedClass(Assignment.class)
                .addAnnotatedClass(Component.class)
                .addAnnotatedClass(CrowdTask.class)
                .addAnnotatedClass(Heuristic.class)
                .addAnnotatedClass(History.class)
                .addAnnotatedClass(HIT.class)
                .addAnnotatedClass(Interaction.class)
                .addAnnotatedClass(Library.class)
                .addAnnotatedClass(Permission.class)
                .addAnnotatedClass(Provider.class)
                .addAnnotatedClass(Receiver.class)
                .addAnnotatedClass(Screenshot.class)
                .addAnnotatedClass(Sequence.class)
                .addAnnotatedClass(Service.class)
                .addAnnotatedClass(Server.class)
                .addAnnotatedClass(State.class)
                .addAnnotatedClass(TaintLog.class)
                .addAnnotatedClass(Traversal.class)
                .buildEntityManagerFactory();
        factories.add(factory);
    }

    return factory;
}
项目:kuali_rice    文件:DevHibernatePersistence.java   
private Ejb3Configuration configure(PersistenceUnitInfo info, Map map) throws IOException {     
    Ejb3Configuration configured = new Ejb3Configuration().configure(info, map);
    if (useSerialization) {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(serializationFilename));
        oos.writeObject(configured);
        oos.close();
    }
    return configured;
}
项目:ds4p    文件:SpringEntityManagerFactoryBeanConfigSchemaExporter.java   
public static void main(String[] args) {
    boolean drop = false;
    boolean create = false;
    String outFile = null;
    String delimiter = "";
    String activeSpringProfile = null;
    String dataAccessApplicationContextConfigClassPath = null;

    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("--")) {
            if (args[i].equals("--drop")) {
                drop = true;
            } else if (args[i].equals("--create")) {
                create = true;
            } else if (args[i].startsWith("--output=")) {
                outFile = args[i].substring(9);
            } else if (args[i].startsWith("--delimiter=")) {
                delimiter = args[i].substring(12);
            } else if (args[i].startsWith("--activeSpringProfile=")) {
                activeSpringProfile = args[i].substring(22);
            } else if (args[i].startsWith("--dataAccessApplicationContextConfigClassPath=")) {
                dataAccessApplicationContextConfigClassPath = args[i].substring(46);
            }

        }
    }

    Formatter formatter = FormatStyle.DDL.getFormatter();

    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    if (activeSpringProfile != null) {
        context.getEnvironment().setActiveProfiles(activeSpringProfile);
    }

    context.load(dataAccessApplicationContextConfigClassPath);

    context.refresh();

    AbstractEntityManagerFactoryBean bean = context
            .getBean(AbstractEntityManagerFactoryBean.class);

    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure(
            bean.getPersistenceUnitInfo(), bean.getJpaPropertyMap());

    SchemaExporter.export(jpaConfiguration, drop, create, outFile, delimiter, formatter);

    context.close();
}
项目:TechnologyReadinessTool    文件:HibernateExtendedPersistenceProvider.java   
private void setupConfiguration(Ejb3Configuration cfg) {
    cfg.getEventListeners().setPreUpdateEventListeners(preUpdateEventListeners);
    cfg.getEventListeners().setPreInsertEventListeners(preInsertEventListeners);
}
项目:needle4j    文件:EJB3Configuration.java   
private static EntityManagerFactory createEntityManagerFactory(final Class<?>[] entityClasses) {
    final Ejb3Configuration cfg = new Ejb3Configuration();

    // add a regular hibernate.cfg.xml
    cfg.configure(PropertyBasedConfigurationFactory.get().getHibernateCfgFilename());

    for (final Class<?> clazz : entityClasses) {
        cfg.addAnnotatedClass(clazz);
    }

    return cfg.buildEntityManagerFactory();

}
项目:unitils    文件:UnitilsHibernatePersistenceProvider.java   
/**
 * Should not be used until after creating the <code>EntityManagerFactory</code> using 
 * {@link #createContainerEntityManagerFactory}
 * 
 * @return The hibernate configuration object that was used for configuring the <code>EntityManagerFactory</code>.
 */
public Ejb3Configuration getHibernateConfiguration() {
    return hibernateConfiguration;
}
项目:metaworks_framework    文件:EJB3ConfigurationDao.java   
public abstract Ejb3Configuration getConfiguration();
项目:SparkCommerce    文件:EJB3ConfigurationDao.java   
public abstract Ejb3Configuration getConfiguration();
项目:blcdemo    文件:EJB3ConfigurationDao.java   
public abstract Ejb3Configuration getConfiguration();