Java 类org.hibernate.jpa.internal.EntityManagerFactoryImpl 实例源码

项目:sdcct    文件:SdcctEntityManagerFactoryFactoryBean.java   
@Override
public EntityManagerFactoryImpl build() {
    SessionFactoryImpl sessionFactory =
        ((SessionFactoryImpl) (SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory = ((EntityManagerFactoryImpl) super.build()))
            .getSessionFactory());
    StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();

    serviceRegistry.getService(EntityManagerFactoryRef.class).setEntityManagerFactory(SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory);

    ContextHelper.getSearchintegratorBySFI(sessionFactory).getIndexBindings().replaceAll((entityClass, entityIndexBinding) -> {
        MutableEntityIndexBinding newEntityIndexBinding =
            new DefaultMutableEntityIndexBinding(entityIndexBinding.getSelectionStrategy(), entityIndexBinding.getSimilarity(),
                entityIndexBinding.getIndexManagers(), SdcctEntityManagerFactoryFactoryBean.this.entityIndexingInterceptor);
        newEntityIndexBinding.setDocumentBuilderIndexedEntity(entityIndexBinding.getDocumentBuilder());

        return newEntityIndexBinding;
    });

    serviceRegistry.getService(DbMetadataService.class);

    return SdcctEntityManagerFactoryFactoryBean.this.entityManagerFactory;
}
项目:oscm    文件:TestPersistence.java   
private EntityManagerFactory buildEntityManagerFactory(ITestDB testDb,
        String unitName) throws Exception {
    Map<Object, Object> properties = new HashMap<Object, Object>();
    properties.put(Environment.HBM2DDL_AUTO, "");
    properties.put(Environment.DATASOURCE, createManagedDataSource(testDb
            .getDataSource()));
    properties.put("hibernate.search.autoregister_listeners", System.getProperty("hibernate.search.autoregister_listeners"));
    properties.put("hibernate.transaction.jta.platform", "org.hibernate.service.jta.platform.internal.SunOneJtaPlatform");
    properties.put("hibernate.id.new_generator_mappings", "false");
    properties.put("org.hibernate.SQL", "false");
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(unitName, properties);
    sf = ((EntityManagerFactoryImpl) entityManagerFactory).getSessionFactory();
    return entityManagerFactory;
}
项目:mojito    文件:HibernateEventListenerConfig.java   
@PostConstruct
public void registerListeners() {
    EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) lcemfb.getNativeEntityManagerFactory();
    SessionFactoryImpl sf = emf.getSessionFactory();
    EventListenerRegistry registry = (EventListenerRegistry)sf.getServiceRegistry().getService(EventListenerRegistry.class);
    registry.getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(entityCrudEventListener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(entityCrudEventListener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(entityCrudEventListener);
}
项目:mojito    文件:DDLGenerator.java   
@Test
public void generateCreateAnUpdateDDL() throws IOException {
    logger.debug("Generate create and update DDL");

    EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) lcemfb.getNativeEntityManagerFactory();
    SessionFactoryImpl sf = emf.getSessionFactory();
    SessionFactoryServiceRegistryImpl serviceRegistry = (SessionFactoryServiceRegistryImpl) sf.getServiceRegistry();
    Configuration cfg = null;

    try {
        Field field = SessionFactoryServiceRegistryImpl.class.getDeclaredField("configuration");
        field.setAccessible(true);
        cfg = (Configuration) field.get(serviceRegistry);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }

    Files.createDirectories(Paths.get("target/db/migration/"));

    SchemaUpdate update = new SchemaUpdate(serviceRegistry, cfg);
    update.setDelimiter(";");
    update.setOutputFile("target/db/migration/Vx__yy_zz.sql");
    update.execute(false, false);

    SchemaExport export = new SchemaExport(serviceRegistry, cfg);
    export.setDelimiter(";");
    export.setOutputFile("target/db/migration/create.sql");
    export.execute(false, false, false, true);     
}
项目:development    文件:TestPersistence.java   
private EntityManagerFactory buildEntityManagerFactory(ITestDB testDb,
        String unitName) throws Exception {
    Map<Object, Object> properties = new HashMap<Object, Object>();
    properties.put(Environment.HBM2DDL_AUTO, "");
    properties.put(Environment.DATASOURCE, createManagedDataSource(testDb
            .getDataSource()));
    properties.put("hibernate.search.autoregister_listeners", System.getProperty("hibernate.search.autoregister_listeners"));
    properties.put("hibernate.transaction.jta.platform", "org.hibernate.service.jta.platform.internal.SunOneJtaPlatform");
    properties.put("hibernate.id.new_generator_mappings", "false");
    properties.put("org.hibernate.SQL", "false");
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(unitName, properties);
    sf = ((EntityManagerFactoryImpl) entityManagerFactory).getSessionFactory();
    return entityManagerFactory;
}
项目:persistence    文件:HibernatePersistenceProviderWithGenericDatatypeSupport.java   
/**
 * {@inheritDoc}
 */
@Override
public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {

  LOGGER.trace("Starting createEntityManagerFactory for persistenceUnitName {}", persistenceUnitName);

  try {
    final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull(persistenceUnitName, properties);
    if (builder == null) {
      LOGGER.trace("Could not obtain matching EntityManagerFactoryBuilder, returning null");
      return null;
    } else {
      EntityManagerFactoryImpl impl = (EntityManagerFactoryImpl) builder;
      TypeResolver typeResolver = impl.getSessionFactory().getTypeResolver();
      return builder.build();
    }
  } catch (PersistenceException pe) {
    throw pe;
  } catch (Exception e) {
    LOGGER.debug("Unable to build entity manager factory", e);
    throw new PersistenceException("Unable to build entity manager factory", e);
  }
  // EntityManagerFactory entityManagerFactory = super.createEntityManagerFactory(persistenceUnitName,
  // properties);
  // if (entityManagerFactory instanceof EntityManagerFactoryImpl) {
  // SessionFactoryImpl sessionFactory = ((EntityManagerFactoryImpl)
  // entityManagerFactory).getSessionFactory();
  // TypeResolver typeResolver = sessionFactory.getTypeResolver();
  // // typeResolver.registerTypeOverride(type, keys);
  // }
  // return entityManagerFactory;
}
项目:sdcct    文件:DbMetadataServiceImpl.java   
@Override
public EntityManagerFactoryImpl getEntityManagerFactory() {
    return this.entityManagerFactory;
}
项目:sdcct    文件:EntityManagerFactoryRefImpl.java   
@Override
public EntityManagerFactoryImpl getEntityManagerFactory() {
    return this.entityManagerFactory;
}
项目:sdcct    文件:EntityManagerFactoryRefImpl.java   
@Override
public void setEntityManagerFactory(EntityManagerFactoryImpl entityManagerFactory) {
    this.entityManagerFactory = entityManagerFactory;
}
项目:switchyard    文件:EntityManagerImpl.java   
public EntityManagerImpl(EntityManagerFactoryImpl entityManagerFactory, PersistenceContextType pcType, SynchronizationType synchronizationType, PersistenceUnitTransactionType transactionType, boolean discardOnClose, Class sessionInterceptorClass, Map properties) {
    super(entityManagerFactory, pcType, synchronizationType, transactionType, discardOnClose, sessionInterceptorClass, properties);
}
项目:croquet    文件:CroquetPersistService.java   
@Override
public void start() {
    if(null != entityManagerFactory) {
        throw new IllegalStateException("Persistence service was already initialized.");
    }

    final Configuration configuration = new Configuration();

    //
    // We'll want to map these to settings
    //
    configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
    configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, TRUE_STRING);
    configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, TRUE_STRING);
    configuration.setProperty(AvailableSettings.ORDER_UPDATES, TRUE_STRING);
    configuration.setProperty(AvailableSettings.ORDER_INSERTS, TRUE_STRING);
    configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, TRUE_STRING);
    configuration.setProperty("jadira.usertype.autoRegisterUserTypes", TRUE_STRING);
    configuration.setProperty(AvailableSettings.DIALECT, settings.getDatabaseSettings().getDialectClass());

    // turn on and off features based upon log level
    if(LOG.isDebugEnabled()) {
        configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, TRUE_STRING);
        configuration.setProperty(AvailableSettings.SHOW_SQL, TRUE_STRING);
    } else {
        configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, FALSE_STRING);
        configuration.setProperty(AvailableSettings.SHOW_SQL, FALSE_STRING);
    }

    // add in all the entities
    for (final Class<? extends Serializable> entity : settings.getDatabaseSettings().getEntities()) {
        LOG.debug("Adding entity: {}", entity.getCanonicalName());
        configuration.addAnnotatedClass(entity);
    }

    final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
        .applySettings(configuration.getProperties())
        // set our connection provider
        .addService(ConnectionProvider.class, connectionProvider)
        .build();

    // create the actual entity manager
    this.entityManagerFactory = new EntityManagerFactoryImpl(PersistenceUnitTransactionType.RESOURCE_LOCAL,
                                                             false,
                                                             null,
                                                             configuration,
                                                             serviceRegistry,
                                                             persistenceUnitName);

}
项目:sdcct    文件:DbMetadataService.java   
public EntityManagerFactoryImpl getEntityManagerFactory();
项目:sdcct    文件:EntityManagerFactoryRef.java   
public EntityManagerFactoryImpl getEntityManagerFactory();
项目:sdcct    文件:EntityManagerFactoryRef.java   
public void setEntityManagerFactory(EntityManagerFactoryImpl entityManagerFactory);