下面列出了怎么用org.hibernate.boot.cfgxml.spi.LoadedConfig的API类实例代码及写法,或者点击链接到github查看源代码。
@SuppressWarnings("unchecked")
private void processConfigXml(
LoadedConfig loadedConfig,
MergedSettings mergedSettings,
StandardServiceRegistryBuilder ssrBuilder) {
if ( ! mergedSettings.configurationValues.containsKey( SESSION_FACTORY_NAME ) ) {
// there is not already a SF-name in the merged settings
final String sfName = loadedConfig.getSessionFactoryName();
if ( sfName != null ) {
// but the cfg.xml file we are processing named one..
mergedSettings.configurationValues.put( SESSION_FACTORY_NAME, sfName );
}
}
mergedSettings.configurationValues.putAll( loadedConfig.getConfigurationValues() );
ssrBuilder.configure( loadedConfig );
}
public LoadedConfig loadConfigXmlResource(String cfgXmlResourceName) {
final InputStream stream = bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( cfgXmlResourceName );
if ( stream == null ) {
throw new ConfigurationException( "Could not locate cfg.xml resource [" + cfgXmlResourceName + "]" );
}
try {
final JaxbCfgHibernateConfiguration jaxbCfg = jaxbProcessorHolder.getValue().unmarshal(
stream,
new Origin( SourceType.RESOURCE, cfgXmlResourceName )
);
return LoadedConfig.consume( jaxbCfg );
}
finally {
try {
stream.close();
}
catch (IOException e) {
log.debug( "Unable to close cfg.xml resource stream", e );
}
}
}
/**
* Intended for use exclusively from JPA boot-strapping, or extensions of
* this class. Consider this an SPI.
*
* @see #forJpa
*/
protected ReactiveServiceRegistryBuilder(
BootstrapServiceRegistry bootstrapServiceRegistry,
Map settings,
LoadedConfig loadedConfig) {
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
this.configLoader = new ConfigLoader( bootstrapServiceRegistry );
this.settings = settings;
this.aggregatedCfgXml = loadedConfig;
this.initiators = defaultReactiveInitiatorList();
}
/**
* Intended for use exclusively from Quarkus boot-strapping, or extensions of
* this class which need to override the standard ServiceInitiator list.
* Consider this an SPI.
*/
protected ReactiveServiceRegistryBuilder(
BootstrapServiceRegistry bootstrapServiceRegistry,
Map settings,
LoadedConfig loadedConfig,
@SuppressWarnings("rawtypes")
List<StandardServiceInitiator> initiators) {
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
this.configLoader = new ConfigLoader( bootstrapServiceRegistry );
this.settings = settings;
this.aggregatedCfgXml = loadedConfig;
this.initiators = initiators;
}
/**
* Create a builder with the specified bootstrap services.
*
* @param bootstrapServiceRegistry Provided bootstrap registry to use.
*/
public ReactiveServiceRegistryBuilder(
BootstrapServiceRegistry bootstrapServiceRegistry,
LoadedConfig loadedConfigBaseline) {
this.settings = Environment.getProperties();
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
this.configLoader = new ConfigLoader( bootstrapServiceRegistry );
this.aggregatedCfgXml = loadedConfigBaseline;
this.initiators = defaultReactiveInitiatorList();
}
@SuppressWarnings({"unchecked"})
public StandardServiceRegistryBuilder configure(LoadedConfig loadedConfig) {
aggregatedCfgXml.merge( loadedConfig );
settings.putAll( loadedConfig.getConfigurationValues() );
return this;
}
private RecordableBootstrap(BootstrapServiceRegistry bootstrapServiceRegistry, Map properties,
LoadedConfig loadedConfigBaseline) {
super(bootstrapServiceRegistry, properties, loadedConfigBaseline, null);
this.settings = properties;
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
this.aggregatedCfgXml = loadedConfigBaseline;
this.initiators = standardInitiatorList();
}
@Override
public CfgXmlAccessService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return new CfgXmlAccessService() {
@Override
public LoadedConfig getAggregatedConfig() {
return null;
}
};
}
private void applyCfgXmlValues(LoadedConfig aggregatedConfig, SessionFactoryServiceRegistry serviceRegistry) {
final JaccService jaccService = serviceRegistry.getService( JaccService.class );
if ( jaccService.getContextId() != null ) {
final JaccPermissionDeclarations permissions = aggregatedConfig.getJaccPermissions( jaccService.getContextId() );
if ( permissions != null ) {
for ( GrantedPermission grantedPermission : permissions.getPermissionDeclarations() ) {
jaccService.addPermission( grantedPermission );
}
}
}
if ( aggregatedConfig.getEventListenerMap() != null ) {
final ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class );
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
for ( Map.Entry<EventType, Set<String>> entry : aggregatedConfig.getEventListenerMap().entrySet() ) {
final EventListenerGroup group = eventListenerRegistry.getEventListenerGroup( entry.getKey() );
for ( String listenerClassName : entry.getValue() ) {
try {
group.appendListener( cls.classForName( listenerClassName ).newInstance() );
}
catch (Exception e) {
throw new ConfigurationException( "Unable to instantiate event listener class : " + listenerClassName, e );
}
}
}
}
}
private void applyCfgXmlValues(CfgXmlAccessService service) {
final LoadedConfig aggregatedConfig = service.getAggregatedConfig();
if ( aggregatedConfig == null ) {
return;
}
for ( CacheRegionDefinition cacheRegionDefinition : aggregatedConfig.getCacheRegionDefinitions() ) {
applyCacheRegionDefinition( cacheRegionDefinition );
}
}
/**
* Create a builder with the specified bootstrap services.
*
* @param bootstrapServiceRegistry Provided bootstrap registry to use.
*/
public StandardServiceRegistryBuilder(
BootstrapServiceRegistry bootstrapServiceRegistry,
LoadedConfig loadedConfigBaseline) {
this.settings = Environment.getProperties();
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
this.configLoader = new ConfigLoader( bootstrapServiceRegistry );
this.aggregatedCfgXml = loadedConfigBaseline;
}
@SuppressWarnings({"unchecked"})
public StandardServiceRegistryBuilder configure(LoadedConfig loadedConfig) {
aggregatedCfgXml.merge( loadedConfig );
settings.putAll( loadedConfig.getConfigurationValues() );
return this;
}
public LoadedConfig loadConfigXmlFile(File cfgXmlFile) {
try {
final JaxbCfgHibernateConfiguration jaxbCfg = jaxbProcessorHolder.getValue().unmarshal(
new FileInputStream( cfgXmlFile ),
new Origin( SourceType.FILE, cfgXmlFile.getAbsolutePath() )
);
return LoadedConfig.consume( jaxbCfg );
}
catch (FileNotFoundException e) {
throw new ConfigurationException(
"Specified cfg.xml file [" + cfgXmlFile.getAbsolutePath() + "] does not exist"
);
}
}
/**
* Intended for internal testing use only!!
*/
public LoadedConfig getAggregatedCfgXml() {
return aggregatedCfgXml;
}
public RecordableBootstrap(BootstrapServiceRegistry bootstrapServiceRegistry) {
this(bootstrapServiceRegistry, initialProperties(), LoadedConfig.baseline());
}
/**
* Intended for internal testing use only!!
*/
@Override
public LoadedConfig getAggregatedCfgXml() {
return aggregatedCfgXml;
}
@Override
@SuppressWarnings({ "unchecked" })
public StandardServiceRegistryBuilder configure(LoadedConfig loadedConfig) {
throw new UnsupportedOperationException(DISABLED_FEATURE_MSG);
}
/**
* Intended for internal testing use only!!
*/
public LoadedConfig getAggregatedCfgXml() {
return aggregatedCfgXml;
}
public CfgXmlAccessServiceImpl(Map configurationValues) {
aggregatedCfgXml = (LoadedConfig) configurationValues.get( LOADED_CONFIG_KEY );
}
@Override
public LoadedConfig getAggregatedConfig() {
return aggregatedCfgXml;
}
/**
* Create a builder with the specified bootstrap services.
*
* @param bootstrapServiceRegistry Provided bootstrap registry to use.
*/
public ReactiveServiceRegistryBuilder(BootstrapServiceRegistry bootstrapServiceRegistry) {
this( bootstrapServiceRegistry, LoadedConfig.baseline() );
}
/**
* Create a builder with the specified bootstrap services.
*
* @param bootstrapServiceRegistry Provided bootstrap registry to use.
*/
public StandardServiceRegistryBuilder(BootstrapServiceRegistry bootstrapServiceRegistry) {
this( bootstrapServiceRegistry, LoadedConfig.baseline() );
}