下面列出了怎么用org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider的API类实例代码及写法,或者点击链接到github查看源代码。
private void registerIdentifierGenerators(StandardServiceRegistry ssr) {
final StrategySelector strategySelector = ssr.getService(StrategySelector.class);
// apply id generators
final Object idGeneratorStrategyProviderSetting = buildTimeSettings
.get(AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER);
if (idGeneratorStrategyProviderSetting != null) {
final IdentifierGeneratorStrategyProvider idGeneratorStrategyProvider = strategySelector
.resolveStrategy(IdentifierGeneratorStrategyProvider.class, idGeneratorStrategyProviderSetting);
final MutableIdentifierGeneratorFactory identifierGeneratorFactory = ssr
.getService(MutableIdentifierGeneratorFactory.class);
if (identifierGeneratorFactory == null) {
throw persistenceException("Application requested custom identifier generator strategies, "
+ "but the MutableIdentifierGeneratorFactory could not be found");
}
for (Map.Entry<String, Class<?>> entry : idGeneratorStrategyProvider.getStrategies().entrySet()) {
identifierGeneratorFactory.register(entry.getKey(), entry.getValue());
}
}
}
private void configure(StandardServiceRegistry ssr, MergedSettings mergedSettings) {
final StrategySelector strategySelector = ssr.getService( StrategySelector.class );
// apply id generators
final Object idGeneratorStrategyProviderSetting = configurationValues.remove( AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER );
if ( idGeneratorStrategyProviderSetting != null ) {
final IdentifierGeneratorStrategyProvider idGeneratorStrategyProvider =
strategySelector.resolveStrategy( IdentifierGeneratorStrategyProvider.class, idGeneratorStrategyProviderSetting );
final MutableIdentifierGeneratorFactory identifierGeneratorFactory = ssr.getService( MutableIdentifierGeneratorFactory.class );
if ( identifierGeneratorFactory == null ) {
throw persistenceException(
"Application requested custom identifier generator strategies, " +
"but the MutableIdentifierGeneratorFactory could not be found"
);
}
for ( Map.Entry<String,Class<?>> entry : idGeneratorStrategyProvider.getStrategies().entrySet() ) {
identifierGeneratorFactory.register( entry.getKey(), entry.getValue() );
}
}
}