下面列出了怎么用org.hibernate.internal.util.config.ConfigurationException的API类实例代码及写法,或者点击链接到github查看源代码。
private Driver findDriver(URI uri, ServiceConfigurationError originalError) {
String scheme = uri.getScheme(); // "postgresql", "mysql", "db2", etc
for (Driver d : ServiceLoader.load( Driver.class )) {
String driverName = d.getClass().getCanonicalName();
CoreLogging.messageLogger(SqlClientPool.class).infof( "HRX000013: Detected driver [%s]", driverName );
if ("io.vertx.db2client.spi.DB2Driver".equals( driverName ) && "db2".equalsIgnoreCase( scheme )) {
return d;
}
if ("io.vertx.mysqlclient.spi.MySQLDriver".equals( driverName ) && "mysql".equalsIgnoreCase( scheme )) {
return d;
}
if ("io.vertx.pgclient.spi.PgDriver".equals( driverName ) &&
("postgre".equalsIgnoreCase( scheme ) ||
"postgres".equalsIgnoreCase( scheme ) ||
"postgresql".equalsIgnoreCase( scheme ))) {
return d;
}
}
throw new ConfigurationException( "No suitable drivers found for URI scheme: " + scheme, originalError );
}
public static MappingReference consume(JaxbCfgMappingReferenceType jaxbMapping) {
if ( StringHelper.isNotEmpty( jaxbMapping.getClazz() ) ) {
return new MappingReference( MappingReference.Type.CLASS, jaxbMapping.getClazz() );
}
else if ( StringHelper.isNotEmpty( jaxbMapping.getFile() ) ) {
return new MappingReference( MappingReference.Type.FILE, jaxbMapping.getFile() );
}
else if ( StringHelper.isNotEmpty( jaxbMapping.getResource() ) ) {
return new MappingReference( MappingReference.Type.RESOURCE, jaxbMapping.getResource() );
}
else if ( StringHelper.isNotEmpty( jaxbMapping.getJar() ) ) {
return new MappingReference( MappingReference.Type.JAR, jaxbMapping.getJar() );
}
else if ( StringHelper.isNotEmpty( jaxbMapping.getPackage() ) ) {
return new MappingReference( MappingReference.Type.PACKAGE, jaxbMapping.getPackage() );
}
else {
throw new ConfigurationException( "<mapping/> named unexpected reference type" );
}
}
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 );
}
}
}
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 JAXBContext hbmJaxbContext() {
if ( hbmJaxbContext == null ) {
try {
hbmJaxbContext = JAXBContext.newInstance( JaxbHbmHibernateMapping.class );
}
catch ( JAXBException e ) {
throw new ConfigurationException( "Unable to build hbm.xml JAXBContext", e );
}
}
return hbmJaxbContext;
}
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"
);
}
}
@Test
public void shouldFailOnWrongConfigFile() {
Map props = U.map(CFG_FILE, "non-existing.xml");
assertThrows(ConfigurationException.class, () -> provider().createEMF(props));
}