Example usage for org.hibernate Query setCacheable

List of usage examples for org.hibernate Query setCacheable

Introduction

In this page you can find the example usage for org.hibernate Query setCacheable.

Prototype

Query<R> setCacheable(boolean cacheable);

Source Link

Document

Enable/disable second level query (result) caching for this query.

Usage

From source file:org.egov.commons.dao.ChartOfAccountsHibernateDAO.java

License:Open Source License

/**
 * @description- This method returns a list of detail type object based on the glcode.
 * @param glCode - glcode supplied by the client.
 * @return List<Accountdetailtype> -list of Accountdetailtype object(s).
 * @throws ApplicationException//w ww . j a va2 s . c o m
 */
@SuppressWarnings("unchecked")
public List<Accountdetailtype> getAccountdetailtypeListByGLCode(final String glCode) {
    if (StringUtils.isBlank(glCode)) {
        throw new ApplicationRuntimeException("GL Code is empty ");
    }
    // checking if the glcode is exists in ChartOfAccounts table.

    CChartOfAccounts cChartOfAccountsByGlCode = getCChartOfAccountsByGlCode(glCode);
    if (cChartOfAccountsByGlCode == null) {
        throw new ApplicationRuntimeException("GL Code not found in Chart of Accounts");
    }
    try {
        Query query = persistenceService.getSession()
                .createQuery("from Accountdetailtype where id in (select cd.detailTypeId "
                        + "from CChartOfAccountDetail  as cd,CChartOfAccounts as c where cd.glCodeId=c.id and c.glcode=:glCode)");
        query.setString("glCode", glCode);
        query.setCacheable(true);
        return query.list().isEmpty() ? null : query.list(); // NOPMD
    } catch (final Exception e) {
        LOG.error(e);
        throw new ApplicationRuntimeException("Error occured while getting Account Detail Types for GL Code ",
                e);
    }
}

From source file:org.egov.commons.dao.ChartOfAccountsHibernateDAO.java

License:Open Source License

/**
 * @author manoranjan// w ww.j av a  2  s . c  om
 * @description -Get list of COA for a list of types.
 * @param type - list of types,e.g income, Assets etc.
 * @return listChartOfAcc - list of chartofaccounts based on the given list of types
 * @throws ValidationException
 */
public List<CChartOfAccounts> getActiveAccountsForTypes(final char[] type) throws ValidationException {
    if ((null == type) || (type.length == 0)) {
        throw new ValidationException(Arrays.asList(new ValidationError("type",
                "The supplied value for Chart of Account Type  can not be null or empty")));
    }
    final Character[] types = new Character[type.length];
    int count = 0;
    for (final char typ : type) {
        types[count++] = typ;
    }
    final Query query = getCurrentSession().createQuery("from CChartOfAccounts where classification=4 "
            + "and isActiveForPosting=true and type in (:type)");

    query.setParameterList("type", types);
    query.setCacheable(true);
    return query.list();
}

From source file:org.egov.commons.dao.ChartOfAccountsHibernateDAO.java

License:Open Source License

/**
 * @author manoranjan/*from   w  w w. j a  va2s  .c o  m*/
 * @description - Get list of Chartofaccount objects for a list of purpose ids
 * @param purposeId - list of purpose ids.
 * @return listChartOfAcc - list of chartofaccount objects for the given list of purpose id
 * @throws ValidationException
 */
public List<CChartOfAccounts> getAccountCodeByListOfPurposeId(final Integer[] purposeId)
        throws ValidationException {
    if ((null == purposeId) || (purposeId.length == 0)) {
        throw new ValidationException(Arrays
                .asList(new ValidationError("purposeId", "The supplied purposeId  can not be null or empty")));
    }
    final List<CChartOfAccounts> listChartOfAcc = new ArrayList<CChartOfAccounts>();
    Query query = getCurrentSession().createQuery(
            " FROM CChartOfAccounts WHERE purposeid in(:purposeId)AND classification=4 AND isActiveForPosting=true ");
    query.setParameterList("purposeId", purposeId);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());

    query = persistenceService.getSession().createQuery(
            " from CChartOfAccounts where parentId IN (select id  FROM CChartOfAccounts WHERE purposeid in (:purposeId) ) AND classification=4 AND isActiveForPosting=true ");
    query.setParameterList("purposeId", purposeId);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());

    query = persistenceService.getSession().createQuery(
            " from CChartOfAccounts where   parentId IN (select id from CChartOfAccounts where parentId IN (select id  FROM CChartOfAccounts WHERE purposeid in (:purposeId))) AND classification=4 AND isActiveForPosting=true");
    query.setParameterList("purposeId", purposeId);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());

    query = persistenceService.getSession().createQuery(
            " from CChartOfAccounts where   parentId IN (select id from  CChartOfAccounts where   parentId IN (select id from CChartOfAccounts where parentId IN (select id  FROM CChartOfAccounts WHERE purposeid in (:purposeId)))) AND classification=4 AND isActiveForPosting=true ");
    query.setParameterList("purposeId", purposeId);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());

    return listChartOfAcc;
}

From source file:org.egov.commons.dao.ChartOfAccountsHibernateDAO.java

License:Open Source License

/**
 * @author manoranjan//from   ww  w  .  j  a v a 2s . com
 * @description - This api will return the list of detailed chartofaccounts objects that are active for posting.
 * @param glcode - The input is the chartofaccounts code.
 */
public List<CChartOfAccounts> getListOfDetailCode(final String glCode) throws ValidationException {
    if (StringUtils.isBlank(glCode)) {
        throw new ValidationException(Arrays.asList(
                new ValidationError("glcode null", "the glcode value supplied can not be null or blank")));
    }
    Query query = getCurrentSession().createQuery("from CChartOfAccounts where glcode=:glCode");
    query.setString("glCode", glCode);
    query.setCacheable(true);
    if (query.list().isEmpty()) {
        throw new ValidationException(Arrays.asList(new ValidationError("glcode not exist",
                "The GL Code value supplied does not exist in the System")));
    }
    final List<CChartOfAccounts> listChartOfAcc = new ArrayList<CChartOfAccounts>();
    query = getCurrentSession().createQuery(
            " FROM CChartOfAccounts WHERE glcode=:glCode  AND classification=4 AND isActiveForPosting=true ");
    query.setString("glCode", glCode);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());
    query = getCurrentSession().createQuery(
            " from CChartOfAccounts where parentId IN (select id  FROM CChartOfAccounts WHERE glcode=:glCode) AND classification=4 AND isActiveForPosting=true ");
    query.setString("glCode", glCode);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());
    query = getCurrentSession().createQuery(
            " from CChartOfAccounts where parentId IN (select id from CChartOfAccounts where parentId IN ( select id  FROM CChartOfAccounts WHERE glcode=:glCode)) AND classification=4 AND isActiveForPosting=true ");
    query.setString("glCode", glCode);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());
    query = getCurrentSession().createQuery(
            " from CChartOfAccounts where parentId IN (select id from  CChartOfAccounts where   parentId IN (select id from CChartOfAccounts where parentId IN ( select id  FROM CChartOfAccounts WHERE glcode=:glCode)))AND classification=4 AND isActiveForPosting=true ");

    query.setString("glCode", glCode);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());
    return listChartOfAcc;
}

From source file:org.egov.commons.dao.ChartOfAccountsHibernateDAO.java

License:Open Source License

/**
 * @description - Get list of Chartofaccount objects for a list of purpose names
 * @param purposeNames - list of purpose names.
 * @return listChartOfAcc - list of chartofaccount objects for the given list of purpose names
 * @throws ValidationException/*w  w  w.j av a 2  s.  co  m*/
 */
public List<CChartOfAccounts> getAccountCodeByListOfPurposeName(final String[] purposeNames)
        throws ValidationException {
    if ((null == purposeNames) || (purposeNames.length == 0)) {
        throw new ValidationException(Arrays
                .asList(new ValidationError("purposeId", "The supplied purposeId  can not be null or empty")));
    }
    final List<CChartOfAccounts> listChartOfAcc = new ArrayList<CChartOfAccounts>();
    Query query = getCurrentSession().createQuery(
            "SELECT coa  FROM CChartOfAccounts coa,EgfAccountcodePurpose purpose WHERE coa.purposeId = purpose.id and purpose.name in(:purposeNames)AND coa.classification=4 AND coa.isActiveForPosting=true ");
    query.setParameterList("purposeNames", purposeNames);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());

    query = persistenceService.getSession().createQuery(
            " from CChartOfAccounts where parentId IN (select coa.id  FROM CChartOfAccounts coa,EgfAccountcodePurpose purpose WHERE coa.purposeId = purpose.id and purpose.name in (:purposeNames) ) AND classification=4 AND isActiveForPosting=true ");
    query.setParameterList("purposeNames", purposeNames);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());

    query = persistenceService.getSession().createQuery(
            " from CChartOfAccounts where   parentId IN (select id from CChartOfAccounts where parentId IN (select coa.id  FROM CChartOfAccounts coa,EgfAccountcodePurpose purpose WHERE coa.purposeId = purpose.id and purpose.name in (:purposeNames) )) AND classification=4 AND isActiveForPosting=true");
    query.setParameterList("purposeNames", purposeNames);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());

    query = persistenceService.getSession().createQuery(
            " from CChartOfAccounts where   parentId IN (select id from  CChartOfAccounts where   parentId IN (select id from CChartOfAccounts where parentId IN (select coa.id  FROM CChartOfAccounts coa,EgfAccountcodePurpose purpose WHERE coa.purposeId = purpose.id and purpose.name in (:purposeNames) ))) AND classification=4 AND isActiveForPosting=true ");
    query.setParameterList("purposeNames", purposeNames);
    query.setCacheable(true);
    listChartOfAcc.addAll(query.list());

    return listChartOfAcc;
}

From source file:org.egov.commons.dao.FinancialYearHibernateDAO.java

License:Open Source License

public CFinancialYear getFinancialYearByFinYearRange(String finYearRange) {
    Query query = getCurrentSession()
            .createQuery("from CFinancialYear cfinancialyear where cfinancialyear.finYearRange=:finYearRange");
    query.setString("finYearRange", finYearRange);
    query.setCacheable(true);
    return (CFinancialYear) query.uniqueResult();
}

From source file:org.egov.commons.dao.FiscalPeriodHibernateDAO.java

License:Open Source License

/**
* 
*//*  w  ww.j  a  v a2  s.  c o m*/
public CFiscalPeriod getFiscalPeriodByDate(Date voucherDate) {
    Query query = getCurrentSession()
            .createQuery("from CFiscalPeriod fp where  :voucherDate between fp.startingDate and fp.endingDate");
    query.setDate("voucherDate", voucherDate);
    query.setCacheable(true);
    return (CFiscalPeriod) query.uniqueResult();
}

From source file:org.gaia.dao.legalEntity.LegalEntityAccessor.java

License:Open Source License

/**
 * get the agreement between two entities
 *
 * @param entityId1/*from w w  w  .j av a2 s.co  m*/
 * @param entityId2
 * @return
 */
public static Agreement getAgreementByEntities(Integer entityId1, Integer entityId2) {
    Agreement returnValue = null;
    String query = "from Agreement a where a.legalEntity1=:entity1 and a.legalEntity2=:entity2";

    Session session = HibernateUtil.getSession();
    Transaction transaction = null;
    try {
        transaction = session.beginTransaction();
        Query queryObject = session.createQuery(query);
        queryObject.setInteger("entity1", entityId1);
        queryObject.setInteger("entity2", entityId2);
        queryObject.setCacheable(true).uniqueResult();
        List<Serializable> resultList = queryObject.list();
        if (resultList.size() > 0) {
            returnValue = (Agreement) resultList.get(0);
        }
        session.getTransaction().commit();
    } catch (HibernateException e) {
        if (transaction != null) {
            transaction.rollback();
        }
        logger.error(StringUtils.formatErrorMessage(e));
    } finally {
        session.close();
    }
    return returnValue;
}

From source file:org.gbif.portal.dao.geospatial.impl.hibernate.GeoRegionDAOImpl.java

License:Open Source License

public List getGeoRegionsForCountry(final String isoCountryCode) {
    HibernateTemplate template = getHibernateTemplate();
    return (List) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session
                    .createQuery("select id, name from GeoRegion where isoCountryCode=? order by name");
            query.setParameter(0, isoCountryCode);
            query.setCacheable(true);
            return query.list();
        }// w  w w.  java2  s  .  c  o m
    });
}

From source file:org.gbif.portal.dao.occurrence.impl.hibernate.IdentifierRecordDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.occurrence.IdentifierRecordDAO#getIdentifierRecordsForOccurrenceRecord(long)
 *//*  w w  w .  jav  a2s.  c om*/
@SuppressWarnings("unchecked")
public List<IdentifierRecord> getIdentifierRecordsForOccurrenceRecord(final long occurrenceRecordId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<IdentifierRecord>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery("from IdentifierRecord ir" + " where ir.occurrenceRecordId = ?");
            query.setParameter(0, occurrenceRecordId);
            query.setCacheable(true);
            return query.list();
        }
    });
}