org.hibernate.boot.registry.selector.StrategyRegistration Java Examples

The following examples show how to use org.hibernate.boot.registry.selector.StrategyRegistration. 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: StrategySelectorBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds an explicit (as opposed to discovered) strategy registration.
 *
 * @param strategyRegistration The strategy implementation registration.
 * @param <T> The type of the strategy.  Used to make sure that the strategy and implementation are type
 * compatible.
 */
public <T> void addExplicitStrategyRegistration(StrategyRegistration<T> strategyRegistration) {
	if ( !strategyRegistration.getStrategyRole().isInterface() ) {
		// not good form...
		log.debug( "Registering non-interface strategy : " + strategyRegistration.getStrategyRole().getName()  );
	}

	if ( ! strategyRegistration.getStrategyRole().isAssignableFrom( strategyRegistration.getStrategyImplementation() ) ) {
		throw new StrategySelectionException(
				"Implementation class [" + strategyRegistration.getStrategyImplementation().getName()
						+ "] does not implement strategy interface ["
						+ strategyRegistration.getStrategyRole().getName() + "]"
		);
	}
	explicitStrategyRegistrations.add( strategyRegistration );
}
 
Example #3
Source File: StrategyRegistrationProviderImpl.java    From hibernate-l2-memcached with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    final List<StrategyRegistration> strategyRegistrations = new ArrayList<StrategyRegistration>();

    strategyRegistrations.add(
            new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    MemcachedRegionFactory.class,
                    "memcached",
                    MemcachedRegionFactory.class.getName(),
                    MemcachedRegionFactory.class.getSimpleName(),
                    // legacy impl class name
                    "com.mc.hibernate.memcached.MemcachedRegionFactory"
            )
    );

    return strategyRegistrations;
}
 
Example #4
Source File: QuarkusStrategySelectorBuilder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T> void applyFromStrategyRegistration(
        StrategySelectorImpl strategySelector,
        StrategyRegistration<T> strategyRegistration) {
    for (String name : strategyRegistration.getSelectorNames()) {
        strategySelector.registerStrategyImplementor(
                strategyRegistration.getStrategyRole(),
                name,
                strategyRegistration.getStrategyImplementation());
    }
}
 
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;
}
 
Example #6
Source File: StrategySelectorBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> void applyFromStrategyRegistration(StrategySelectorImpl strategySelector, StrategyRegistration<T> strategyRegistration) {
	for ( String name : strategyRegistration.getSelectorNames() ) {
		strategySelector.registerStrategyImplementor(
				strategyRegistration.getStrategyRole(),
				name,
				strategyRegistration.getStrategyImplementation()
		);
	}
}
 
Example #7
Source File: RedissonStrategyRegistrationProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example #8
Source File: RedissonStrategyRegistrationProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example #9
Source File: RedissonStrategyRegistrationProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example #10
Source File: RedissonStrategyRegistrationProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
    return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
                    RegionFactory.class,
                    RedissonRegionFactory.class,
                    "redisson",
                    RedissonRegionFactory.class.getName(),
                    RedissonRegionFactory.class.getSimpleName()));
}
 
Example #11
Source File: TestStrategyRegistrationProvider.java    From hibernate-demos with Apache License 2.0 4 votes vote down vote up
@Override
   public Iterable<StrategyRegistration> getStrategyRegistrations() {
	System.out.println("StrategyRegistrationProvider#getStrategyRegistrations");
	return Collections.EMPTY_LIST;
}
 
Example #12
Source File: TestStrategyRegistrationProvider.java    From hibernate-demos with Apache License 2.0 4 votes vote down vote up
@Override
   public Iterable<StrategyRegistration> getStrategyRegistrations() {
	System.out.println("StrategyRegistrationProvider#getStrategyRegistrations");
	return Collections.EMPTY_LIST;
}
 
Example #13
Source File: BootstrapServiceRegistryBuilder.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Applies one or more strategy selectors announced as available by the passed announcer.
 *
 * @param strategyRegistrationProvider A provider for one or more available selectors
 *
 * @return {@code this}, for method chaining
 *
 * @see org.hibernate.boot.registry.selector.spi.StrategySelector#registerStrategyImplementor(Class, String, Class)
 */
@SuppressWarnings( {"UnusedDeclaration"})
public BootstrapServiceRegistryBuilder applyStrategySelectors(StrategyRegistrationProvider strategyRegistrationProvider) {
	for ( StrategyRegistration strategyRegistration : strategyRegistrationProvider.getStrategyRegistrations() ) {
		this.strategySelectorBuilder.addExplicitStrategyRegistration( strategyRegistration );
	}
	return this;
}