/** * @deprecated Use {@link #applyIntegrator} instead */ @Deprecated public BootstrapServiceRegistryBuilder with(Integrator integrator) { return applyIntegrator( integrator ); }
@Override protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { builder.applyIntegrator( new Integrator() { @Override public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { integrate( serviceRegistry ); } private void integrate(SessionFactoryServiceRegistry serviceRegistry) { EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() ); eventListenerRegistry.setListeners( EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners() ); eventListenerRegistry.setListeners( EventType.AUTO_FLUSH, buildAutoFlushEventListeners() ); eventListenerRegistry.setListeners( EventType.FLUSH, buildFlushEventListeners() ); eventListenerRegistry.setListeners( EventType.FLUSH_ENTITY, buildFlushEntityEventListeners() ); } @Override public void disintegrate( SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { } } ); }
@Override protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { super.prepareBootstrapRegistryBuilder( builder ); builder.applyIntegrator( new Integrator() { @Override public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { integrate( serviceRegistry ); } private void integrate(SessionFactoryServiceRegistry serviceRegistry) { serviceRegistry.getService( EventListenerRegistry.class ).prependListeners( EventType.LOAD, new CustomLoadListener() ); } @Override public void disintegrate( SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { } } ); }
@Override protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { super.prepareBootstrapRegistryBuilder( builder ); builder.applyIntegrator( new Integrator() { @Override public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { integrate( serviceRegistry ); } private void integrate(SessionFactoryServiceRegistry serviceRegistry) { serviceRegistry.getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.PRE_UPDATE ) .appendListener( InitializingPreUpdateEventListener.INSTANCE ); } @Override public void disintegrate( SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { } } ); }
/** * Determine the Hibernate {@link MetadataSources} to use. * <p>Can also be externally called to initialize and pre-populate a {@link MetadataSources} * instance which is then going to be used for {@link SessionFactory} building. * @return the MetadataSources to use (never {@code null}) * @since 4.3 * @see LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources) */ public MetadataSources getMetadataSources() { this.metadataSourcesAccessed = true; if (this.metadataSources == null) { BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder(); if (this.resourcePatternResolver != null) { builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader()); } if (this.hibernateIntegrators != null) { for (Integrator integrator : this.hibernateIntegrators) { builder = builder.applyIntegrator(integrator); } } this.metadataSources = new MetadataSources(builder.build()); } return this.metadataSources; }
@Override protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) { super.prepareBootstrapRegistryBuilder( builder ); builder.applyIntegrator( new Integrator() { @Override public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { integrate( serviceRegistry ); } private void integrate(SessionFactoryServiceRegistry serviceRegistry) { serviceRegistry.getService( EventListenerRegistry.class ).setListeners( EventType.CLEAR, listener ); } @Override public void disintegrate( SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { } } ); } }
bsrb.applyIntegrator(new JpaIntegrator());
@Test public void test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example() { ClassLoader customClassLoader = Thread.currentThread().getContextClassLoader(); Integrator customIntegrator = new BeanValidationIntegrator(); //tag::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[] BootstrapServiceRegistryBuilder bootstrapRegistryBuilder = new BootstrapServiceRegistryBuilder(); // add a custom ClassLoader bootstrapRegistryBuilder.applyClassLoader( customClassLoader ); // manually add an Integrator bootstrapRegistryBuilder.applyIntegrator( customIntegrator ); BootstrapServiceRegistry bootstrapRegistry = bootstrapRegistryBuilder.build(); //end::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[] }
if ( integratorProvider != null ) { for ( Integrator integrator : integratorProvider.getIntegrators() ) { bsrBuilder.applyIntegrator( integrator );
/** * Determine the Hibernate {@link MetadataSources} to use. * <p>Can also be externally called to initialize and pre-populate a {@link MetadataSources} * instance which is then going to be used for {@link SessionFactory} building. * @return the MetadataSources to use (never {@code null}) * @since 4.3 * @see LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources) */ public MetadataSources getMetadataSources() { this.metadataSourcesAccessed = true; if (this.metadataSources == null) { BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder(); if (this.resourcePatternResolver != null) { builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader()); } if (this.hibernateIntegrators != null) { for (Integrator integrator : this.hibernateIntegrators) { builder = builder.applyIntegrator(integrator); } } this.metadataSources = new MetadataSources(builder.build()); } return this.metadataSources; }
bsrBuilder.applyIntegrator( integrator );
private SessionFactoryImplementor buildSessionFactory(ExtendedBeanManagerImpl standIn, NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) { BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder() .applyIntegrator( beanConsumingIntegrator ) .build(); final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ) .applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ) .applySetting( AvailableSettings.CDI_BEAN_MANAGER, standIn ) .build(); try { return (SessionFactoryImplementor) new MetadataSources( ssr ) .addAnnotatedClass( TheEntity.class ) .buildMetadata() .getSessionFactoryBuilder() .build(); } catch (Exception e) { StandardServiceRegistryBuilder.destroy( ssr ); throw e; } }
private SessionFactoryImplementor buildSessionFactory(SeContainer cdiContainer, NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) { BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder() .applyIntegrator( beanConsumingIntegrator ) .build(); final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ) .applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ) .applySetting( AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager() ) .build(); try { return (SessionFactoryImplementor) new MetadataSources( ssr ) .addAnnotatedClass( TheEntity.class ) .buildMetadata() .getSessionFactoryBuilder() .build(); } catch ( Exception e ) { StandardServiceRegistryBuilder.destroy( ssr ); throw e; } }
/** * @deprecated Use {@link #applyIntegrator} instead */ @Deprecated public BootstrapServiceRegistryBuilder with(Integrator integrator) { return applyIntegrator( integrator ); }
private BootstrapServiceRegistry buildBootstrapServiceRegistry() { final Integrator integrator = new Integrator() { @Override public void integrate( final Metadata metadata, final SessionFactoryImplementor sessionFactory, final SessionFactoryServiceRegistry serviceRegistry) { updateV5MetaData(metadata); } @Override public void disintegrate( final SessionFactoryImplementor sessionFactory, final SessionFactoryServiceRegistry serviceRegistry) { } }; return new BootstrapServiceRegistryBuilder().applyIntegrator(integrator).build(); }
bsrb.applyIntegrator(new JpaIntegrator());
if ( integratorProvider != null ) { for ( Integrator integrator : integratorProvider.getIntegrators() ) { bsrBuilder.applyIntegrator( integrator );
bsrb.applyIntegrator( integrator );