List of usage examples for org.hibernate Query iterate
Iterator<R> iterate();
From source file:PersonaDAO.java
public static java.util.Iterator iteratePersonaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From Persona as Persona"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/*from www .j a v a 2 s . co m*/ Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:PersonaDAO.java
public static java.util.Iterator iteratePersonaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From Persona as Persona"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/*ww w . ja v a 2s .c om*/ Query query = session.createQuery(sb.toString()); query.setLockMode("Persona", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:AdministrativoManoDeObra.java
public static java.util.Iterator iterateAdministrativoManoDeObraByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From AdministrativoManoDeObra as AdministrativoManoDeObra"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/* w w w. j a v a 2s .c o m*/ Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:AdministrativoManoDeObra.java
public static java.util.Iterator iterateAdministrativoManoDeObraByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From AdministrativoManoDeObra as AdministrativoManoDeObra"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {// w w w.j av a 2 s. co m Query query = session.createQuery(sb.toString()); query.setLockMode("AdministrativoManoDeObra", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:au.org.theark.core.dao.StudyDao.java
License:Open Source License
public boolean customFieldHasData(CustomField customField) { StringBuffer sb = new StringBuffer(); sb.append("SELECT count(*) FROM "); sb.append(" CustomField cf, "); sb.append(" CustomFieldDisplay cfd, "); sb.append(" PhenoData pd "); sb.append("WHERE cf.study.id = :studyId "); sb.append(" AND cf.arkFunction.id = :arkFunctionId "); sb.append(" AND cf.id = cfd.customField.id "); sb.append(" AND pd.customFieldDisplay.id = cfd.id"); Query query = getSession().createQuery(sb.toString()); query.setParameter("studyId", customField.getStudy().getId()); query.setParameter("arkFunctionId", customField.getArkFunction().getId()); return ((Number) query.iterate().next()).intValue() > 0; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
/** * /*from w ww.j av a 2 s . c om*/ */ public List<List<String>> getPhenoDataAsMatrix(Study study, List<String> subjectUids, List<PhenoDataSetField> phenoDataSetFields, List<PhenoDataSetGroup> phenoDataSetGroups, PhenoDataSetCategory phenoDataSetCategory) { List<List<String>> dataSet = new ArrayList<List<String>>(); StringBuffer dataHQLquery = new StringBuffer(); StringBuffer noDataHQLquery = new StringBuffer(); StringBuffer phenoFieldColumnSQL = new StringBuffer(); List<String> header = new ArrayList<String>(0); //stringBuffer.append("SELECT data.* FROM (\n"); //ARK-799 // dataHQLquery.append("SELECT lss.subjectUID, pc.recordDate, pc.description, \n"); dataHQLquery.append("SELECT lss.subjectUID, pdsc.recordDate, \n"); noDataHQLquery .append("SELECT lss.subjectUID, cast(null as char) AS recordDate, cast(null as char) AS name, \n"); header.add("SUBJECTUID"); header.add("RECORD_DATE"); //ARK-799 // header.add("COLLECTION"); // Loop for all custom goups for (PhenoDataSetGroup pdsg : phenoDataSetGroups) { // Get all custom fields for the group and create pivot SQL to create column //for(PhenoDataSetFieldDisplay pdsfd : getPhenoDataSetFieldDisplayForPhenoDataSetFieldGroup(pdsg)) { for (PhenoDataSetField pdsfd : getPhenoDataSetFieldsLinkedToPhenoDataSetFieldGroupAndPhenoDataSetCategory( pdsg, phenoDataSetCategory)) { //MAX(IF(custom_field_display_id = 14, pd.number_data_value, NULL)) AS cfd14, phenoFieldColumnSQL.append("(MAX(CASE WHEN pdsd.phenoDataSetFieldDisplay.id = "); phenoFieldColumnSQL .append(getPhenoDataSetFieldDisplayByPhenoDataSetFieldAndGroup(pdsfd, pdsg).getId()); // Determine field type and append SQL accordingly if (pdsfd.getFieldType().getName().equalsIgnoreCase(Constants.FIELD_TYPE_DATE)) { phenoFieldColumnSQL.append(" THEN pdsd.dateDataValue ELSE NULL END) "); } if (pdsfd.getFieldType().getName().equalsIgnoreCase(Constants.FIELD_TYPE_NUMBER)) { phenoFieldColumnSQL.append(" THEN pdsd.numberDataValue ELSE NULL END) "); } if (pdsfd.getFieldType().getName().equalsIgnoreCase(Constants.FIELD_TYPE_CHARACTER)) { phenoFieldColumnSQL.append(" THEN pdsd.textDataValue ELSE NULL END) "); } phenoFieldColumnSQL.append(") "); phenoFieldColumnSQL.append(","); noDataHQLquery.append("cast(null as char) "); noDataHQLquery.append(","); header.add(pdsfd.getName().toUpperCase()); } } // Remove erroneous ',' char from end of strings if (phenoFieldColumnSQL.length() > 0) { phenoFieldColumnSQL.setLength(phenoFieldColumnSQL.length() - 1); noDataHQLquery.setLength(noDataHQLquery.length() - 1); dataHQLquery.append(phenoFieldColumnSQL); dataHQLquery.append("\nFROM \n"); dataHQLquery.append(" PhenoDataSetData pdsd, "); dataHQLquery.append(" PhenoDataSetCollection pdsc, "); dataHQLquery.append(" LinkSubjectStudy lss, "); dataHQLquery.append(" PhenoDataSetFieldDisplay pdsfd \n"); dataHQLquery.append(" WHERE pdsd.phenoDataSetCollection.id = pdsc.id \n"); dataHQLquery.append(" AND pdsc.linkSubjectStudy.id = lss.id \n"); dataHQLquery.append(" AND lss.study = :study \n"); dataHQLquery.append(" AND lss.subjectUID IN (:subjectUids) \n"); dataHQLquery.append(" AND pdsfd.phenoDataSetGroup in (:phenoDataSetGroups) \n"); dataHQLquery.append(" AND pdsd.phenoDataSetFieldDisplay.id = pdsfd.id \n"); dataHQLquery.append("GROUP BY lss.subjectUID, pdsd.phenoDataSetCollection"); noDataHQLquery.append("\nFROM LinkSubjectStudy lss\n"); noDataHQLquery.append("WHERE lss.study = :study \n"); noDataHQLquery.append( "AND lss.id NOT IN (SELECT pdsc.linkSubjectStudy.id FROM PhenoDataSetCollection pdsc WHERE pdsc.questionnaire IN (:phenoDataSetGroups))\n"); String hqlQuery = dataHQLquery.toString(); Session session = getSession(); Query dataQuery = session.createQuery(hqlQuery); dataQuery.setParameter("study", study); dataQuery.setParameterList("subjectUids", subjectUids); dataQuery.setParameterList("phenoDataSetGroups", phenoDataSetGroups); // Add header as first list item dataSet.add(header); // Add data //ArrayList<List<String>> dataList = new ArrayList<List<String>>(); //dataList = (ArrayList<List<String>>) dataQuery.list(); //This result set contains a List of Object arrayseach array represents one set of properties Iterator it = dataQuery.iterate(); while (it.hasNext()) { Object[] val = (Object[]) it.next(); List<String> stringList = new ArrayList<String>(); for (Object o : val) { stringList.add(o != null ? o.toString() : new String()); } dataSet.add(stringList); } hqlQuery = noDataHQLquery.toString(); Query noDataQuery = session.createQuery(hqlQuery); noDataQuery.setParameter("study", study); noDataQuery.setParameterList("phenoDataSetGroups", phenoDataSetGroups); //noDataQuery.list(); //dataSet.addAll(noDataQuery.list()); } return dataSet; }
From source file:bbdd.Administrador_DAO.java
public static java.util.Iterator iterateAdministrador_ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From bbdd.Administrador_ as Administrador_"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/*ww w. j av a 2 s . com*/ Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:bbdd.Administrador_DAO.java
public static java.util.Iterator iterateAdministrador_ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From bbdd.Administrador_ as Administrador_"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/* www . jav a 2 s .co m*/ Query query = session.createQuery(sb.toString()); query.setLockMode("this", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:bbdd.ConfiguracionDAO.java
public static java.util.Iterator iterateConfiguracionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From bbdd.Configuracion as Configuracion"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/*w ww . ja va 2 s.c om*/ Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:bbdd.ConfiguracionDAO.java
public static java.util.Iterator iterateConfiguracionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From bbdd.Configuracion as Configuracion"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/*from www. ja v a2s.c om*/ Query query = session.createQuery(sb.toString()); query.setLockMode("this", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }