Java Code Examples for org.hibernate.boot.registry.classloading.spi.ClassLoaderService#loadJavaServices()

The following examples show how to use org.hibernate.boot.registry.classloading.spi.ClassLoaderService#loadJavaServices() . 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: QuarkusStrategySelectorBuilder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the selector.
 *
 * @param classLoaderService The class loading service used to (attempt to) resolve any un-registered
 *        strategy implementations.
 *
 * @return The selector.
 */
public static StrategySelector buildSelector(ClassLoaderService classLoaderService) {
    final StrategySelectorImpl strategySelector = new StrategySelectorImpl(classLoaderService);

    // build the baseline...
    strategySelector.registerStrategyLazily(Dialect.class, new DefaultDialectSelector());
    strategySelector.registerStrategyLazily(JtaPlatform.class, new DefaultJtaPlatformSelector());
    addTransactionCoordinatorBuilders(strategySelector);
    addMultiTableBulkIdStrategies(strategySelector);
    addImplicitNamingStrategies(strategySelector);
    addCacheKeysFactories(strategySelector);

    // Required to support well known extensions e.g. Envers
    // TODO: should we introduce a new integrator SPI to limit these to extensions supported by Quarkus?
    for (StrategyRegistrationProvider provider : classLoaderService.loadJavaServices(StrategyRegistrationProvider.class)) {
        for (StrategyRegistration discoveredStrategyRegistration : provider.getStrategyRegistrations()) {
            applyFromStrategyRegistration(strategySelector, discoveredStrategyRegistration);
        }
    }

    return strategySelector;
}
 
Example 2
Source File: SessionFactoryServiceRegistryFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SessionFactoryServiceRegistry buildServiceRegistry(
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions options) {
	final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class );
	final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry );

	for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) {
		contributor.contribute( builder );
	}

	return builder.buildSessionFactoryServiceRegistry( sessionFactory, bootstrapContext, options );
}
 
Example 3
Source File: MetadataSources.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * In case a custom {@link MetadataBuilderFactory} creates a custom builder, return that one, otherwise the default
 * builder.
 */
private MetadataBuilder getCustomBuilderOrDefault(MetadataBuilderImpl defaultBuilder) {
	final ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class );
	final java.util.Collection<MetadataBuilderFactory> discoveredBuilderFactories = cls.loadJavaServices( MetadataBuilderFactory.class );

	MetadataBuilder builder = null;
	List<String> activeFactoryNames = null;

	for ( MetadataBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories ) {
		final MetadataBuilder returnedBuilder = discoveredBuilderFactory.getMetadataBuilder( this, defaultBuilder );
		if ( returnedBuilder != null ) {
			if ( activeFactoryNames == null ) {
				activeFactoryNames = new ArrayList<>();
			}
			activeFactoryNames.add( discoveredBuilderFactory.getClass().getName() );
			builder = returnedBuilder;
		}
	}

	if ( activeFactoryNames != null && activeFactoryNames.size() > 1 ) {
		throw new HibernateException(
				"Multiple active MetadataBuilder definitions were discovered : " +
						String.join(", ", activeFactoryNames)
		);
	}

	return builder != null ? builder : defaultBuilder;
}
 
Example 4
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SessionFactoryBuilder getSessionFactoryBuilder() {
	final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl( this, bootstrapContext );

	final ClassLoaderService cls = metadataBuildingOptions.getServiceRegistry().getService( ClassLoaderService.class );
	final java.util.Collection<SessionFactoryBuilderFactory> discoveredBuilderFactories = cls.loadJavaServices( SessionFactoryBuilderFactory.class );

	SessionFactoryBuilder builder = null;
	List<String> activeFactoryNames = null;

	for ( SessionFactoryBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories ) {
		final SessionFactoryBuilder returnedBuilder = discoveredBuilderFactory.getSessionFactoryBuilder( this, defaultBuilder );
		if ( returnedBuilder != null ) {
			if ( activeFactoryNames == null ) {
				activeFactoryNames = new ArrayList<>();
			}
			activeFactoryNames.add( discoveredBuilderFactory.getClass().getName() );
			builder = returnedBuilder;
		}
	}

	if ( activeFactoryNames != null && activeFactoryNames.size() > 1 ) {
		throw new HibernateException(
				"Multiple active SessionFactoryBuilderFactory definitions were discovered : " +
						String.join(", ", activeFactoryNames)
		);
	}

	if ( builder != null ) {
		return builder;
	}

	return defaultBuilder;
}
 
Example 5
Source File: StrategySelectorBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds the selector.
 *
 * @param classLoaderService The class loading service used to (attempt to) resolve any un-registered
 * strategy implementations.
 *
 * @return The selector.
 */
public StrategySelector buildSelector(ClassLoaderService classLoaderService) {
	final StrategySelectorImpl strategySelector = new StrategySelectorImpl( classLoaderService );

	// build the baseline...
	addDialects( strategySelector );
	addJtaPlatforms( strategySelector );
	addTransactionCoordinatorBuilders( strategySelector );
	addMultiTableBulkIdStrategies( strategySelector );
	addEntityCopyObserverStrategies( strategySelector );
	addImplicitNamingStrategies( strategySelector );
	addCacheKeysFactories( strategySelector );

	// apply auto-discovered registrations
	for ( StrategyRegistrationProvider provider : classLoaderService.loadJavaServices( StrategyRegistrationProvider.class ) ) {
		for ( StrategyRegistration discoveredStrategyRegistration : provider.getStrategyRegistrations() ) {
			applyFromStrategyRegistration( strategySelector, discoveredStrategyRegistration );
		}
	}

	// apply customizations
	for ( StrategyRegistration explicitStrategyRegistration : explicitStrategyRegistrations ) {
		applyFromStrategyRegistration( strategySelector, explicitStrategyRegistration );
	}

	return strategySelector;
}