/** * Constructs a BootstrapServiceRegistryImpl. * * Do not use directly generally speaking. Use {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder} * instead. * * @param autoCloseRegistry See discussion on * {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder#disableAutoClose} * @param classLoaderService The ClassLoaderService to use * @param providedIntegrators The group of explicitly provided integrators * * @see org.hibernate.boot.registry.BootstrapServiceRegistryBuilder */ public BootstrapServiceRegistryImpl( boolean autoCloseRegistry, ClassLoaderService classLoaderService, LinkedHashSet<Integrator> providedIntegrators) { this.autoCloseRegistry = autoCloseRegistry; this.classLoaderServiceBinding = new ServiceBinding<ClassLoaderService>( this, ClassLoaderService.class, classLoaderService ); final StrategySelectorImpl strategySelector = new StrategySelectorImpl( classLoaderService ); this.strategySelectorBinding = new ServiceBinding<StrategySelector>( this, StrategySelector.class, strategySelector ); this.integratorServiceBinding = new ServiceBinding<IntegratorService>( this, IntegratorService.class, new IntegratorServiceImpl( providedIntegrators, classLoaderService ) ); }
@Before public void init() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<>(); Integrator integrator = integrator(); if (integrator != null) { configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator)); } emf = new HibernatePersistenceProvider().createContainerEntityManagerFactory( persistenceUnitInfo, configuration ); }
@SuppressWarnings("deprecation") private void applyServiceContributingIntegrators() { for ( Integrator integrator : bootstrapServiceRegistry.getService( IntegratorService.class ).getIntegrators() ) { if ( org.hibernate.integrator.spi.ServiceContributingIntegrator.class.isInstance( integrator ) ) { org.hibernate.integrator.spi.ServiceContributingIntegrator.class.cast( integrator ).prepareServices( this ); } } }
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)); } EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<String, Object>(); configuration.put(AvailableSettings.INTERCEPTOR, interceptor()); Integrator integrator = integrator(); EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }
private void addIntegrator(Integrator integrator) { LOG.debugf( "Adding Integrator [%s].", integrator.getClass().getName() ); integrators.add( integrator ); }
@Override public Iterable<Integrator> getIntegrators() { return integrators; }
@Override public BootstrapServiceRegistryBuilder with(Integrator integrator) { super.with( integrator ); return this; }
private SessionFactory newSessionFactory() { final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder() .enableAutoClose(); Integrator integrator = integrator(); if (integrator != null) { bsrb.applyIntegrator(integrator); } final BootstrapServiceRegistry bsr = bsrb.build(); final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr) .applySettings(properties()) .build(); final MetadataSources metadataSources = new MetadataSources(serviceRegistry); for (Class annotatedClass : entities()) { metadataSources.addAnnotatedClass(annotatedClass); } String[] packages = packages(); if (packages != null) { for (String annotatedPackage : packages) { metadataSources.addPackage(annotatedPackage); } } String[] resources = resources(); if (resources != null) { for (String resource : resources) { metadataSources.addResource(resource); } } final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(); metadataBuilder.enableNewIdentifierGeneratorSupport(true); metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE); MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build(); final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); Interceptor interceptor = interceptor(); if (interceptor != null) { sfb.applyInterceptor(interceptor); } return sfb.build(); }
protected Integrator integrator() { return null; }
@Override protected Integrator integrator() { return RootAwareEventListenerIntegrator.INSTANCE; }
@Override protected Integrator integrator() { return MetadataExtractorIntegrator.INSTANCE; }
private SessionFactory newSessionFactory() { final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder() .enableAutoClose(); Integrator integrator = integrator(); if (integrator != null) { bsrb.applyIntegrator( integrator ); } final BootstrapServiceRegistry bsr = bsrb.build(); final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr) .applySettings(properties()) .build(); final MetadataSources metadataSources = new MetadataSources(serviceRegistry); for (Class annotatedClass : entities()) { metadataSources.addAnnotatedClass(annotatedClass); } String[] packages = packages(); if (packages != null) { for (String annotatedPackage : packages) { metadataSources.addPackage(annotatedPackage); } } String[] resources = resources(); if (resources != null) { for (String resource : resources) { metadataSources.addResource(resource); } } final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(); metadataBuilder.enableNewIdentifierGeneratorSupport(true); metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE); final List<Type> additionalTypes = additionalTypes(); if (additionalTypes != null) { additionalTypes.stream().forEach(type -> { metadataBuilder.applyTypes((typeContributions, serviceRegistry1) -> { if(type instanceof BasicType) { typeContributions.contributeType((BasicType) type); } else if (type instanceof UserType ){ typeContributions.contributeType((UserType) type); } else if (type instanceof CompositeUserType) { typeContributions.contributeType((CompositeUserType) type); } }); }); } MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build(); final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); Interceptor interceptor = interceptor(); if(interceptor != null) { sfb.applyInterceptor(interceptor); } return sfb.build(); }
/** * Add an {@link Integrator} to be applied to the bootstrap registry. * * @param integrator The integrator to add. * * @return {@code this}, for method chaining */ public BootstrapServiceRegistryBuilder with(Integrator integrator) { providedIntegrators.add( integrator ); return this; }
/** * Constructs a BootstrapServiceRegistryImpl. * * Do not use directly generally speaking. Use {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder} * instead. * * @param classLoaderService The ClassLoaderService to use * @param providedIntegrators The group of explicitly provided integrators * * @see org.hibernate.boot.registry.BootstrapServiceRegistryBuilder */ public BootstrapServiceRegistryImpl( ClassLoaderService classLoaderService, LinkedHashSet<Integrator> providedIntegrators) { this( true, classLoaderService, providedIntegrators ); }