use of org.hibernate.boot.model.TypeContributor in project hibernate-orm by hibernate.
the class OsgiSessionFactoryService method buildSessionFactory.
private Object buildSessionFactory(Bundle requestingBundle, OsgiClassLoader osgiClassLoader) {
final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder();
bsrBuilder.applyClassLoaderService(new OSGiClassLoaderServiceImpl(osgiClassLoader, osgiServiceUtil));
final Integrator[] integrators = osgiServiceUtil.getServiceImpls(Integrator.class);
for (Integrator integrator : integrators) {
bsrBuilder.applyIntegrator(integrator);
}
final StrategyRegistrationProvider[] strategyRegistrationProviders = osgiServiceUtil.getServiceImpls(StrategyRegistrationProvider.class);
for (StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviders) {
bsrBuilder.applyStrategySelectors(strategyRegistrationProvider);
}
final BootstrapServiceRegistry bsr = bsrBuilder.build();
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
// Allow bundles to put the config file somewhere other than the root level.
final BundleWiring bundleWiring = (BundleWiring) requestingBundle.adapt(BundleWiring.class);
final Collection<String> cfgResources = bundleWiring.listResources("/", "hibernate.cfg.xml", BundleWiring.LISTRESOURCES_RECURSE);
if (cfgResources.size() == 0) {
ssrBuilder.configure();
} else {
if (cfgResources.size() > 1) {
LOG.warn("Multiple hibernate.cfg.xml files found in the persistence bundle. Using the first one discovered.");
}
String cfgResource = "/" + cfgResources.iterator().next();
ssrBuilder.configure(cfgResource);
}
ssrBuilder.applySetting(AvailableSettings.JTA_PLATFORM, osgiJtaPlatform);
final StandardServiceRegistry ssr = ssrBuilder.build();
final MetadataBuilder metadataBuilder = new MetadataSources(ssr).getMetadataBuilder();
final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls(TypeContributor.class);
for (TypeContributor typeContributor : typeContributors) {
metadataBuilder.applyTypes(typeContributor);
}
return metadataBuilder.build().buildSessionFactory();
}
use of org.hibernate.boot.model.TypeContributor in project hibernate-orm by hibernate.
the class MetadataBuildingProcess method handleTypes.
// private static JandexInitManager buildJandexInitializer(
// MetadataBuildingOptions options,
// ClassLoaderAccess classLoaderAccess) {
// final boolean autoIndexMembers = ConfigurationHelper.getBoolean(
// org.hibernate.cfg.AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES,
// options.getServiceRegistry().getService( ConfigurationService.class ).getSettings(),
// false
// );
//
// return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
// }
private static BasicTypeRegistry handleTypes(MetadataBuildingOptions options) {
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
// ultimately this needs to change a little bit to account for HHH-7792
final BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry();
final TypeContributions typeContributions = new TypeContributions() {
@Override
public void contributeType(org.hibernate.type.BasicType type) {
basicTypeRegistry.register(type);
}
@Override
public void contributeType(BasicType type, String... keys) {
basicTypeRegistry.register(type, keys);
}
@Override
public void contributeType(UserType type, String[] keys) {
basicTypeRegistry.register(type, keys);
}
@Override
public void contributeType(CompositeUserType type, String[] keys) {
basicTypeRegistry.register(type, keys);
}
};
// add Dialect contributed types
final Dialect dialect = options.getServiceRegistry().getService(JdbcServices.class).getDialect();
dialect.contributeTypes(typeContributions, options.getServiceRegistry());
// add TypeContributor contributed types.
for (TypeContributor contributor : classLoaderService.loadJavaServices(TypeContributor.class)) {
contributor.contribute(typeContributions, options.getServiceRegistry());
}
// add explicit application registered types
for (BasicTypeRegistration basicTypeRegistration : options.getBasicTypeRegistrations()) {
basicTypeRegistry.register(basicTypeRegistration.getBasicType(), basicTypeRegistration.getRegistrationKeys());
}
return basicTypeRegistry;
}
use of org.hibernate.boot.model.TypeContributor in project hibernate-orm by hibernate.
the class EntityManagerFactoryBuilderImpl method populate.
protected void populate(MetadataBuilder metamodelBuilder, MergedSettings mergedSettings, StandardServiceRegistry ssr, List<AttributeConverterDefinition> attributeConverterDefinitions) {
if (persistenceUnit.getTempClassLoader() != null) {
metamodelBuilder.applyTempClassLoader(persistenceUnit.getTempClassLoader());
}
metamodelBuilder.applyScanEnvironment(new StandardJpaScanEnvironmentImpl(persistenceUnit));
metamodelBuilder.applyScanOptions(new StandardScanOptions((String) configurationValues.get(org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY), persistenceUnit.isExcludeUnlistedClasses()));
if (mergedSettings.cacheRegionDefinitions != null) {
for (CacheRegionDefinition localCacheRegionDefinition : mergedSettings.cacheRegionDefinitions) {
metamodelBuilder.applyCacheRegionDefinition(localCacheRegionDefinition);
}
}
final TypeContributorList typeContributorList = (TypeContributorList) configurationValues.remove(TYPE_CONTRIBUTORS);
if (typeContributorList != null) {
for (TypeContributor typeContributor : typeContributorList.getTypeContributors()) {
metamodelBuilder.applyTypes(typeContributor);
}
}
if (attributeConverterDefinitions != null) {
for (AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitions) {
metamodelBuilder.applyAttributeConverter(attributeConverterDefinition);
}
}
}
use of org.hibernate.boot.model.TypeContributor in project hibernate-orm by hibernate.
the class Configuration method buildSessionFactory.
/**
* Create a {@link SessionFactory} using the properties and mappings in this configuration. The
* SessionFactory will be immutable, so changes made to this Configuration afterQuery building the
* SessionFactory will not affect it.
*
* @param serviceRegistry The registry of services to be used in creating this session factory.
*
* @return The built {@link SessionFactory}
*
* @throws HibernateException usually indicates an invalid configuration or invalid mapping information
*/
public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException {
log.debug("Building session factory using provided StandardServiceRegistry");
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder((StandardServiceRegistry) serviceRegistry);
if (implicitNamingStrategy != null) {
metadataBuilder.applyImplicitNamingStrategy(implicitNamingStrategy);
}
if (physicalNamingStrategy != null) {
metadataBuilder.applyPhysicalNamingStrategy(physicalNamingStrategy);
}
if (sharedCacheMode != null) {
metadataBuilder.applySharedCacheMode(sharedCacheMode);
}
if (!typeContributorRegistrations.isEmpty()) {
for (TypeContributor typeContributor : typeContributorRegistrations) {
metadataBuilder.applyTypes(typeContributor);
}
}
if (!basicTypes.isEmpty()) {
for (BasicType basicType : basicTypes) {
metadataBuilder.applyBasicType(basicType);
}
}
if (sqlFunctions != null) {
for (Map.Entry<String, SQLFunction> entry : sqlFunctions.entrySet()) {
metadataBuilder.applySqlFunction(entry.getKey(), entry.getValue());
}
}
if (auxiliaryDatabaseObjectList != null) {
for (AuxiliaryDatabaseObject auxiliaryDatabaseObject : auxiliaryDatabaseObjectList) {
metadataBuilder.applyAuxiliaryDatabaseObject(auxiliaryDatabaseObject);
}
}
if (attributeConverterDefinitionsByClass != null) {
for (AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitionsByClass.values()) {
metadataBuilder.applyAttributeConverter(attributeConverterDefinition);
}
}
final Metadata metadata = metadataBuilder.build();
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
if (interceptor != null && interceptor != EmptyInterceptor.INSTANCE) {
sessionFactoryBuilder.applyInterceptor(interceptor);
}
if (getSessionFactoryObserver() != null) {
sessionFactoryBuilder.addSessionFactoryObservers(getSessionFactoryObserver());
}
if (getEntityNotFoundDelegate() != null) {
sessionFactoryBuilder.applyEntityNotFoundDelegate(getEntityNotFoundDelegate());
}
if (getEntityTuplizerFactory() != null) {
sessionFactoryBuilder.applyEntityTuplizerFactory(getEntityTuplizerFactory());
}
if (getCurrentTenantIdentifierResolver() != null) {
sessionFactoryBuilder.applyCurrentTenantIdentifierResolver(getCurrentTenantIdentifierResolver());
}
return sessionFactoryBuilder.build();
}
use of org.hibernate.boot.model.TypeContributor in project hibernate-orm by hibernate.
the class OsgiPersistenceProvider method generateSettings.
@SuppressWarnings("unchecked")
private Map generateSettings(Map properties) {
final Map settings = new HashMap();
if (properties != null) {
settings.putAll(properties);
}
settings.put(AvailableSettings.JTA_PLATFORM, osgiJtaPlatform);
final Integrator[] integrators = osgiServiceUtil.getServiceImpls(Integrator.class);
final IntegratorProvider integratorProvider = new IntegratorProvider() {
@Override
public List<Integrator> getIntegrators() {
return Arrays.asList(integrators);
}
};
settings.put(EntityManagerFactoryBuilderImpl.INTEGRATOR_PROVIDER, integratorProvider);
final StrategyRegistrationProvider[] strategyRegistrationProviders = osgiServiceUtil.getServiceImpls(StrategyRegistrationProvider.class);
final StrategyRegistrationProviderList strategyRegistrationProviderList = new StrategyRegistrationProviderList() {
@Override
public List<StrategyRegistrationProvider> getStrategyRegistrationProviders() {
return Arrays.asList(strategyRegistrationProviders);
}
};
settings.put(EntityManagerFactoryBuilderImpl.STRATEGY_REGISTRATION_PROVIDERS, strategyRegistrationProviderList);
final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls(TypeContributor.class);
final TypeContributorList typeContributorList = new TypeContributorList() {
@Override
public List<TypeContributor> getTypeContributors() {
return Arrays.asList(typeContributors);
}
};
settings.put(EntityManagerFactoryBuilderImpl.TYPE_CONTRIBUTORS, typeContributorList);
return settings;
}
Aggregations