Search in sources :

Example 86 with Session

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

the class GenericDaoHibernate method update.

@Override
public final void update(final Object entity) {
    try {
        Session session = getSession();
        session.update(entity);
        AuditInterceptor interceptor = (AuditInterceptor) StaticHibernateUtil.getInterceptor();
        if (interceptor.isAuditLogRequired()) {
            interceptor.createChangeValueMap(entity);
        }
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Session(org.hibernate.Session) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 87 with Session

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

the class GenericDaoHibernate method executeNamedQueryWithOffsetAndOrderAppend.

@SuppressWarnings("unchecked")
@Override
public final List<? extends Object> executeNamedQueryWithOffsetAndOrderAppend(final String queryName, final Map<String, ?> queryParameters, int position, int noOfObjects) {
    try {
        Session session = getSession();
        StringBuilder stringBuilder = new StringBuilder(session.getNamedQuery(queryName).getQueryString());
        stringBuilder.append(" ORDER BY ");
        stringBuilder.append(queryParameters.get("ordering"));
        Query query = session.createQuery(stringBuilder.toString());
        query.setProperties(queryParameters);
        query.setFirstResult(position);
        query.setMaxResults(noOfObjects);
        return query.list();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : Query(org.hibernate.Query) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Session(org.hibernate.Session) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 88 with Session

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

the class ReportsPersistence method createReportsDataSource.

public void createReportsDataSource(ReportsDataSource reportsDataSource) throws ApplicationException, SystemException {
    Session session = null;
    try {
        session = StaticHibernateUtil.getSessionTL();
        StaticHibernateUtil.startTransaction();
        session.save(reportsDataSource);
        session.flush();
        StaticHibernateUtil.commitTransaction();
    } catch (HibernateProcessException hpe) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ApplicationException(hpe);
    } catch (HibernateException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) HibernateException(org.hibernate.HibernateException) ReportException(org.mifos.reports.exceptions.ReportException) SystemException(org.mifos.framework.exceptions.SystemException) ReportException(org.mifos.reports.exceptions.ReportException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Session(org.hibernate.Session)

Example 89 with Session

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

the class EntityMasterData method init.

/**
     * This method creates a map of entity master table as sets it into the
     * servletcontext so that it is available till the application is up.
     *
     * @throws HibernateProcessException
     */
public void init() throws HibernateProcessException {
    Session session = null;
    try {
        session = StaticHibernateUtil.getSessionTL();
        Query query = session.getNamedQuery(NamedQueryConstants.GET_ENTITY_MASTER);
        List<EntityMaster> entityMasterData = query.list();
        for (EntityMaster entityMaster : entityMasterData) {
            entityMap.put(entityMaster.getEntityType(), entityMaster.getId());
        }
    } catch (HibernateException e) {
        logger.error("table entity_master could not be fetched", e);
    }
}
Also used : Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) EntityMaster(org.mifos.framework.business.EntityMaster) Session(org.hibernate.Session)

Example 90 with Session

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

the class ReportsPersistence method getReport.

public ReportsBO getReport(Short reportId) {
    Session session = null;
    session = StaticHibernateUtil.getSessionTL();
    return (ReportsBO) session.load(ReportsBO.class, reportId);
}
Also used : Session(org.hibernate.Session) ReportsBO(org.mifos.reports.business.ReportsBO)

Aggregations

Session (org.hibernate.Session)4457 Test (org.junit.Test)2517 Transaction (org.hibernate.Transaction)1327 List (java.util.List)576 ArrayList (java.util.ArrayList)475 Test (org.testng.annotations.Test)411 TestForIssue (org.hibernate.testing.TestForIssue)389 Query (org.hibernate.Query)345 HibernateException (org.hibernate.HibernateException)299 DAOException (com.tomasio.projects.trainning.exception.DAOException)186 Criteria (org.hibernate.Criteria)174 Date (java.util.Date)134 Iterator (java.util.Iterator)127 SkipForDialect (org.hibernate.testing.SkipForDialect)114 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)113 SQLException (java.sql.SQLException)108 Map (java.util.Map)105 SessionFactory (org.hibernate.SessionFactory)105 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)104 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)104