org.hibernate.integrator.spi.Integrator Java Examples

The following examples show how to use org.hibernate.integrator.spi.Integrator. 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: LocalSessionFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
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 #3
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 )
	);
}
 
Example #4
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 #5
Source File: LocalSessionFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: AbstractJPAProgrammaticBootstrapTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
@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
    );
}
 
Example #7
Source File: PersistenceUnitsHolder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static Map<String, RecordedState> constructMetadataAdvance(
        final List<PersistenceUnitDescriptor> parsedPersistenceXmlDescriptors, Scanner scanner,
        Collection<Class<? extends Integrator>> additionalIntegrators,
        PreGeneratedProxies proxyClassDefinitions,
        MultiTenancyStrategy strategy) {
    Map<String, RecordedState> recordedStates = new HashMap<>();

    for (PersistenceUnitDescriptor unit : parsedPersistenceXmlDescriptors) {
        RecordedState m = createMetadata(unit, scanner, additionalIntegrators, proxyClassDefinitions, strategy);
        Object previous = recordedStates.put(unitName(unit), m);
        if (previous != null) {
            throw new IllegalStateException("Duplicate persistence unit name: " + unit.getName());
        }
    }

    return recordedStates;
}
 
Example #8
Source File: FastBootMetadataBuilder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private Collection<Integrator> getIntegrators() {
    LinkedHashSet<Integrator> integrators = new LinkedHashSet<>();
    integrators.add(new BeanValidationIntegrator());
    integrators.add(new CollectionCacheInvalidator());

    for (Class<? extends Integrator> integratorClass : additionalIntegrators) {
        try {
            integrators.add(integratorClass.getConstructor().newInstance());
        } catch (Exception e) {
            throw new IllegalArgumentException("Unable to instantiate integrator " + integratorClass, e);
        }
    }

    return integrators;
}
 
Example #9
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 #10
Source File: StandardServiceRegistryBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 );
		}
	}
}
 
Example #11
Source File: HibernateDatastore.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
private Metadata getMetadataInternal() {
    Metadata metadata = null;
    ServiceRegistry bootstrapServiceRegistry = ((SessionFactoryImplementor) sessionFactory).getServiceRegistry().getParentServiceRegistry();
    Iterable<Integrator> integrators = bootstrapServiceRegistry.getService(IntegratorService.class).getIntegrators();
    for (Integrator integrator : integrators) {
        if (integrator instanceof MetadataIntegrator) {
            metadata = ((MetadataIntegrator) integrator).getMetadata();
        }
    }
    return metadata;
}
 
Example #12
Source File: JPADTOProjectionClassImportIntegratorPropertyClassTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Override
public List<Integrator> getIntegrators() {
    return List.of(
        new ClassImportIntegrator(
            List.of(
                PostDTO.class
            )
        )
    );
}
 
Example #13
Source File: PersistenceUnitsHolder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static RecordedState createMetadata(PersistenceUnitDescriptor unit, Scanner scanner,
        Collection<Class<? extends Integrator>> additionalIntegrators, PreGeneratedProxies proxyDefinitions,
        MultiTenancyStrategy strategy) {
    FastBootMetadataBuilder fastBootMetadataBuilder = new FastBootMetadataBuilder(unit, scanner, additionalIntegrators,
            proxyDefinitions, strategy);
    return fastBootMetadataBuilder.build();
}
 
Example #14
Source File: HibernateOrmRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public BeanContainerListener initMetadata(List<ParsedPersistenceXmlDescriptor> parsedPersistenceXmlDescriptors,
        Scanner scanner, Collection<Class<? extends Integrator>> additionalIntegrators,
        PreGeneratedProxies proxyDefinitions, MultiTenancyStrategy strategy) {
    return new BeanContainerListener() {
        @Override
        public void created(BeanContainer beanContainer) {
            PersistenceUnitsHolder.initializeJpa(parsedPersistenceXmlDescriptors, scanner, additionalIntegrators,
                    proxyDefinitions, strategy);
        }
    };
}
 
Example #15
Source File: ReactiveServiceRegistryBuilder.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void applyServiceContributingIntegrators() {
    for ( Integrator integrator : bootstrapServiceRegistry.getService( IntegratorService.class )
            .getIntegrators() ) {
        if (integrator instanceof ServiceContributingIntegrator) {
            ((ServiceContributingIntegrator) integrator).prepareServices( this );
        }
    }
}
 
Example #16
Source File: RecordedState.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RecordedState(Dialect dialect, PrevalidatedQuarkusMetadata metadata,
        BuildTimeSettings settings, Collection<Integrator> integrators,
        Collection<ProvidedService> providedServices, IntegrationSettings integrationSettings,
        ProxyDefinitions classDefinitions, MultiTenancyStrategy strategy) {
    this.dialect = dialect;
    this.metadata = metadata;
    this.settings = settings;
    this.integrators = integrators;
    this.providedServices = providedServices;
    this.integrationSettings = integrationSettings;
    this.proxyClassDefinitions = classDefinitions;
    this.multiTenancyStrategy = strategy;
}
 
Example #17
Source File: JpaConfiguration.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * @param applicationContext      The application context
 * @param integrator              The {@link Integrator}
 * @param entityScanConfiguration The entity scan configuration
 */
@Inject
protected JpaConfiguration(ApplicationContext applicationContext,
                           @Nullable Integrator integrator,
                           @Nullable EntityScanConfiguration entityScanConfiguration) {
    ClassLoader classLoader = applicationContext.getClassLoader();
    BootstrapServiceRegistryBuilder bootstrapServiceRegistryBuilder =
            createBootstrapServiceRegistryBuilder(integrator, classLoader);

    this.bootstrapServiceRegistry = bootstrapServiceRegistryBuilder.build();
    this.entityScanConfiguration = entityScanConfiguration != null ? entityScanConfiguration : new EntityScanConfiguration(applicationContext.getEnvironment());
    this.environment = applicationContext.getEnvironment();
    this.applicationContext = applicationContext;
}
 
Example #18
Source File: JpaConfiguration.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the default {@link BootstrapServiceRegistryBuilder}.
 *
 * @param integrator  The integrator to use. Can be null
 * @param classLoader The class loade rto use
 * @return The BootstrapServiceRegistryBuilder
 */
@SuppressWarnings("WeakerAccess")
protected BootstrapServiceRegistryBuilder createBootstrapServiceRegistryBuilder(
        @Nullable Integrator integrator,
        ClassLoader classLoader) {
    BootstrapServiceRegistryBuilder bootstrapServiceRegistryBuilder = new BootstrapServiceRegistryBuilder();
    bootstrapServiceRegistryBuilder.applyClassLoader(classLoader);
    if (integrator != null) {
        bootstrapServiceRegistryBuilder.applyIntegrator(integrator);
    }
    return bootstrapServiceRegistryBuilder;
}
 
Example #19
Source File: DTOProjectionImportRelativePathTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
protected Integrator integrator() {
    return new ClassImportIntegrator(Arrays.asList(PostDTO.class))
        .excludePath("com.vladmihalcea.hibernate.type");
}
 
Example #20
Source File: MetadataTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
@Override
protected Integrator integrator() {
    return MetadataExtractorIntegrator.INSTANCE;
}
 
Example #21
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
protected Integrator integrator() {
    return null;
}
 
Example #22
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example #23
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
protected Integrator integrator() {
    return null;
}
 
Example #24
Source File: AbstractTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
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()
    .enableNewIdentifierGeneratorSupport(true)
    .applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        additionalTypes.stream().forEach(type -> {
            metadataBuilder.applyTypes((typeContributions, sr) -> {
                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);
                }
            });
        });
    }

    additionalMetadata(metadataBuilder);

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if(interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}
 
Example #25
Source File: DTOProjectionImportTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
protected Integrator integrator() {
    return new ClassImportIntegrator(Arrays.asList(PostDTO.class));
}
 
Example #26
Source File: DTOProjectionImportRelativePathTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
protected Integrator integrator() {
    return new ClassImportIntegrator(Arrays.asList(PostDTO.class))
        .excludePath("com.vladmihalcea.hibernate.type");
}
 
Example #27
Source File: AbstractJPAProgrammaticBootstrapTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
protected Integrator integrator() {
    return null;
}
 
Example #28
Source File: OptimisticLockingChildUpdatesRootVersionTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
@Override
protected Integrator integrator() {
    return RootAwareEventListenerIntegrator.INSTANCE;
}
 
Example #29
Source File: OptimisticLockingBidirectionalChildUpdatesRootVersionTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
@Override
protected Integrator integrator() {
    return RootAwareEventListenerIntegrator.INSTANCE;
}
 
Example #30
Source File: JPADTOProjectionClassImportIntegratorTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
@Override
protected Integrator integrator() {
    return new ClassImportIntegrator(
        List.of(PostDTO.class)
    );
}