Search in sources :

Example 86 with HibernateException

use of org.hibernate.HibernateException in project head by mifos.

the class SystemInformationServiceFacadeWebTier method getSystemInformation.

@Override
public SystemInformationDto getSystemInformation(ServletContext context, Locale locale) {
    try {
        DatabaseMetaData metaData = StaticHibernateUtil.getSessionTL().connection().getMetaData();
        final SystemInfo systemInfo = new SystemInfo(metaData, context, locale, true);
        systemInfo.setCustomReportsDir(BirtReportsUploadAction.getCustomReportStorageDirectory());
        return new SystemInformationDto(systemInfo.getApplicationServerInfo(), systemInfo.getApplicationVersion(), systemInfo.getBuildDate(), systemInfo.getBuildNumber(), systemInfo.getCommitIdentifier(), systemInfo.getCustomReportsDir(), systemInfo.getDatabaseName(), systemInfo.getDatabasePort(), systemInfo.getDatabaseServer(), systemInfo.getDatabaseUser(), systemInfo.getDatabaseVendor(), systemInfo.getDatabaseVersion(), systemInfo.getDriverName(), systemInfo.getDriverVersion(), systemInfo.getDateTimeString(), systemInfo.getDateTimeStringIso8601(), systemInfo.getInfoSource(), systemInfo.getInfoURL(), systemInfo.getJavaVendor(), systemInfo.getJavaVersion(), systemInfo.getOsArch(), systemInfo.getOsName(), systemInfo.getOsUser(), systemInfo.getOsVersion(), systemInfo.getReleaseName());
    } catch (HibernateException e) {
        throw new MifosRuntimeException(e);
    } catch (SQLException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : SystemInfo(org.mifos.application.admin.system.SystemInfo) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) DatabaseMetaData(java.sql.DatabaseMetaData) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 87 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class AdditionalJaxbMappingProducerImpl method produceAdditionalMappings.

@Override
public Collection<MappingDocument> produceAdditionalMappings(final MetadataImplementor metadata, IndexView jandexIndex, final MappingBinder mappingBinder, final MetadataBuildingContext buildingContext) {
    final ServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
    final EnversService enversService = serviceRegistry.getService(EnversService.class);
    if (!enversService.isEnabled()) {
        // short-circuit if envers integration has been disabled.
        return Collections.emptyList();
    }
    final ArrayList<MappingDocument> additionalMappingDocuments = new ArrayList<>();
    // atm we do not have distinct origin info for envers
    final Origin origin = new Origin(SourceType.OTHER, "envers");
    //		final DOMWriter writer = new DOMWriter();
    final MappingCollector mappingCollector = new MappingCollector() {

        @Override
        public void addDocument(Document document) throws DocumentException {
            dump(document);
            // while the commented-out code here is more efficient (well, understanding that
            // this whole process is un-efficient)  it leads to un-decipherable messages when
            // we get mapping mapping errors from envers output.
            //				final DOMSource domSource = new DOMSource( writer.write( document ) );
            //				domSource.setSystemId( "envers" );
            //				final Binding jaxbBinding = mappingBinder.bind( domSource, origin );
            // this form at least allows us to get better error messages
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                final Writer w = new BufferedWriter(new OutputStreamWriter(baos, "UTF-8"));
                final XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
                xw.write(document);
                w.flush();
            } catch (IOException e) {
                throw new HibernateException("Unable to bind Envers-generated XML", e);
            }
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            BufferedInputStream bis = new BufferedInputStream(bais);
            final Binding jaxbBinding = mappingBinder.bind(bis, origin);
            final JaxbHbmHibernateMapping jaxbRoot = (JaxbHbmHibernateMapping) jaxbBinding.getRoot();
            additionalMappingDocuments.add(new MappingDocument(jaxbRoot, origin, buildingContext));
        }
    };
    enversService.initialize(metadata, mappingCollector);
    return additionalMappingDocuments;
}
Also used : Origin(org.hibernate.boot.jaxb.Origin) Binding(org.hibernate.boot.jaxb.spi.Binding) HibernateException(org.hibernate.HibernateException) MappingDocument(org.hibernate.boot.model.source.internal.hbm.MappingDocument) ArrayList(java.util.ArrayList) OutputFormat(org.dom4j.io.OutputFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(org.dom4j.Document) MappingDocument(org.hibernate.boot.model.source.internal.hbm.MappingDocument) XMLWriter(org.dom4j.io.XMLWriter) BufferedWriter(java.io.BufferedWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) OutputStreamWriter(java.io.OutputStreamWriter) ServiceRegistry(org.hibernate.service.ServiceRegistry) MappingCollector(org.hibernate.envers.configuration.internal.MappingCollector) XMLWriter(org.dom4j.io.XMLWriter) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) JaxbHbmHibernateMapping(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping)

Example 88 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class EnversIntegrator method integrate.

public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    final EnversService enversService = serviceRegistry.getService(EnversService.class);
    // Opt-out of registration if EnversService is disabled
    if (!enversService.isEnabled()) {
        log.debug("Skipping Envers listener registrations : EnversService disabled");
        return;
    }
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Opt-out of registration if asked to not register
    final boolean autoRegister = serviceRegistry.getService(ConfigurationService.class).getSetting(AUTO_REGISTER, StandardConverters.BOOLEAN, true);
    if (!autoRegister) {
        log.debug("Skipping Envers listener registrations : Listener auto-registration disabled");
        return;
    }
    // Verify that the EnversService is fully initialized and ready to go.
    if (!enversService.isInitialized()) {
        throw new HibernateException("Expecting EnversService to have been initialized prior to call to EnversIntegrator#integrate");
    }
    // Opt-out of registration if no audited entities found
    if (!enversService.getEntitiesConfigurations().hasAuditedEntities()) {
        log.debug("Skipping Envers listener registrations : No audited entities found");
        return;
    }
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Do the registrations
    final EventListenerRegistry listenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    listenerRegistry.addDuplicationStrategy(EnversListenerDuplicationStrategy.INSTANCE);
    if (enversService.getEntitiesConfigurations().hasAuditedEntities()) {
        listenerRegistry.appendListeners(EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_INSERT, new EnversPostInsertEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.PRE_UPDATE, new EnversPreUpdateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.POST_COLLECTION_RECREATE, new EnversPostCollectionRecreateEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.PRE_COLLECTION_REMOVE, new EnversPreCollectionRemoveEventListenerImpl(enversService));
        listenerRegistry.appendListeners(EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl(enversService));
    }
}
Also used : HibernateException(org.hibernate.HibernateException) EnversPreUpdateEventListenerImpl(org.hibernate.envers.event.spi.EnversPreUpdateEventListenerImpl) EnversPreCollectionRemoveEventListenerImpl(org.hibernate.envers.event.spi.EnversPreCollectionRemoveEventListenerImpl) EnversPreCollectionUpdateEventListenerImpl(org.hibernate.envers.event.spi.EnversPreCollectionUpdateEventListenerImpl) EnversPostInsertEventListenerImpl(org.hibernate.envers.event.spi.EnversPostInsertEventListenerImpl) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) EnversPostUpdateEventListenerImpl(org.hibernate.envers.event.spi.EnversPostUpdateEventListenerImpl) EnversPostCollectionRecreateEventListenerImpl(org.hibernate.envers.event.spi.EnversPostCollectionRecreateEventListenerImpl) EnversPostDeleteEventListenerImpl(org.hibernate.envers.event.spi.EnversPostDeleteEventListenerImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 89 with HibernateException

use of org.hibernate.HibernateException in project hibernate-orm by hibernate.

the class HikariCPConnectionProvider method configure.

// *************************************************************************
// Configurable
// *************************************************************************
@SuppressWarnings("rawtypes")
@Override
public void configure(Map props) throws HibernateException {
    try {
        LOGGER.debug("Configuring HikariCP");
        hcfg = HikariConfigurationUtil.loadConfiguration(props);
        hds = new HikariDataSource(hcfg);
    } catch (Exception e) {
        throw new HibernateException(e);
    }
    LOGGER.debug("HikariCP Configured");
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) UnknownUnwrapTypeException(org.hibernate.service.UnknownUnwrapTypeException) HibernateException(org.hibernate.HibernateException)

Example 90 with HibernateException

use of org.hibernate.HibernateException in project head by mifos.

the class BranchReportHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    Session session = StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    Date runDate = new Date(timeInMillis);
    try {
        removeExistingBranchReportsForGivenRunDate(runDate);
        populateBranchReportBatch(session, runDate);
        StaticHibernateUtil.commitTransaction();
    } catch (HibernateException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BatchJobException(e);
    } catch (ServiceException e) {
        throw new BatchJobException(e);
    }
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateException(org.hibernate.HibernateException) Date(java.util.Date) Session(org.hibernate.Session)

Aggregations

HibernateException (org.hibernate.HibernateException)372 DAOException (org.jbei.ice.storage.DAOException)141 Session (org.hibernate.Session)72 Test (org.junit.Test)41 ArrayList (java.util.ArrayList)30 SQLException (java.sql.SQLException)27 IOException (java.io.IOException)15 TestForIssue (org.hibernate.testing.TestForIssue)15 Transaction (org.hibernate.Transaction)14 Group (org.jbei.ice.storage.model.Group)14 Type (org.hibernate.type.Type)12 PersistenceException (org.mifos.framework.exceptions.PersistenceException)12 Serializable (java.io.Serializable)11 EntityEntry (org.hibernate.engine.spi.EntityEntry)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)10 HashMap (java.util.HashMap)9 Method (java.lang.reflect.Method)8 Dialect (org.hibernate.dialect.Dialect)8 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)8 HibernateProxy (org.hibernate.proxy.HibernateProxy)8