org.hibernate.internal.util.config.ConfigurationException Java Examples

The following examples show how to use org.hibernate.internal.util.config.ConfigurationException. 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: ConfigLoader.java    From lams with GNU General Public License v2.0 7 votes vote down vote up
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 );
		}
	}
}
 
Example #2
Source File: SqlClientPool.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 );
}
 
Example #3
Source File: MappingReference.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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" );
	}
}
 
Example #4
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 );
				}
			}
		}
	}
}
 
Example #5
Source File: MappingBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: ConfigLoader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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"
		);
	}
}
 
Example #7
Source File: CustomHibernatePersistenceProviderTest.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldFailOnWrongConfigFile() {
	Map props = U.map(CFG_FILE, "non-existing.xml");

	assertThrows(ConfigurationException.class, () -> provider().createEMF(props));
}