Example usage for org.hibernate Query setProperties

List of usage examples for org.hibernate Query setProperties

Introduction

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

Prototype

Query<R> setProperties(Map bean);

Source Link

Document

Bind the values of the given Map for each named parameters of the query, matching key names with parameter names and mapping value types to Hibernate types using heuristics.

Usage

From source file:org.mifos.accounts.savings.persistence.GenericDaoHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from w  ww .  j a  va2 s.  c om*/
public final List<? extends Object> executeNamedQueryWithResultTransformer(final String queryName,
        final Map<String, ?> nameQueryParameters, final Class<?> className) {

    try {
        Session session = getSession();
        Query query = session.getNamedQuery(queryName)
                .setResultTransformer(Transformers.aliasToBean(className));
        query.setProperties(nameQueryParameters);
        return query.list();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}

From source file:org.mifos.accounts.savings.persistence.GenericDaoHibernate.java

License:Open Source License

@Override
public final Object executeUniqueResultNamedQueryWithResultTransformer(final String queryName,
        final Map<String, ?> nameQueryParameters, final Class<?> className) {

    try {/*w ww  .ja v a  2  s .co m*/
        Session session = getSession();
        Query query = session.getNamedQuery(queryName)
                .setResultTransformer(Transformers.aliasToBean(className));
        query.setProperties(nameQueryParameters);
        return query.uniqueResult();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}

From source file:org.mifos.accounts.savings.persistence.GenericDaoHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w ww .  j  a  v  a 2 s . co  m*/
public final List<? extends Object> executeNamedQuery(final String queryName,
        final Map<String, ?> queryParameters) {

    try {
        Session session = getSession();
        Query query = session.getNamedQuery(queryName);
        query.setProperties(queryParameters);
        return query.list();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}

From source file:org.mifos.accounts.savings.persistence.GenericDaoHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  w w w.j a  v  a 2 s .  co  m
public final List<? extends Object> executeNamedQueryWithOffset(final String queryName,
        final Map<String, ?> queryParameters, int position, int noOfObjects) {

    try {
        Session session = getSession();
        Query query = session.getNamedQuery(queryName);
        query.setProperties(queryParameters);
        query.setFirstResult(position);
        query.setMaxResults(noOfObjects);
        return query.list();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}

From source file:org.mifos.accounts.savings.persistence.GenericDaoHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* w  w w. ja v  a2  s  .c  o m*/
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);
    }
}

From source file:org.mifos.accounts.savings.persistence.GenericDaoHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  w  ww . j a  va2  s . co m
public final int executeNamedQueryDelete(final String queryName, final Map<String, ?> queryParameters) {

    try {
        Session session = getSession();
        Query query = session.getNamedQuery(queryName);
        query.setProperties(queryParameters);
        return query.executeUpdate();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}

From source file:org.mifos.accounts.savings.persistence.GenericDaoHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   w  w  w  . ja v  a  2  s . c  o  m
public final Iterator<? extends Object> executeNamedQueryIterator(final String queryName,
        final Map<String, ?> queryParameters) {

    try {
        Session session = getSession();
        Query query = session.getNamedQuery(queryName);
        query.setProperties(queryParameters);
        return query.iterate();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}

From source file:org.mifos.accounts.savings.persistence.GenericDaoHibernate.java

License:Open Source License

@Override
public final Object executeUniqueResultNamedQuery(final String queryName,
        final Map<String, ?> queryParameters) {

    try {/*from w  w w .j a  v a2 s . c o  m*/
        Session session = getSession();
        Query query = session.getNamedQuery(queryName);
        query.setProperties(queryParameters);
        return query.uniqueResult();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}

From source file:org.mifos.customers.business.CustomerAccountBO.java

License:Open Source License

@Override
public Money getTotalAmountInArrears() {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("ACTION_DATE", DateUtils.getCurrentDateWithoutTimeStamp());
    queryParameters.put("CUSTOMER_ID", getAccountId());
    Query query = StaticHibernateUtil.getSessionTL()
            .getNamedQuery(NamedQueryConstants.RETRIEVE_TOTAL_AMOUNT_IN_ARREARS);
    query.setProperties(queryParameters);

    BigDecimal total = (BigDecimal) query.uniqueResult();

    if (total == null) {
        total = new BigDecimal(0);
    }/*from w  w  w .  j  ava 2s.  c  o m*/

    return new Money(getCurrency(), total);
}

From source file:org.mifos.framework.persistence.LegacyGenericDao.java

License:Open Source License

/**
 * This method takes the name of a named query to be executed as well as a
 * list of parameters that the query uses. It assumes the session is open.
 *//*from   w  w  w.  j  a v  a2 s  .  c om*/
@SuppressWarnings("unchecked")
public List executeNamedQuery(final String queryName, final Map<String, ?> queryParameters)
        throws PersistenceException {
    try {
        Query query = createdNamedQuery(queryName);
        query.setProperties(queryParameters);
        return query.list();
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}