Search in sources :

Example 96 with HibernateException

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

the class LegacyGenericDao method save.

public Object save(final Object object) throws PersistenceException {
    try {
        getSession().saveOrUpdate(object);
        AuditInterceptor interceptor = (AuditInterceptor) StaticHibernateUtil.getInterceptor();
        if (interceptor.isAuditLogRequired()) {
            interceptor.createChangeValueMap(object);
        }
    } catch (HibernateException e) {
        throw new PersistenceException(e);
    }
    return object;
}
Also used : AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) HibernateException(org.hibernate.HibernateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 97 with HibernateException

use of org.hibernate.HibernateException in project ACS by ACS-Community.

the class HibernateUtil method reconnect.

/**
     * Reconnects a Hibernate Session to the current Thread.
     *
     * @param session The Hibernate Session to be reconnected.
     */
@SuppressWarnings("deprecation")
public void reconnect(Session session) throws HibernateUtilException {
    try {
        Connection c = session.disconnect();
        session.reconnect(c);
        threadSession.set(session);
    } catch (HibernateException ex) {
        throw new HibernateUtilException(ex);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) Connection(java.sql.Connection)

Example 98 with HibernateException

use of org.hibernate.HibernateException in project ACS by ACS-Community.

the class StartServicesHelper method internalGetServicesDescription.

/**
	 * Return the the XML string describing the services to start by reading the services from the
	 * TMCDB.
	 *  
	 * @param daemon That services daemon
	 * @return The XML and the list of services describing the services to start
	 * @throws HibernateException In case of error reading the services from the TMCDB
	 * @throws DaemonException In case of error from the daemon
	 * @throws TMCDBException If the list of service read from the TMCDB is empty
	 */
private AlarmServicesDefinitionHolder internalGetServicesDescription(ServicesDaemon daemon) throws HibernateException, DaemonException, TMCDBException {
    if (daemon == null) {
        throw new IllegalArgumentException("The daemon can't be null");
    }
    // Get the service definition builder for the current instance
    ServiceDefinitionBuilder srvDefBuilder = null;
    try {
        srvDefBuilder = daemon.create_service_definition_builder((short) instance);
    } catch (Throwable t) {
        throw new DaemonException("Error getting the service definition builder", t);
    }
    logger.log(AcsLogLevel.DEBUG, "ServiceDefinitionBuilder got from the ACS services daemon");
    // Get the services from the TMCDB
    List<AcsServiceToStart> services = getServicesList();
    if (services.isEmpty()) {
        throw new TMCDBException("No services to start from TMCDB");
    }
    logger.log(AcsLogLevel.DEBUG, "Read " + services.size() + " to start from TMCDB");
    // Add the services to the service definition builder
    try {
        /*
			 * NOTE: some of the paremeters required to start the services are hardcoded
			 *       because the tables of the database do not allow to have them stored
			 *       in the TMCDB.
			 *       For this release it is good enough but if we want to have them available
			 *       in the TMCDB and the explorer then we have to change the table of
			 *       the database too.
			 */
        for (AcsServiceToStart svc : services) {
            if (svc.serviceName == null) {
                logger.log(AcsLogLevel.DEBUG, "Adding " + svc.serviceType + "@" + svc.hostName + " to the ServicesDefinitionBuilder");
            } else {
                logger.log(AcsLogLevel.DEBUG, "Adding " + svc.serviceType + "@" + svc.hostName + " with name " + svc.serviceName + " to the ServicesDefinitionBuilder");
            }
            switch(svc.serviceType) {
                case MANAGER:
                    {
                        srvDefBuilder.add_manager(svc.hostName, "", false);
                        break;
                    }
                case ALARM:
                    {
                        srvDefBuilder.add_alarm_service(svc.hostName);
                        break;
                    }
                case CDB:
                    {
                        srvDefBuilder.add_rdb_cdb(svc.hostName, false, configurationName);
                        break;
                    }
                case IFR:
                    {
                        srvDefBuilder.add_interface_repository(svc.hostName, true, false);
                        break;
                    }
                case LOGGING:
                    {
                        srvDefBuilder.add_logging_service(svc.hostName, "Log");
                        break;
                    }
                case LOGPROXY:
                    {
                        srvDefBuilder.add_acs_log(svc.hostName);
                        break;
                    }
                case NAMING:
                    {
                        srvDefBuilder.add_naming_service(svc.hostName);
                        break;
                    }
                case NOTIFICATION:
                    {
                        srvDefBuilder.add_notification_service(svc.serviceName, svc.hostName);
                        break;
                    }
                default:
                    {
                        throw new Exception("Unknown type of service to start: " + svc.serviceType + ", on " + svc.hostName);
                    }
            }
        }
    } catch (Throwable t) {
        throw new DaemonException("Error adding services to the daemon", t);
    }
    logger.log(AcsLogLevel.DEBUG, "All the services have been added to the ServiceDefinitionBuilder");
    String svcsXML = srvDefBuilder.get_services_definition();
    StringHolder errorStr = new StringHolder();
    if (!srvDefBuilder.is_valid(errorStr)) {
        // Error in the XML
        throw new DaemonException("Error in the services definition: " + errorStr.value);
    } else {
        logger.log(AcsLogLevel.DEBUG, "Services successfully validated by the ServicesDefinitionBuilder");
    }
    return new AlarmServicesDefinitionHolder(svcsXML, Collections.unmodifiableList(services));
}
Also used : StringHolder(org.omg.CORBA.StringHolder) ServiceDefinitionBuilder(alma.acsdaemon.ServiceDefinitionBuilder) AcsServiceToStart(alma.acs.commandcenter.serviceshelper.TMCDBServicesHelper.AcsServiceToStart) HibernateException(org.hibernate.HibernateException)

Example 99 with HibernateException

use of org.hibernate.HibernateException in project ACS by ACS-Community.

the class HibernateXmlType method nullSafeSet.

/* (non-Javadoc)
	 * @see org.hibernate.type.StringClobType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int)
	 */
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor si) throws HibernateException, SQLException {
    JdbcNativeExtractor extractor = new JdbcNativeExtractor();
    Connection connection = extractor.getNativeConnection(st.getConnection());
    if (connection.getClass().getName().startsWith(ORACLE_JDBC)) {
        try {
            Object xmlType = null;
            if (value != null) {
                Class<?> clazz = Class.forName(XML_TYPE);
                Constructor<?> con = clazz.getConstructor(Connection.class, String.class);
                xmlType = con.newInstance(connection, (String) value);
                st.setObject(index, xmlType);
            } else {
                /* TODO: 2007 is oracle.jdbc.OracleTypes.OPAQUE, use reflection */
                st.setNull(index, 2007, "SYS.XMLTYPE");
            }
        } catch (Exception e) {
            throw new SQLException("Failed to convert Document to XMLTYPE String for storage", e);
        }
    } else {
        // If not Oracle (i.e. HSQLDB) use the hibernate StringClobType impl of nullSafeSet()
        super.nullSafeSet(st, value, index, si);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SQLException(java.sql.SQLException) HibernateException(org.hibernate.HibernateException)

Example 100 with HibernateException

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

the class ProxoolConnectionProvider method getConfigProperties.

private Properties getConfigProperties(String resource) {
    try {
        Properties properties = new Properties();
        properties.load(classLoaderService.locateResourceStream(resource));
        return properties;
    } catch (IOException e) {
        throw new HibernateException("Unable to load properties from specified config file: " + resource, e);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) IOException(java.io.IOException) Properties(java.util.Properties)

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