List of usage examples for org.hibernate Query setShort
@Deprecated @SuppressWarnings("unchecked") default Query<R> setShort(String name, short val)
From source file:org.mifos.framework.hibernate.helper.QueryResultAccountIdSearch.java
License:Open Source License
@Override public List<Object> get(int position, int noOfObjects) throws HibernateSearchException { List<Object> returnList = new ArrayList<Object>(); try {/*from w w w . ja va2s . c om*/ Session session = StaticHibernateUtil.getSessionTL(); Query query = prepareQuery(session, queryInputs.getQueryStrings()[1]); list = query.list(); this.queryInputs.setTypes(query.getReturnTypes()); dtoBuilder.setInputs(queryInputs); if (list != null) { for (int i = 0; i < list.size(); i++) { if (buildDTO) { Object record = buildDTO((Object[]) list.get(i)); CustomerSearchDto search = (CustomerSearchDto) record; Integer customerId = search.getCustomerId(); short customerLevel = search.getCustomerType(); query = session.getNamedQuery(NamedQueryConstants.ACCOUNT_LIST_ID_SEARCH); query.setInteger("customerId", customerId).setShort("loanAccountTypeId", CustomerSearchConstants.LOAN_TYPE); query.setShort("groupLoanAccountTypeId", CustomerSearchConstants.GROUP_LOAN_TYPE); query.setShort("savingsAccountTypeId", CustomerSearchConstants.SAVINGS_TYPE); query.setString("searchString", searchString); List<?> accountNumAndTypeId = query.list(); Object[] obj2 = (Object[]) accountNumAndTypeId.get(0); search.setLoanGlobalAccountNumber(obj2[0].toString()); Short accountTypeId = (Short) obj2[1]; search.setCustomerType(deduceCustomerType(customerLevel, accountTypeId)); returnList.add(search); } else { if (i < noOfObjects) { returnList.add(list.get(i)); } } } } StaticHibernateUtil.closeSession(); } catch (Exception e) { throw new HibernateSearchException(HibernateConstants.SEARCH_FAILED, e); } return returnList; }
From source file:org.mifos.framework.hibernate.helper.QueryResultsMainSearchImpl.java
License:Open Source License
@Override public java.util.List get(int position, int noOfObjects) throws HibernateSearchException { java.util.List returnList = new java.util.ArrayList(); java.util.List list = new java.util.ArrayList(); Session session = null;/*w w w.j a v a 2 s . co m*/ try { session = StaticHibernateUtil.getSessionTL(); Query query = prepareQuery(session, queryInputs.getQueryStrings()[1]); query.setFirstResult(position); query.setMaxResults(noOfObjects); list = query.list(); this.queryInputs.setTypes(query.getReturnTypes()); dtoBuilder.setInputs(queryInputs); Query query1 = session.createQuery( "select account.globalAccountNum " + "from org.mifos.accounts.business.AccountBO account " + "where account.customer.customerId=:customerId" + " and account.accountType.accountTypeId=:accountTypeId" + " and account.accountState.id not in (6,7,10,15,17,18) "); if (list != null) { for (int i = 0; i < list.size(); i++) { if (buildDTO) { Object record = buildDTO((Object[]) list.get(i)); CustomerSearchDto cs = ((CustomerSearchDto) record); query1.setInteger("customerId", cs.getCustomerId()).setShort("accountTypeId", (short) 1); cs.setLoanGlobalAccountNum(query1.list()); query1.setShort("accountTypeId", (short) 5); cs.setGroupLoanGlobalAccountNum(query1.list()); query1.setShort("accountTypeId", (short) 2); cs.setSavingsGlobalAccountNum(query1.list()); returnList.add(cs); } else { if (i < noOfObjects) { returnList.add(list.get(i)); } } } } StaticHibernateUtil.closeSession(); } catch (Exception e) { throw new HibernateSearchException(HibernateConstants.SEARCH_FAILED, e); } return returnList; }
From source file:org.mifos.security.rolesandpermission.business.RoleActivityEntityIntegrationTest.java
License:Open Source License
private RoleActivityEntity getRoleActivity(Short roleId, Short activityId) { Query query = StaticHibernateUtil.getSessionTL().createQuery( "from org.mifos.security.rolesandpermission.business.RoleActivityEntity roleActivity where roleActivity.role=? and roleActivity.activity=?"); query.setShort(0, roleId); query.setShort(1, activityId);/*from w w w .j a va2s. com*/ RoleActivityEntity roleActivityEntity = (RoleActivityEntity) query.uniqueResult(); return roleActivityEntity; }
From source file:org.mifos.security.rolesandpermission.persistence.LegacyRolesPermissionsDao.java
License:Open Source License
/** * This function returns the PersonRoles object which contains the person * information and the set of all the roles related to that user * * @param uid//w w w. j a v a 2s .c o m * user id * @return PersonRoles * @throws HibernateProcessException */ public Set getUserRoles(short uid) throws SystemException, ApplicationException { Set roles = null; try { Session session = StaticHibernateUtil.getSessionTL(); Query personRoles = session.getNamedQuery(NamedQueryConstants.GETPERSONROLES); personRoles.setShort("ID", uid); List<PersonRoles> lst = personRoles.list(); if (null != lst && lst.size() > 0) { PersonRoles pr = lst.get(0); roles = pr.getRoles(); } } catch (HibernateException he) { throw new SecurityException(SecurityConstants.GENERALERROR, he); } return roles; }
From source file:org.mifos.security.util.SecurityHelper.java
License:Open Source License
/** * This function returns the PersonRoles object which contains the person * information and the set of all the roles related to that user * * @param uid/*from ww w . j a va 2 s . c o m*/ * user id * @return PersonRoles * @throws HibernateProcessException */ public static Set getUserRoles(short uid) throws SystemException, ApplicationException { Set roles = null; Session session = null; Transaction transaction = null; Query personRoles = null; try { session = StaticHibernateUtil.openSession(); transaction = session.beginTransaction(); personRoles = session.getNamedQuery(NamedQueryConstants.GETPERSONROLES); personRoles.setShort("ID", uid); List<PersonRoles> lst = personRoles.list(); transaction.commit(); if (null != lst && lst.size() > 0) { PersonRoles pr = lst.get(0); roles = pr.getRoles(); } } catch (HibernateProcessException e) { transaction.rollback(); throw new SystemException(e); } catch (HibernateException he) { transaction.rollback(); throw new SecurityException(SecurityConstants.GENERALERROR, he); } finally { StaticHibernateUtil.closeSession(session); } return roles; }