org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl Java Examples

The following examples show how to use org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LongToNumericTypeTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    PersistenceUnitInfoImpl persistenceUnitInfo = new PersistenceUnitInfoImpl(
            LongToNumericTypeTest.class.getName(),
            Collections.singletonList( Event.class.getName() ),
            validateProperties()
    );

    Map<String, Object> configuration = new HashMap<>();
    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
            new PersistenceUnitInfoDescriptor( persistenceUnitInfo), configuration
    );
    EntityManagerFactory emf = null;
    try {
        emf = entityManagerFactoryBuilder.build();
    }
    finally {
        if ( emf != null ) {
            emf.close();
        }
    }
}
 
Example #2
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(AvailableSettings.INTERCEPTOR, interceptor());
    final Integrator integrator = integrator();
    if (integrator != null) {
        configuration.put(
            "hibernate.integrator_provider",
            new IntegratorProvider() {
                @Override
                public List<Integrator> getIntegrators() {
                    return Collections.singletonList(integrator);
                }
            }
        );
    }

    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
            new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration
    );
    return entityManagerFactoryBuilder.build();
}
 
Example #3
Source File: FastBootMetadataBuilder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Greatly simplified copy of
 * org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl#populate(org.hibernate.boot.MetadataBuilder,
 * org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.MergedSettings,
 * org.hibernate.boot.registry.StandardServiceRegistry, java.util.List)
 */
protected void populate(MetadataBuilder metamodelBuilder, List<CacheRegionDefinition> cacheRegionDefinitions,
        StandardServiceRegistry ssr) {

    ((MetadataBuilderImplementor) metamodelBuilder).getBootstrapContext().markAsJpaBootstrap();

    metamodelBuilder.applyScanEnvironment(new StandardJpaScanEnvironmentImpl(persistenceUnit));
    metamodelBuilder.applyScanOptions(new StandardScanOptions(
            (String) buildTimeSettings.get(org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY),
            persistenceUnit.isExcludeUnlistedClasses()));

    if (cacheRegionDefinitions != null) {
        cacheRegionDefinitions.forEach(metamodelBuilder::applyCacheRegionDefinition);
    }

    final TypeContributorList typeContributorList = (TypeContributorList) buildTimeSettings
            .get(EntityManagerFactoryBuilderImpl.TYPE_CONTRIBUTORS);
    if (typeContributorList != null) {
        typeContributorList.getTypeContributors().forEach(metamodelBuilder::applyTypes);
    }
}
 
Example #4
Source File: AbstractTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map configuration = properties();
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.put(AvailableSettings.INTERCEPTOR, interceptor);
    }
    Integrator integrator = integrator();
    if (integrator != null) {
        configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator));
    }

    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
        new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration
    );
    return entityManagerFactoryBuilder.build();
}
 
Example #5
Source File: Bootstrap.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Intended for use in Hibernate tests
 *
 * @param persistenceXmlUrl The URL to a persistence.xml
 * @param persistenceUnitName The name of the persistence-unit to parse
 * @param integration setting overrides
 *
 * @return The EMFB
 */
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
		URL persistenceXmlUrl,
		String persistenceUnitName,
		PersistenceUnitTransactionType transactionType,
		Map integration) {
	;
	return new EntityManagerFactoryBuilderImpl(
			PersistenceXmlParser.parse( persistenceXmlUrl, transactionType, integration ).get( persistenceUnitName ),
			integration
	);
}
 
Example #6
Source File: SpringHibernateJpaPersistenceProvider.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
	final List<String> mergedClassesAndPackages = new ArrayList<String>(info.getManagedClassNames());
	if (info instanceof SmartPersistenceUnitInfo) {
		mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages());
	}
	return new EntityManagerFactoryBuilderImpl(
			new PersistenceUnitInfoDescriptor(info) {
				@Override
				public List<String> getManagedClassNames() {
					return mergedClassesAndPackages;
				}
			}, properties).build();
}
 
Example #7
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<String, Object>();

    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
            new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration
    );
    return entityManagerFactoryBuilder.build();
}
 
Example #8
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<>();
    configuration.put(AvailableSettings.INTERCEPTOR, interceptor());
    Integrator integrator = integrator();
    if (integrator != null) {
        configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator));
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.put("hibernate.type_contributors", (TypeContributorList) () -> {
            List<TypeContributor> typeContributors = new ArrayList<>();

            for (Type additionalType : additionalTypes) {
                if (additionalType instanceof BasicType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((BasicType) additionalType));


                } else if (additionalType instanceof UserType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((UserType) additionalType));
                } else if (additionalType instanceof CompositeUserType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((CompositeUserType) additionalType));
                }
            }
            return typeContributors;
        });
    }

    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
            new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration
    );
    return entityManagerFactoryBuilder.build();
}
 
Example #9
Source File: PostgreSQLJsonNodeTypeTest.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
protected void additionalProperties(Properties properties) {
    properties.put(
        EntityManagerFactoryBuilderImpl.METADATA_BUILDER_CONTRIBUTOR,
        (MetadataBuilderContributor) metadataBuilder -> metadataBuilder.applyBasicType(
            JsonNodeBinaryType.INSTANCE
        )
    );
}
 
Example #10
Source File: AbstractTest.java    From hibernate-master-class with Apache License 2.0 5 votes vote down vote up
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = new PersistenceUnitInfoImpl(
        getClass().getSimpleName(), entityClassNames(), getProperties()
    );

    Map<String, Object> configuration = new HashMap<>();
    configuration.put(org.hibernate.jpa.AvailableSettings.INTERCEPTOR, interceptor());
    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
        new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration
    );
    return entityManagerFactoryBuilder.build();
}
 
Example #11
Source File: SpringHibernateJpaPersistenceProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
	final List<String> mergedClassesAndPackages = new ArrayList<String>(info.getManagedClassNames());
	if (info instanceof SmartPersistenceUnitInfo) {
		mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages());
	}
	return new EntityManagerFactoryBuilderImpl(
			new PersistenceUnitInfoDescriptor(info) {
				@Override
				public List<String> getManagedClassNames() {
					return mergedClassesAndPackages;
				}
			}, properties).build();
}
 
Example #12
Source File: SpringHibernateJpaPersistenceProvider.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
	final List<String> mergedClassesAndPackages = new ArrayList<>(info.getManagedClassNames());
	if (info instanceof SmartPersistenceUnitInfo) {
		mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages());
	}
	return new EntityManagerFactoryBuilderImpl(
			new PersistenceUnitInfoDescriptor(info) {
				@Override
				public List<String> getManagedClassNames() {
					return mergedClassesAndPackages;
				}
			}, properties).build();
}
 
Example #13
Source File: AbstractTest.java    From hypersistence-optimizer with Apache License 2.0 5 votes vote down vote up
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(AvailableSettings.INTERCEPTOR, interceptor());

    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
        new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration
    );
    return entityManagerFactoryBuilder.build();
}
 
Example #14
Source File: SpringHibernateJpaPersistenceProvider.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
	final List<String> mergedClassesAndPackages = new ArrayList<>(info.getManagedClassNames());
	if (info instanceof SmartPersistenceUnitInfo) {
		mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages());
	}
	return new EntityManagerFactoryBuilderImpl(
			new PersistenceUnitInfoDescriptor(info) {
				@Override
				public List<String> getManagedClassNames() {
					return mergedClassesAndPackages;
				}
			}, properties).build();
}
 
Example #15
Source File: JpaEntityManagerFactory.java    From tutorials with MIT License 4 votes vote down vote up
protected EntityManagerFactory getEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = getPersistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<>();
    return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration)
      .build();
}
 
Example #16
Source File: JpaEntityManagerFactory.java    From tutorials with MIT License 4 votes vote down vote up
protected EntityManagerFactory getEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = getPersistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<>();
    return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration)
      .build();
}
 
Example #17
Source File: HibernateJpaEntityManagerFactory.java    From we-cmdb with Apache License 2.0 4 votes vote down vote up
public EntityManagerFactory getEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = getPersistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<>();
    return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration, new CiClassLoaderService(classLoader)).build();
}
 
Example #18
Source File: Bootstrap.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
		PersistenceUnitDescriptor persistenceUnitDescriptor,
		Map integration,
		ClassLoaderService providedClassLoaderService) {
	return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoaderService );
}
 
Example #19
Source File: Bootstrap.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
		PersistenceUnitDescriptor persistenceUnitDescriptor,
		Map integration,
		ClassLoader providedClassLoader) {
	return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoader );
}
 
Example #20
Source File: Bootstrap.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
		PersistenceUnitDescriptor persistenceUnitDescriptor,
		Map integration) {
	return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration );
}
 
Example #21
Source File: DatabaseImpl.java    From jweb-cms with GNU Affero General Public License v3.0 4 votes vote down vote up
private EntityManagerFactory createEMF() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo();
    Map<String, Object> configuration = new HashMap<>();
    return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration).build();
}