Example usage for org.hibernate CacheMode IGNORE

List of usage examples for org.hibernate CacheMode IGNORE

Introduction

In this page you can find the example usage for org.hibernate CacheMode IGNORE.

Prototype

CacheMode IGNORE

To view the source code for org.hibernate CacheMode IGNORE.

Click Source Link

Document

The session will never interact with the cache, except to invalidate cache items when updates occur.

Usage

From source file:org.life.sl.importers.ShapeFileImporter.java

License:Open Source License

public void dumpToPostgresql() {
    ArrayList<Node> nodes = psg.getNodes();
    Iterator<Node> iter = nodes.iterator();

    session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//w  w  w  .  j a  v  a  2  s.c o  m
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();

    // first, empty the database table:
    session.beginTransaction();
    session.setCacheMode(CacheMode.IGNORE);
    int nDel = session.createQuery("delete OSMNode").executeUpdate();
    session.flush();
    logger.info("Deleted " + nDel + " records from OSMNode");
    nDel = session.createQuery("delete OSMEdge").executeUpdate();
    session.flush();
    logger.info("Deleted " + nDel + " records from OSMEdge");

    logger.info("Writing nodes...");
    Integer batchSize = Integer.getInteger(new Configuration().getProperty("hibernate.jdbc.batch_size"), 50);
    logger.info("Database batch size: " + batchSize);

    Timer timer = new Timer();
    timer.init();

    int nNodes = 0; // will be used as node ID
    double nNodesMax = nodes.size();
    HashMap<Node, Integer> node__nodeId = new HashMap<Node, Integer>();
    while (iter.hasNext()) {
        Node n = iter.next();
        nNodes++;

        OSMNode osmNode = new OSMNode();
        osmNode.setGeometry(fact.createPoint(n.getCoordinate()));
        // @SuppressWarnings("unchecked")
        // HashMap<String, Integer> data = (HashMap<String, Integer>) n.getData();
        // int id = data.get("id");
        osmNode.setId(nNodes); //  todo set this properly

        node__nodeId.put(n, nNodes);
        session.save(osmNode);
        if (nNodes % batchSize == 0) {
            session.flush();
            session.clear();
        }
        timer.showProgress((double) nNodes / nNodesMax);
    }
    if (nNodes % batchSize == 0) {
        session.flush();
        session.clear();
    }
    System.out.println();

    Collection<Edge> edges = psg.getEdges();
    Iterator<Edge> iter2 = edges.iterator();

    logger.info("Writing edges...");
    int nEdges = 0; // will be used as edge ID
    double nEdgesMax = edges.size();

    while (iter2.hasNext()) {
        Edge e = iter2.next();
        nEdges++;

        OSMEdge osmEdge = new OSMEdge();
        @SuppressWarnings("unchecked")
        HashMap<String, Object> data2 = (HashMap<String, Object>) e.getData();
        Object geom = data2.get("geometry");

        /*Object bctyp_s = data2.get("BICYCLETYP");
        if (bctyp_s != null) {
           Integer bint = new Integer((Integer) bctyp_s);
           Short bicycle = bint.shortValue();
           osmEdge.setBicycletype(bicycle);
        }
                
        Object cycleway_s = data2.get("CYCLEWAYTY");
        if (cycleway_s != null) {
           Integer cwint = new Integer((Integer) cycleway_s);
           Short cycleway = cwint.shortValue();
           osmEdge.setCyclewaytype(cycleway);
        }
                
        Object foottype_s = data2.get("FOOTTYPE");
        if (foottype_s != null) {
           Integer fint = new Integer((Integer) foottype_s);
           Short foot = fint.shortValue();
           osmEdge.setFoottype(foot);
        }
                
        Object hwt_s = data2.get("HIGHWAYTYP");
        if (hwt_s != null) {
           Integer hwt = new Integer((Integer) hwt_s);
           Short highway = hwt.shortValue();
           osmEdge.setHighwaytype(highway);
        }
                
        Object sgrd_s = data2.get("SEGREGATED");
        if (sgrd_s != null) {
           Integer sgrd = new Integer((Integer) sgrd_s);
           Short segregated = sgrd.shortValue();
           osmEdge.setSegregatedtype(segregated);
        }
                
        Object roadname_o = data2.get("ROADNAME");
        if (roadname_o != null) {
           String roadname = (String) roadname_o;
           osmEdge.setRoadname(roadname);
        }*/

        // The HSP-specific stuff

        Integer envtp = new Integer((Integer) data2.get("EnvType"));
        Short envType = envtp.shortValue();

        Integer cyktp = new Integer((Integer) data2.get("CykType"));
        Short cykType = cyktp.shortValue();

        Double groenPct = new Double((Double) data2.get("GroenPct"));
        Double groenM = new Double((Double) data2.get("GroenM"));

        LineString ls = (LineString) geom;

        osmEdge.setGeometry(ls);
        osmEdge.setId(nEdges);
        osmEdge.setEnvtype(envType);
        osmEdge.setCyktype(cykType);
        osmEdge.setGroenpct(groenPct.floatValue());
        osmEdge.setGroenm(groenM.floatValue());

        Node from_node = e.getDirEdge(0).getFromNode();
        Node to_node = e.getDirEdge(0).getToNode();

        Integer from_node_id = node__nodeId.get(from_node);
        Integer to_node_id = node__nodeId.get(to_node);

        osmEdge.setFromnode(from_node_id);
        osmEdge.setTonode(to_node_id);
        osmEdge.setLength((float) ls.getLength());

        session.save(osmEdge);
        if (nEdges % batchSize == 0) {
            session.flush();
            session.clear();
        }
        timer.showProgress((double) nEdges / nEdgesMax);
    }
    if (nEdges % batchSize == 0) {
        session.flush();
        session.clear();
    }
    System.out.println();

    session.getTransaction().commit();
    logger.info("Imported " + nNodes + " nodes, " + nEdges + " edges");
    timer.getRunTime(true, "... import finished");
}

From source file:org.medici.bia.dao.JpaDao.java

License:Open Source License

/**
 * //www  .j  av  a2 s  .c o m
 * @throws PersistenceException
 */
public void generateIndex() throws PersistenceException {
    try {
        EntityManager entityManager = getEntityManager();
        Session session = ((HibernateEntityManager) entityManager).getSession();
        session = session.getSessionFactory().openSession();
        FullTextSession fullTextSession = Search.getFullTextSession(session);

        fullTextSession.createIndexer(entityClass).batchSizeToLoadObjects(30).threadsForSubsequentFetching(8)
                .threadsToLoadObjects(4).threadsForIndexWriter(3).cacheMode(CacheMode.IGNORE).startAndWait();
    } catch (Throwable throwable) {
        logger.error(throwable);
    }
}

From source file:org.mifos.application.master.persistence.Upgrade1286195484.java

License:Open Source License

@Override
public void upgrade(Connection connection) throws IOException, SQLException {
    conditionalAlter(connection);//from  www  .j av a2 s  .  c om

    Session session = StaticHibernateUtil.getSessionTL();
    ScrollableResults results = session.createQuery("from CustomerAddressDetailEntity")
            .setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);
    Query update = session.createQuery(
            "update CustomerAddressDetailEntity set address.phoneNumberStripped = :phoneNumberStripped where "
                    + "customerAddressId = :id");
    Transaction t = session.beginTransaction();
    int modifyCount = 0;
    int resultCount = 0;
    while (results.next()) {
        ++resultCount;
        CustomerAddressDetailEntity address = (CustomerAddressDetailEntity) results.get(0);
        if (address.getAddress().getPhoneNumber() != null && !address.getAddress().getPhoneNumber().isEmpty()) {
            update.setString("phoneNumberStripped", address.getAddress().getPhoneNumberStripped());
            update.setInteger("id", address.getCustomerAddressId());
            update.executeUpdate();
            ++modifyCount;
            if (modifyCount % COMMIT_EVERY == 0) {
                t.commit();
                t = session.beginTransaction();
            }
        }
        if (resultCount % FLUSH_EVERY == 0) {
            session.flush();
            session.clear();
        }
        if (resultCount % PRINT_EVERY == 0) {
            System.out.print(".");
            System.out.flush();
        }
    }
    session.flush();
    t.commit();
}

From source file:org.openhie.openempi.blocking.basicblockinghp.dao.hibernate.BlockingDaoHibernate.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
public Record loadRecord(final long recordId, final List<String> fieldNameSet) {
    final String[] fieldNames = fieldNameSet.toArray(new String[] {});
    return (Record) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            try {
                org.hibernate.Criteria criteria = createQueryFromFields(session, fieldNameSet);
                criteria.add(Restrictions.eq("personId", new Integer((int) recordId)));
                criteria.setCacheMode(CacheMode.IGNORE);
                criteria.setFetchSize(10000);
                ScrollableResults iterator = criteria.scroll(ScrollMode.FORWARD_ONLY);
                int count = 0;
                Record record = null;/*from  w  w  w.  ja  v  a  2s . co  m*/
                while (iterator.next()) {
                    Object[] values = iterator.get();
                    Person person = populatePersonObject(fieldNames, values);
                    Long recordId = person.getPersonId().longValue();
                    record = new Record(person);
                    record.setRecordId(recordId);
                    log.trace("Loaded " + count + " records with id " + recordId + " into the cache.");
                    count++;
                }
                return record;
            } catch (Exception e) {
                log.error("Failed while scrolling through the records: " + e, e);
                throw new RuntimeException("Failed while scrolling through the records: " + e.getMessage());
            }
        }
    });
}

From source file:org.openhie.openempi.blocking.basicblockinghp.dao.hibernate.BlockingDaoHibernate.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
public void loadAllRecords(final Cache recordCache, final List<String> fieldNameSet) {
    final String[] fieldNames = fieldNameSet.toArray(new String[] {});
    //      final String queryStr = buildQuery(fieldNames).toString();
    getHibernateTemplate().execute(new HibernateCallback() {
        @Override// w w  w. j a v  a  2 s .  c om
        public Object doInHibernate(Session session) {
            try {
                org.hibernate.Criteria criteria = createQueryFromFields(session, fieldNameSet);
                criteria.setCacheMode(CacheMode.IGNORE);
                criteria.setFetchSize(10000);
                ScrollableResults iterator = criteria.scroll(ScrollMode.FORWARD_ONLY);
                //               Query query = session.createQuery(queryStr);
                //               query.setCacheMode(CacheMode.IGNORE);
                //               query.setFetchSize(10000);
                //               ScrollableResults iterator = query.scroll(ScrollMode.FORWARD_ONLY);
                int count = 0;
                while (iterator.next()) {
                    Object[] values = iterator.get();
                    Person person = populatePersonObject(fieldNames, values);
                    Record record = new Record(person);
                    Long recordId = person.getPersonId().longValue();
                    record.setRecordId(recordId);
                    Element element = new Element(recordId, record);
                    recordCache.put(element);
                    log.trace("Loaded record " + recordId + " into the cache.");
                    count++;
                }
                log.debug("Loaded " + count + " records into the cache.");
            } catch (Exception e) {
                log.error("Failed while scrolling through the records: " + e, e);
            }
            return null;
        }
    });
}

From source file:org.openmrs.api.db.hibernate.HibernateContextDAO.java

License:Mozilla Public License

@Override
public void updateSearchIndexForType(Class<?> type) {
    //From http://docs.jboss.org/hibernate/search/3.3/reference/en-US/html/manual-index-changes.html#search-batchindex-flushtoindexes
    FullTextSession session = Search.getFullTextSession(sessionFactory.getCurrentSession());
    session.purgeAll(type);/*ww  w.ja  va2  s  .  c  o m*/

    //Prepare session for batch work
    session.flush();
    session.clear();

    FlushMode flushMode = session.getFlushMode();
    CacheMode cacheMode = session.getCacheMode();
    try {
        session.setFlushMode(FlushMode.MANUAL);
        session.setCacheMode(CacheMode.IGNORE);

        //Scrollable results will avoid loading too many objects in memory
        ScrollableResults results = session.createCriteria(type).setFetchSize(1000)
                .scroll(ScrollMode.FORWARD_ONLY);
        int index = 0;
        while (results.next()) {
            index++;
            session.index(results.get(0)); //index each element
            if (index % 1000 == 0) {
                session.flushToIndexes(); //apply changes to indexes
                session.clear(); //free memory since the queue is processed
            }
        }
        session.flushToIndexes();
        session.clear();
    } finally {
        session.setFlushMode(flushMode);
        session.setCacheMode(cacheMode);
    }
}

From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java

License:Mozilla Public License

/**
 * a given program. If fromDate != null, then only those patients who were in the program at any
 * time after that date if toDate != null, then only those patients who were in the program at
 * any time before that date/*from www. j a  v a2s .  c om*/
 */
public Cohort getPatientsInProgram(Integer programId, Date fromDate, Date toDate) {
    String sql = "select pp.patient_id from patient_program pp ";
    sql += " inner join patient p on pp.patient_id = p.patient_id and p.voided = false ";
    sql += " where pp.voided = false and pp.program_id = :programId ";
    if (fromDate != null) {
        sql += " and (date_completed is null or date_completed >= :fromDate) ";
    }
    if (toDate != null) {
        sql += " and (date_enrolled is null or date_enrolled <= :toDate) ";
    }
    log.debug("sql: " + sql);

    Query query = sessionFactory.getCurrentSession().createSQLQuery(sql);
    query.setCacheMode(CacheMode.IGNORE);

    query.setInteger("programId", programId);
    if (fromDate != null) {
        query.setDate("fromDate", fromDate);
    }
    if (toDate != null) {
        query.setDate("toDate", toDate);
    }

    return new Cohort(query.list());
}

From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java

License:Mozilla Public License

public Cohort getPatientsHavingObs(Integer conceptId, PatientSetService.TimeModifier timeModifier,
        PatientSetService.Modifier modifier, Object value, Date fromDate, Date toDate) {
    if (conceptId == null && value == null) {
        throw new IllegalArgumentException("Can't have conceptId == null and value == null");
    }/*from  w  w  w .  j  a v a2s  .co m*/
    if (conceptId == null && (timeModifier != TimeModifier.ANY && timeModifier != TimeModifier.NO)) {
        throw new IllegalArgumentException("If conceptId == null, timeModifier must be ANY or NO");
    }
    if (conceptId == null && modifier != Modifier.EQUAL) {
        throw new IllegalArgumentException("If conceptId == null, modifier must be EQUAL");
    }
    Concept concept = null;
    if (conceptId != null) {
        concept = Context.getConceptService().getConcept(conceptId);
    }
    Number numericValue = null;
    String stringValue = null;
    Concept codedValue = null;
    Date dateValue = null;
    String valueSql = null;
    if (value != null) {
        if (concept == null) {
            if (value instanceof Concept) {
                codedValue = (Concept) value;
            } else {
                codedValue = Context.getConceptService().getConceptByName(value.toString());
            }
            valueSql = "o.value_coded";
        } else if (concept.getDatatype().isNumeric()) {
            if (value instanceof Number) {
                numericValue = (Number) value;
            } else {
                numericValue = new Double(value.toString());
            }
            valueSql = "o.value_numeric";
        } else if (concept.getDatatype().isText()) {
            stringValue = value.toString();
            valueSql = "o.value_text";
            if (modifier == null) {
                modifier = Modifier.EQUAL;
            }
        } else if (concept.getDatatype().isCoded()) {
            if (value instanceof Concept) {
                codedValue = (Concept) value;
            } else {
                codedValue = Context.getConceptService().getConceptByName(value.toString());
            }
            valueSql = "o.value_coded";
        } else if (concept.getDatatype().isDate()) {
            if (value instanceof Date) {
                dateValue = (Date) value;
            } else {
                try {
                    dateValue = Context.getDateFormat().parse(value.toString());
                } catch (ParseException ex) {
                    throw new IllegalArgumentException("Cannot interpret " + dateValue
                            + " as a date in the format " + Context.getDateFormat());
                }
            }
            valueSql = "o.value_datetime";
        } else if (concept.getDatatype().isBoolean()) {
            if (value instanceof Concept) {
                codedValue = (Concept) value;
            } else {
                boolean asBoolean = false;
                if (value instanceof Boolean) {
                    asBoolean = ((Boolean) value).booleanValue();
                } else {
                    asBoolean = Boolean.valueOf(value.toString());
                }
                codedValue = asBoolean ? Context.getConceptService().getTrueConcept()
                        : Context.getConceptService().getFalseConcept();
            }
            valueSql = "o.value_coded";
        }
    }

    StringBuilder sb = new StringBuilder();
    boolean useValue = value != null;
    boolean doSqlAggregation = timeModifier == TimeModifier.MIN || timeModifier == TimeModifier.MAX
            || timeModifier == TimeModifier.AVG;
    boolean doInvert = false;

    String dateSql = "";
    String dateSqlForSubquery = "";
    if (fromDate != null) {
        dateSql += " and o.obs_datetime >= :fromDate ";
        dateSqlForSubquery += " and obs_datetime >= :fromDate ";
    }
    if (toDate != null) {
        dateSql += " and o.obs_datetime <= :toDate ";
        dateSqlForSubquery += " and obs_datetime <= :toDate ";
    }

    if (timeModifier == TimeModifier.ANY || timeModifier == TimeModifier.NO) {
        if (timeModifier == TimeModifier.NO) {
            doInvert = true;
        }
        sb.append("select o.person_id from obs o "
                + "inner join patient p on o.person_id = p.patient_id and p.voided = false "
                + "where o.voided = false ");
        if (conceptId != null) {
            sb.append("and concept_id = :concept_id ");
        }
        sb.append(dateSql);

    } else if (timeModifier == TimeModifier.FIRST || timeModifier == TimeModifier.LAST) {
        boolean isFirst = timeModifier == PatientSetService.TimeModifier.FIRST;
        sb.append("select o.person_id " + "from obs o inner join (" + "    select person_id, "
                + (isFirst ? "min" : "max") + "(obs_datetime) as obs_datetime" + "    from obs"
                + "    where voided = false and concept_id = :concept_id " + dateSqlForSubquery
                + "    group by person_id"
                + ") subq on o.person_id = subq.person_id and o.obs_datetime = subq.obs_datetime "
                + " inner join patient p on o.person_id = p.patient_id and p.voided = false "
                + "where o.voided = false and o.concept_id = :concept_id ");

    } else if (doSqlAggregation) {
        String sqlAggregator = timeModifier.toString();
        valueSql = sqlAggregator + "(" + valueSql + ")";
        sb.append("select o.person_id " + "from obs o "
                + "inner join patient p on o.person_id = p.patient_id and p.voided = false "
                + "where o.voided = false and concept_id = :concept_id " + dateSql + "group by o.person_id ");

    } else {
        throw new IllegalArgumentException("TimeModifier '" + timeModifier + "' not recognized");
    }

    if (useValue) {
        sb.append(doSqlAggregation ? " having " : " and ");
        sb.append(valueSql + " ");
        sb.append(modifier.getSqlRepresentation() + " :value");
    }
    if (!doSqlAggregation) {
        sb.append(" group by o.person_id ");
    }

    log.debug("query: " + sb);
    Query query = sessionFactory.getCurrentSession().createSQLQuery(sb.toString());
    query.setCacheMode(CacheMode.IGNORE);

    if (conceptId != null) {
        query.setInteger("concept_id", conceptId);
    }
    if (useValue) {
        if (numericValue != null) {
            query.setDouble("value", numericValue.doubleValue());
        } else if (codedValue != null) {
            query.setInteger("value", codedValue.getConceptId());
        } else if (stringValue != null) {
            query.setString("value", stringValue);
        } else if (dateValue != null) {
            query.setDate("value", dateValue);
        } else {
            throw new IllegalArgumentException(
                    "useValue is true, but numeric, coded, string, boolean, and date values are all null");
        }
    }
    if (fromDate != null) {
        query.setDate("fromDate", fromDate);
    }
    if (toDate != null) {
        query.setDate("toDate", toDate);
    }

    Cohort ret;
    if (doInvert) {
        ret = getAllPatients();
        ret.getMemberIds().removeAll(query.list());
    } else {
        ret = new Cohort(query.list());
    }

    return ret;
}

From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java

License:Mozilla Public License

/**
 * within <code>startTime</code> and <code>endTime</code>
 * //  ww w  .j a  va  2  s . c om
 * @param conceptId
 * @param startTime
 * @param endTime
 * @return PatientSet
 */
public Cohort getPatientsHavingDateObs(Integer conceptId, Date startTime, Date endTime) {
    StringBuffer sb = new StringBuffer();
    sb.append("select o.person_id from obs o " + "where concept_id = :concept_id ");
    sb.append(" and o.value_datetime between :startValue and :endValue");
    sb.append(" and o.voided = '0'");

    Query query = sessionFactory.getCurrentSession().createSQLQuery(sb.toString());
    query.setCacheMode(CacheMode.IGNORE);

    query.setInteger("concept_id", conceptId);
    query.setDate("startValue", startTime);
    query.setDate("endValue", endTime);

    return new Cohort(query.list());
}

From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java

License:Mozilla Public License

public Cohort getPatientsHavingNumericObs(Integer conceptId, PatientSetService.TimeModifier timeModifier,
        PatientSetService.Modifier modifier, Number value, Date fromDate, Date toDate) {

    Concept concept = Context.getConceptService().getConcept(conceptId);
    if (!concept.isNumeric()) {
        // throw new IllegalArgumentException(concept + " is not numeric");
    }/*  w  w w  .  j  a  v a 2  s  . c om*/

    StringBuffer sb = new StringBuffer();
    boolean useValue = modifier != null && value != null;
    boolean doSqlAggregation = timeModifier == TimeModifier.MIN || timeModifier == TimeModifier.MAX
            || timeModifier == TimeModifier.AVG;
    String valueSql = "o.value_numeric";
    boolean doInvert = false;

    String dateSql = "";
    if (fromDate != null) {
        dateSql += " and o.obs_datetime >= :fromDate ";
    }
    if (toDate != null) {
        dateSql += " and o.obs_datetime <= :toDate ";
    }

    if (timeModifier == TimeModifier.ANY || timeModifier == TimeModifier.NO) {
        if (timeModifier == TimeModifier.NO) {
            doInvert = true;
        }
        sb.append("select o.person_id from obs o " + "where voided = false and concept_id = :concept_id ");
        sb.append(dateSql);
    } else if (timeModifier == TimeModifier.FIRST || timeModifier == TimeModifier.LAST) {
        boolean isFirst = timeModifier == PatientSetService.TimeModifier.FIRST;
        sb.append("select o.person_id " + "from obs o inner join (" + "    select person_id, "
                + (isFirst ? "min" : "max") + "(obs_datetime) as obs_datetime" + "    from obs"
                + "    where voided = false and concept_id = :concept_id " + dateSql + "    group by person_id"
                + ") subq on o.person_id = subq.person_id and o.obs_datetime = subq.obs_datetime "
                + "where o.voided = false and o.concept_id = :concept_id ");
    } else if (doSqlAggregation) {
        String sqlAggregator = timeModifier.toString();
        valueSql = sqlAggregator + "(o.value_numeric)";
        sb.append("select o.person_id " + "from obs o where o.voided = false and concept_id = :concept_id "
                + dateSql + "group by o.person_id ");
    } else {
        throw new IllegalArgumentException("TimeModifier '" + timeModifier + "' not recognized");
    }

    if (useValue) {
        sb.append(doSqlAggregation ? "having " : " and ");
        sb.append(valueSql + " ");
        sb.append(modifier.getSqlRepresentation() + " :value");
    }
    if (!doSqlAggregation) {
        sb.append(" group by o.person_id ");
    }

    log.debug("query: " + sb);
    Query query = sessionFactory.getCurrentSession().createSQLQuery(sb.toString());
    query.setCacheMode(CacheMode.IGNORE);

    query.setInteger("concept_id", conceptId);
    if (useValue) {
        query.setDouble("value", value.doubleValue());
    }
    if (fromDate != null) {
        query.setDate("fromDate", fromDate);
    }
    if (toDate != null) {
        query.setDate("toDate", fromDate);
    }

    Cohort ret;
    if (doInvert) {
        ret = getAllPatients();
        ret.getMemberIds().removeAll(query.list());
    } else {
        ret = new Cohort(query.list());
    }

    return ret;
}