下面列出了怎么用org.hibernate.boot.registry.selector.StrategyRegistration的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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;
}
/**
* 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 );
}
@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;
}
@SuppressWarnings("unchecked")
private static <T> void applyFromStrategyRegistration(
StrategySelectorImpl strategySelector,
StrategyRegistration<T> strategyRegistration) {
for (String name : strategyRegistration.getSelectorNames()) {
strategySelector.registerStrategyImplementor(
strategyRegistration.getStrategyRole(),
name,
strategyRegistration.getStrategyImplementation());
}
}
/**
* 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;
}
@SuppressWarnings("unchecked")
private <T> void applyFromStrategyRegistration(StrategySelectorImpl strategySelector, StrategyRegistration<T> strategyRegistration) {
for ( String name : strategyRegistration.getSelectorNames() ) {
strategySelector.registerStrategyImplementor(
strategyRegistration.getStrategyRole(),
name,
strategyRegistration.getStrategyImplementation()
);
}
}
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
RegionFactory.class,
RedissonRegionFactory.class,
"redisson",
RedissonRegionFactory.class.getName(),
RedissonRegionFactory.class.getSimpleName()));
}
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
RegionFactory.class,
RedissonRegionFactory.class,
"redisson",
RedissonRegionFactory.class.getName(),
RedissonRegionFactory.class.getSimpleName()));
}
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
RegionFactory.class,
RedissonRegionFactory.class,
"redisson",
RedissonRegionFactory.class.getName(),
RedissonRegionFactory.class.getSimpleName()));
}
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return Collections.<StrategyRegistration>singleton(new SimpleStrategyRegistrationImpl(
RegionFactory.class,
RedissonRegionFactory.class,
"redisson",
RedissonRegionFactory.class.getName(),
RedissonRegionFactory.class.getSimpleName()));
}
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
System.out.println("StrategyRegistrationProvider#getStrategyRegistrations");
return Collections.EMPTY_LIST;
}
@Override
public Iterable<StrategyRegistration> getStrategyRegistrations() {
System.out.println("StrategyRegistrationProvider#getStrategyRegistrations");
return Collections.EMPTY_LIST;
}
/**
* 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;
}