Search in sources :

Example 1 with ConnectionNotFoundException

use of org.mifos.framework.exceptions.ConnectionNotFoundException in project head by mifos.

the class LegacyGenericDao method execUniqueResultNamedQueryWithResultTransformer.

@SuppressWarnings("unchecked")
public <T extends Object> T execUniqueResultNamedQueryWithResultTransformer(final String queryName, final Map<String, ?> queryParameters, final Class<T> clazz) {
    try {
        Query query = getSession().getNamedQuery(queryName).setResultTransformer(Transformers.aliasToBean(clazz));
        query.setProperties(queryParameters);
        query.setResultTransformer(Transformers.aliasToBean(clazz));
        return (T) query.uniqueResult();
    } catch (GenericJDBCException gje) {
        throw new ConnectionNotFoundException(gje);
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : ConnectionNotFoundException(org.mifos.framework.exceptions.ConnectionNotFoundException) Query(org.hibernate.Query) GenericJDBCException(org.hibernate.exception.GenericJDBCException) ConnectionNotFoundException(org.mifos.framework.exceptions.ConnectionNotFoundException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GenericJDBCException(org.hibernate.exception.GenericJDBCException) HibernateException(org.hibernate.HibernateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with ConnectionNotFoundException

use of org.mifos.framework.exceptions.ConnectionNotFoundException in project head by mifos.

the class LegacyGenericDao method execUniqueResultNamedQueryWithoutFlush.

public Object execUniqueResultNamedQueryWithoutFlush(final String queryName, final Map<String, ?> queryParameters) throws PersistenceException {
    try {
        Session sess = getSession();
        sess.setFlushMode(FlushMode.MANUAL);
        Query query = getSession().getNamedQuery(queryName);
        logger.debug("The query object for the query with the name  " + queryName + " has been obtained");
        query.setProperties(queryParameters);
        Object returnObject = query.uniqueResult();
        sess.setFlushMode(FlushMode.AUTO);
        return returnObject;
    } catch (GenericJDBCException gje) {
        throw new ConnectionNotFoundException(gje);
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}
Also used : ConnectionNotFoundException(org.mifos.framework.exceptions.ConnectionNotFoundException) Query(org.hibernate.Query) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GenericJDBCException(org.hibernate.exception.GenericJDBCException) ConnectionNotFoundException(org.mifos.framework.exceptions.ConnectionNotFoundException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GenericJDBCException(org.hibernate.exception.GenericJDBCException) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

Example 3 with ConnectionNotFoundException

use of org.mifos.framework.exceptions.ConnectionNotFoundException in project head by mifos.

the class LegacyGenericDao method execUniqueResultNamedQuery.

public Object execUniqueResultNamedQuery(final String queryName, final Map<String, ?> queryParameters) throws PersistenceException {
    try {
        Query query = getSession().getNamedQuery(queryName);
        logger.debug("The query object for the query with the name  " + queryName + " has been obtained");
        query.setProperties(queryParameters);
        return query.uniqueResult();
    } catch (GenericJDBCException gje) {
        throw new ConnectionNotFoundException(gje);
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}
Also used : ConnectionNotFoundException(org.mifos.framework.exceptions.ConnectionNotFoundException) Query(org.hibernate.Query) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GenericJDBCException(org.hibernate.exception.GenericJDBCException) ConnectionNotFoundException(org.mifos.framework.exceptions.ConnectionNotFoundException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GenericJDBCException(org.hibernate.exception.GenericJDBCException) HibernateException(org.hibernate.HibernateException)

Aggregations

HibernateException (org.hibernate.HibernateException)3 Query (org.hibernate.Query)3 GenericJDBCException (org.hibernate.exception.GenericJDBCException)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)3 ConnectionNotFoundException (org.mifos.framework.exceptions.ConnectionNotFoundException)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 Session (org.hibernate.Session)1