Search in sources :

Example 1 with ConfigurationException

use of org.hibernate.internal.util.config.ConfigurationException in project hibernate-orm by hibernate.

the class SessionFactoryImpl method applyCfgXmlValues.

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);
                }
            }
        }
    }
}
Also used : Set(java.util.Set) EventListenerGroup(org.hibernate.event.service.spi.EventListenerGroup) EventType(org.hibernate.event.spi.EventType) JaccService(org.hibernate.secure.spi.JaccService) GrantedPermission(org.hibernate.secure.spi.GrantedPermission) InvalidObjectException(java.io.InvalidObjectException) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) MappingException(org.hibernate.MappingException) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry) JaccPermissionDeclarations(org.hibernate.secure.spi.JaccPermissionDeclarations) ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) Map(java.util.Map) HashMap(java.util.HashMap) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 2 with ConfigurationException

use of org.hibernate.internal.util.config.ConfigurationException in project hibernate-orm by hibernate.

the class ConfigLoader method loadProperties.

public Properties loadProperties(String resourceName) {
    final InputStream stream = bootstrapServiceRegistry.getService(ClassLoaderService.class).locateResourceStream(resourceName);
    if (stream == null) {
        throw new ConfigurationException("Unable to apply settings from properties file [" + resourceName + "]");
    }
    try {
        Properties properties = new Properties();
        properties.load(stream);
        return properties;
    } catch (IOException e) {
        throw new ConfigurationException("Unable to apply settings from properties file [" + resourceName + "]", e);
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            log.debug(String.format("Unable to close properties file [%s] stream", resourceName), e);
        }
    }
}
Also used : ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 3 with ConfigurationException

use of org.hibernate.internal.util.config.ConfigurationException in project hibernate-orm by hibernate.

the class ConfigLoader method loadProperties.

public Properties loadProperties(File file) {
    try {
        final InputStream stream = new FileInputStream(file);
        try {
            Properties properties = new Properties();
            properties.load(stream);
            return properties;
        } catch (IOException e) {
            throw new ConfigurationException("Unable to apply settings from properties file [" + file.getAbsolutePath() + "]", e);
        } finally {
            try {
                stream.close();
            } catch (IOException e) {
                log.debug(String.format("Unable to close properties file [%s] stream", file.getAbsolutePath()), e);
            }
        }
    } catch (FileNotFoundException e) {
        throw new ConfigurationException("Unable locate specified properties file [" + file.getAbsolutePath() + "]", e);
    }
}
Also used : ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 4 with ConfigurationException

use of org.hibernate.internal.util.config.ConfigurationException in project hibernate-orm by hibernate.

the class JaxbCfgProcessor method unmarshal.

@SuppressWarnings({ "unchecked" })
private JaxbCfgHibernateConfiguration unmarshal(XMLEventReader staxEventReader, final Origin origin) {
    XMLEvent event;
    try {
        event = staxEventReader.peek();
        while (event != null && !event.isStartElement()) {
            staxEventReader.nextEvent();
            event = staxEventReader.peek();
        }
    } catch (Exception e) {
        throw new HibernateException("Error accessing stax stream", e);
    }
    if (event == null) {
        throw new HibernateException("Could not locate root element");
    }
    if (!isNamespaced(event.asStartElement())) {
        // if the elements are not namespaced, wrap the reader in a reader which will namespace them as pulled.
        log.debug("cfg.xml document did not define namespaces; wrapping in custom event reader to introduce namespace information");
        staxEventReader = new NamespaceAddingEventReader(staxEventReader, HIBERNATE_CONFIGURATION_URI);
    }
    final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler();
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(JaxbCfgHibernateConfiguration.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setSchema(schema());
        unmarshaller.setEventHandler(handler);
        return (JaxbCfgHibernateConfiguration) unmarshaller.unmarshal(staxEventReader);
    } catch (JAXBException e) {
        throw new ConfigurationException("Unable to perform unmarshalling at line number " + handler.getLineNumber() + " and column " + handler.getColumnNumber() + " in " + origin.getType().name() + " " + origin.getName() + ". Message: " + handler.getMessage(), e);
    }
}
Also used : JaxbCfgHibernateConfiguration(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgHibernateConfiguration) HibernateException(org.hibernate.HibernateException) ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) JAXBException(javax.xml.bind.JAXBException) XMLEvent(javax.xml.stream.events.XMLEvent) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) ConfigurationException(org.hibernate.internal.util.config.ConfigurationException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) HibernateException(org.hibernate.HibernateException) XsdException(org.hibernate.internal.util.xml.XsdException)

Aggregations

IOException (java.io.IOException)4 ConfigurationException (org.hibernate.internal.util.config.ConfigurationException)4 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 HibernateException (org.hibernate.HibernateException)2 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)2 FileNotFoundException (java.io.FileNotFoundException)1 InvalidObjectException (java.io.InvalidObjectException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 PersistenceException (javax.persistence.PersistenceException)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 MappingException (org.hibernate.MappingException)1