List of usage examples for org.hibernate Query setBoolean
@Deprecated @SuppressWarnings("unchecked") default Query<R> setBoolean(String name, boolean val)
From source file:org.jpos.ee.status.StatusManager.java
License:Open Source License
public List findByExpired(boolean expired) throws SQLException, HibernateException { Query q = db.session().createQuery("from org.jpos.ee.status.Status where expired=:expired"); q.setBoolean("expired", expired); return q.list(); }
From source file:org.olat.course.statistic.export.SQLLogExporter.java
License:Apache License
/** * @TODO: charSet is currently ignored!!!!! * @see org.olat.course.statistic.export.ICourseLogExporter#exportCourseLog(java.io.File, java.lang.String, java.lang.Long, java.util.Date, java.util.Date, boolean) */// w w w .j a v a 2 s .com @Override public void exportCourseLog(final File outFile, final String charSet, final Long resourceableId, final Date begin, Date end, final boolean resourceAdminAction, final boolean anonymize) { log_.info("exportCourseLog: BEGIN outFile=" + outFile + ", charSet=" + charSet + ", resourceableId=" + resourceableId + ", begin=" + begin + ", end=" + end + ", resourceAdminAction=" + resourceAdminAction + ", anonymize=" + anonymize); try { if (!outFile.exists()) { if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { throw new IllegalArgumentException( "Cannot create parent of OutFile " + outFile.getAbsolutePath()); } if (!outFile.createNewFile()) { throw new IllegalArgumentException("Cannot create outFile " + outFile.getAbsolutePath()); } } } catch (final IOException e) { e.printStackTrace(); throw new IllegalArgumentException("Cannot create outFile " + outFile.getAbsolutePath()); } if (!outFile.delete()) { throw new IllegalStateException("Could not delete temporary outfile " + outFile.getAbsolutePath()); } // try to make sure the database can write into this directory if (!outFile.getParentFile().setWritable(true, false)) { log_.warn("exportCourseLog: COULD NOT SET DIR TO WRITEABLE: " + outFile.getParent()); } String query = String.valueOf(anonymize ? anonymizedUserSql_ : nonAnonymizedUserSql_); if (begin != null) { query = query.concat(" AND (v.creationDate >= :createdAfter)"); } if (end != null) { query = query.concat(" AND (v.creationDate <= :createdBefore)"); } final Session session = sessionFactory_.openSession(); final long startTime = System.currentTimeMillis(); try { session.beginTransaction(); final Query dbQuery = session.createSQLQuery(query); dbQuery.setBoolean("resAdminAction", resourceAdminAction); dbQuery.setString("resId", Long.toString(resourceableId)); if (begin != null) { dbQuery.setDate("createdAfter", begin); } if (end != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(end); cal.add(Calendar.DAY_OF_MONTH, 1); end = cal.getTime(); dbQuery.setDate("createdBefore", end); } dbQuery.setString("outFile", outFile.getAbsolutePath()); dbQuery.scroll(); } catch (final RuntimeException e) { e.printStackTrace(System.out); } catch (final Error er) { er.printStackTrace(System.out); } finally { if (session != null) { session.close(); } final long diff = System.currentTimeMillis() - startTime; log_.info("exportCourseLog: END DURATION=" + diff + ", outFile=" + outFile + ", charSet=" + charSet + ", resourceableId=" + resourceableId + ", begin=" + begin + ", end=" + end + ", resourceAdminAction=" + resourceAdminAction + ", anonymize=" + anonymize); } }
From source file:org.opencustomer.db.dao.system.RoleDAO.java
License:Mozilla Public License
public List<RoleVO> getList(String name, AdminSelect adminSelect, Sort sort, Page page, UserVO user) { String _name = toLower(adjustWildcards(name)); List<RoleVO> list = new ArrayList<RoleVO>(); try {//from w w w . ja v a 2 s .c o m StringBuilder hql = new StringBuilder(); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE 1=1 "); if (name != null) hql.append(" AND lower(e.name) like :name "); if (!adminSelect.equals(AdminSelect.ALL)) hql.append(" AND admin like :admin "); if (user != null) { if (!user.getProfile().getRole().isAdmin()) hql.append(" AND e.admin = 0 "); hql.append(" AND (e.accessGlobal != '" + EntityAccess.Access.NONE + "' "); hql.append(" OR (e.accessGroup != '" + EntityAccess.Access.NONE + "' "); hql.append(" AND exists (from ").append(UserVO.class.getName()) .append(" as u where u.id = :userId and u.profile.usergroups.id = e.ownerGroup)) "); hql.append(" OR (e.accessUser != '" + EntityAccess.Access.NONE + "' "); hql.append(" AND e.ownerUser = :userId)) "); } if (sort != null) hql.append(" order by " + getSortString(sort)); Query query = HibernateContext.getSession().createQuery(hql.toString()); if (name != null) query.setString("name", _name); if (user != null) query.setInteger("userId", user.getId()); if (adminSelect.equals(AdminSelect.ADMIN)) query.setBoolean("admin", true); else if (adminSelect.equals(AdminSelect.NOT_ADMIN)) query.setBoolean("admin", false); if (page != null) { query.setFirstResult(getFirstResult(page)); query.setMaxResults(getMaxResults(page)); } list = toTypeSafeList(query.list()); if (log.isDebugEnabled()) log.debug("found " + list.size() + " roles"); } catch (HibernateException e) { log.error("Could not find roles", e); throw e; } return list; }
From source file:org.opencustomer.db.dao.system.RoleDAO.java
License:Mozilla Public License
public long countList(String name, AdminSelect adminSelect, UserVO user) { String _name = toLower(adjustWildcards(name)); long count = 0; try {/*from w w w . j a v a 2 s . c o m*/ StringBuilder hql = new StringBuilder(); hql.append(" SELECT count(e.id) "); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE 1=1 "); if (name != null) hql.append(" AND lower(e.name) like :name "); if (!adminSelect.equals(AdminSelect.ALL)) hql.append(" AND admin like :admin "); if (user != null) { if (!user.getProfile().getRole().isAdmin()) hql.append(" AND e.admin = 0 "); hql.append(" AND (e.accessGlobal != '" + EntityAccess.Access.NONE + "' "); hql.append(" OR (e.accessGroup != '" + EntityAccess.Access.NONE + "' "); hql.append(" AND exists (from ").append(UserVO.class.getName()) .append(" as u where u.id = :userId and u.profile.usergroups.id = e.ownerGroup)) "); hql.append(" OR (e.accessUser != '" + EntityAccess.Access.NONE + "' "); hql.append(" AND e.ownerUser = :userId)) "); } Query query = HibernateContext.getSession().createQuery(hql.toString()); if (name != null) query.setString("name", _name); if (user != null) query.setInteger("userId", user.getId()); if (adminSelect.equals(AdminSelect.ADMIN)) query.setBoolean("admin", true); else if (adminSelect.equals(AdminSelect.NOT_ADMIN)) query.setBoolean("admin", false); count = (Long) query.uniqueResult(); if (log.isDebugEnabled()) log.debug("count " + count + " roles"); } catch (HibernateException e) { log.error("Could not find roles", e); throw e; } return count; }
From source file:org.opencustomer.db.dao.system.UsergroupDAO.java
License:Mozilla Public License
public List<UsergroupVO> getList(String name, AdminSelect adminSelect, Sort sort, Page page, UserVO user) { String _name = toLower(adjustWildcards(name)); List<UsergroupVO> list = new ArrayList<UsergroupVO>(); try {//from w w w . j av a2 s . c o m StringBuilder hql = new StringBuilder(); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE 1=1 "); if (name != null) hql.append(" AND lower(e.name) like :name "); if (!adminSelect.equals(AdminSelect.ALL)) hql.append(" AND admin like :admin "); if (user != null) { if (!user.getProfile().getRole().isAdmin()) hql.append(" AND e.admin = 0 "); hql.append(" AND (e.accessGlobal != '" + EntityAccess.Access.NONE + "' "); hql.append(" OR (e.accessGroup != '" + EntityAccess.Access.NONE + "' "); hql.append(" AND exists (from ").append(UserVO.class.getName()) .append(" as u where u.id = :userId and u.profile.usergroups.id = e.ownerGroup)) "); hql.append(" OR (e.accessUser != '" + EntityAccess.Access.NONE + "' "); hql.append(" AND e.ownerUser = :userId)) "); } if (sort != null) hql.append(" order by " + getSortString(sort)); Query query = HibernateContext.getSession().createQuery(hql.toString()); if (name != null) query.setString("name", _name); if (adminSelect.equals(AdminSelect.ADMIN)) query.setBoolean("admin", true); else if (adminSelect.equals(AdminSelect.NOT_ADMIN)) query.setBoolean("admin", false); if (user != null) query.setInteger("userId", user.getId()); if (page != null) { query.setFirstResult(getFirstResult(page)); query.setMaxResults(getMaxResults(page)); } list = toTypeSafeList(query.list()); if (log.isDebugEnabled()) log.debug("found " + list.size() + " usergroups"); } catch (HibernateException e) { log.error("Could not find usergroups", e); throw e; } return list; }
From source file:org.opencustomer.db.dao.system.UsergroupDAO.java
License:Mozilla Public License
public long countList(String name, AdminSelect adminSelect, UserVO user) { String _name = toLower(adjustWildcards(name)); long count = 0; try {//from w w w .j ava2s . com StringBuilder hql = new StringBuilder(); hql.append(" SELECT count(e.id) "); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE 1=1 "); if (name != null) hql.append(" AND lower(e.name) like :name "); if (!adminSelect.equals(AdminSelect.ALL)) hql.append(" AND admin like :admin "); if (user != null) { if (!user.getProfile().getRole().isAdmin()) hql.append(" AND e.admin = 0 "); hql.append(" AND (e.accessGlobal != '" + EntityAccess.Access.NONE + "' "); hql.append(" OR (e.accessGroup != '" + EntityAccess.Access.NONE + "' "); hql.append(" AND exists (from ").append(UserVO.class.getName()) .append(" as u where u.id = :userId and u.profile.usergroups.id = e.ownerGroup)) "); hql.append(" OR (e.accessUser != '" + EntityAccess.Access.NONE + "' "); hql.append(" AND e.ownerUser = :userId)) "); } Query query = HibernateContext.getSession().createQuery(hql.toString()); if (name != null) query.setString("name", _name); if (adminSelect.equals(AdminSelect.ADMIN)) query.setBoolean("admin", true); else if (adminSelect.equals(AdminSelect.NOT_ADMIN)) query.setBoolean("admin", false); if (user != null) query.setInteger("userId", user.getId()); count = (Long) query.uniqueResult(); if (log.isDebugEnabled()) log.debug("count " + count + " usergroups"); } catch (HibernateException e) { log.error("Could not find usergroups", e); throw e; } return count; }
From source file:org.openhie.openempi.dao.hibernate.MatchPairStatDaoHibernate.java
License:Apache License
private void addMatchPairStatInHibernate(Session session, String tableName, MatchPairStat matchPairStat) { log.debug("Saving matchPairStat record: " + matchPairStat); String tableFullName = getTableFullName(tableName); boolean generateId = (matchPairStat.getMatchPairStatId() == null); StringBuilder sqlInsert = new StringBuilder("INSERT INTO public." + tableFullName + " (" + MATCH_PAIR_STAT_ID_COLUMN_NAME + ", " + LEFT_PERSON_PSEUDO_ID_COLUMN_NAME + ", " + RIGHT_PERSON_PSEUDO_ID_COLUMN_NAME + ", " + MATCH_STATE_COLUMN_NAME + ") VALUES (" + (generateId ? ("nextval('" + tableFullName + SEQUENCE_NAME_POSTFIX + "')") : "?") + ",?,?,?)" + (generateId ? (" RETURNING " + MATCH_PAIR_STAT_ID_COLUMN_NAME) : "") + ";"); Query query = session.createSQLQuery(sqlInsert.toString()); int position = 0; if (!generateId) { query.setLong(position, matchPairStat.getMatchPairStatId()); position++;/*from w ww. j a v a2s . c o m*/ } query.setLong(position, matchPairStat.getLeftPersonPseudoId()); position++; query.setLong(position, matchPairStat.getRightPersonPseudoId()); position++; query.setBoolean(position, matchPairStat.getMatchStatus()); if (generateId) { BigInteger bigInt = (BigInteger) query.uniqueResult(); long id = bigInt.longValue(); matchPairStat.setMatchPairStatId(id); log.debug("Finished saving the matchPairStat with id " + id); } else { query.executeUpdate(); log.debug("Finished saving the matchPairStat with id " + matchPairStat.getRightPersonPseudoId()); } }
From source file:org.openhie.openempi.dao.hibernate.MatchPairStatHalfDaoHibernate.java
License:Apache License
private void addMatchPairStatHalfInHibernate(Session session, String tableName, MatchPairStatHalf matchPairStatHalf) { log.debug("Saving matchPairStatHalf record: " + matchPairStatHalf); String tableFullName = getTableFullName(tableName); boolean generateId = (matchPairStatHalf.getMatchPairStatHalfId() == null); StringBuilder sqlInsert = new StringBuilder("INSERT INTO public." + tableFullName + " (" + MATCH_PAIR_STAT_HALF_ID_COLUMN_NAME + ", " + PERSON_PSEUDO_ID_COLUMN_NAME + ", " + MATCH_STATE_COLUMN_NAME + ") VALUES (" + (generateId ? ("nextval('" + tableFullName + SEQUENCE_NAME_POSTFIX + "')") : "?") + ",?,?)" + (generateId ? (" RETURNING " + MATCH_PAIR_STAT_HALF_ID_COLUMN_NAME) : "") + ";"); Query query = session.createSQLQuery(sqlInsert.toString()); int position = 0; if (!generateId) { query.setLong(position, matchPairStatHalf.getMatchPairStatHalfId()); position++;/*from www . ja va 2 s .c o m*/ } query.setLong(position, matchPairStatHalf.getPersonPseudoId()); position++; query.setBoolean(position, matchPairStatHalf.getMatchStatus()); if (generateId) { BigInteger bigInt = (BigInteger) query.uniqueResult(); long id = bigInt.longValue(); matchPairStatHalf.setMatchPairStatHalfId(id); log.debug("Finished saving the matchPairStatHalf with id " + id); } else { query.executeUpdate(); log.debug("Finished saving the matchPairStatHalf with id " + matchPairStatHalf.getPersonPseudoId()); } }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
public Cohort getPatientsHavingDrugOrder(List<Drug> drugList, List<Concept> drugConceptList, Date startDateFrom, Date startDateTo, Date stopDateFrom, Date stopDateTo, Boolean discontinued, List<Concept> orderReason) { if (drugList != null && drugList.size() == 0) { drugList = null;/*from w w w . ja v a 2s . co m*/ } if (drugConceptList != null && drugConceptList.size() == 0) { drugConceptList = null; } StringBuilder sb = new StringBuilder(); sb.append(" select distinct patient.id from DrugOrder where voided = false and patient.voided = false "); if (drugList != null) { sb.append(" and drug.id in (:drugIdList) "); } if (drugConceptList != null) { sb.append(" and concept.id in (:drugConceptIdList) "); } if (startDateFrom != null && startDateTo != null) { sb.append(" and dateActivated between :startDateFrom and :startDateTo "); } else { if (startDateFrom != null) { sb.append(" and dateActivated >= :startDateFrom "); } if (startDateTo != null) { sb.append(" and dateActivated <= :startDateTo "); } } if (orderReason != null && orderReason.size() > 0) { sb.append(" and orderReason.id in (:orderReasonIdList) "); } if (discontinued != null) { if (discontinued) { if (stopDateFrom != null && stopDateTo != null) { sb.append(" and dateStopped between :stopDateFrom and :stopDateTo "); } else { if (stopDateFrom != null) { sb.append(" and dateStopped >= :stopDateFrom "); } if (stopDateTo != null) { sb.append(" and dateStopped <= :stopDateTo "); } } } else { // discontinued == false if (stopDateFrom != null && stopDateTo != null) { sb.append(" and autoExpireDate between :stopDateFrom and :stopDateTo "); } else { if (stopDateFrom != null) { sb.append(" and autoExpireDate >= :stopDateFrom "); } if (stopDateTo != null) { sb.append(" and autoExpireDate <= :stopDateTo "); } } } } else { // discontinued == null, so we need either if (stopDateFrom != null && stopDateTo != null) { sb.append(" and coalesce(dateStopped, autoExpireDate) between :stopDateFrom and :stopDateTo "); } else { if (stopDateFrom != null) { sb.append(" and coalesce(dateStopped, autoExpireDate) >= :stopDateFrom "); } if (stopDateTo != null) { sb.append(" and coalesce(dateStopped, autoExpireDate) <= :stopDateTo "); } } } log.debug("sql = " + sb); Query query = sessionFactory.getCurrentSession().createQuery(sb.toString()); if (drugList != null) { List<Integer> ids = new ArrayList<Integer>(); for (Drug d : drugList) { ids.add(d.getDrugId()); } query.setParameterList("drugIdList", ids); } if (drugConceptList != null) { List<Integer> ids = new ArrayList<Integer>(); for (Concept c : drugConceptList) { ids.add(c.getConceptId()); } query.setParameterList("drugConceptIdList", ids); } if (startDateFrom != null) { query.setDate("startDateFrom", startDateFrom); } if (startDateTo != null) { query.setDate("startDateTo", startDateTo); } if (stopDateFrom != null) { query.setDate("stopDateFrom", stopDateFrom); } if (stopDateTo != null) { query.setDate("stopDateTo", stopDateTo); } if (discontinued != null) { query.setBoolean("discontinued", discontinued); } if (orderReason != null && orderReason.size() > 0) { List<Integer> ids = new ArrayList<Integer>(); for (Concept c : orderReason) { ids.add(c.getConceptId()); } query.setParameterList("orderReasonIdList", ids); } return new Cohort(query.list()); }
From source file:org.openmrs.module.reportingcompatibility.service.db.HibernateReportingCompatibilityDAO.java
License:Open Source License
public Cohort getPatientsHavingDrugOrder(List<Drug> drugList, List<Concept> drugConceptList, Date startDateFrom, Date startDateTo, Date stopDateFrom, Date stopDateTo, Boolean discontinued, List<Concept> discontinuedReason) { if (drugList != null && drugList.size() == 0) drugList = null;//from w ww . java 2s. c om if (drugConceptList != null && drugConceptList.size() == 0) drugConceptList = null; StringBuilder sb = new StringBuilder(); sb.append(" select distinct patient.id from DrugOrder where voided = false and patient.voided = false "); if (drugList != null) sb.append(" and drug.id in (:drugIdList) "); if (drugConceptList != null) sb.append(" and concept.id in (:drugConceptIdList) "); if (startDateFrom != null && startDateTo != null) { sb.append(" and startDate between :startDateFrom and :startDateTo "); } else { if (startDateFrom != null) sb.append(" and startDate >= :startDateFrom "); if (startDateTo != null) sb.append(" and startDate <= :startDateTo "); } if (discontinuedReason != null && discontinuedReason.size() > 0) sb.append(" and discontinuedReason.id in (:discontinuedReasonIdList) "); if (discontinued != null) { sb.append(" and discontinued = :discontinued "); if (discontinued == true) { if (stopDateFrom != null && stopDateTo != null) { sb.append(" and discontinuedDate between :stopDateFrom and :stopDateTo "); } else { if (stopDateFrom != null) sb.append(" and discontinuedDate >= :stopDateFrom "); if (stopDateTo != null) sb.append(" and discontinuedDate <= :stopDateTo "); } } else { // discontinued == false if (stopDateFrom != null && stopDateTo != null) { sb.append(" and autoExpireDate between :stopDateFrom and :stopDateTo "); } else { if (stopDateFrom != null) sb.append(" and autoExpireDate >= :stopDateFrom "); if (stopDateTo != null) sb.append(" and autoExpireDate <= :stopDateTo "); } } } else { // discontinued == null, so we need either if (stopDateFrom != null && stopDateTo != null) { sb.append(" and coalesce(discontinuedDate, autoExpireDate) between :stopDateFrom and :stopDateTo "); } else { if (stopDateFrom != null) sb.append(" and coalesce(discontinuedDate, autoExpireDate) >= :stopDateFrom "); if (stopDateTo != null) sb.append(" and coalesce(discontinuedDate, autoExpireDate) <= :stopDateTo "); } } log.debug("sql = " + sb); Query query = sessionFactory.getCurrentSession().createQuery(sb.toString()); if (drugList != null) { List<Integer> ids = new ArrayList<Integer>(); for (Drug d : drugList) ids.add(d.getDrugId()); query.setParameterList("drugIdList", ids); } if (drugConceptList != null) { List<Integer> ids = new ArrayList<Integer>(); for (Concept c : drugConceptList) ids.add(c.getConceptId()); query.setParameterList("drugConceptIdList", ids); } if (startDateFrom != null) query.setDate("startDateFrom", startDateFrom); if (startDateTo != null) query.setDate("startDateTo", startDateTo); if (stopDateFrom != null) query.setDate("stopDateFrom", stopDateFrom); if (stopDateTo != null) query.setDate("stopDateTo", stopDateTo); if (discontinued != null) query.setBoolean("discontinued", discontinued); if (discontinuedReason != null && discontinuedReason.size() > 0) { List<Integer> ids = new ArrayList<Integer>(); for (Concept c : discontinuedReason) ids.add(c.getConceptId()); query.setParameterList("discontinuedReasonIdList", ids); } return new Cohort(query.list()); }