List of usage examples for org.hibernate ScrollableResults close
void close();
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param genes genes//from www . j av a 2s .c om * @param session session * @return map of probes to input genes they map to. Other genes those probes might detect are not included. */ public static Map<CompositeSequence, Collection<Gene>> getCs2GeneMap(Collection<Gene> genes, Session session) { StopWatch timer = new StopWatch(); timer.start(); final String csQueryString = "select distinct cs, gene from Gene as gene" + " inner join gene.products gp, BioSequence2GeneProduct ba, CompositeSequence cs " + " where ba.bioSequence=cs.biologicalCharacteristic and ba.geneProduct = gp" + " and gene in (:genes) "; Map<CompositeSequence, Collection<Gene>> cs2gene = new HashMap<>(); org.hibernate.Query queryObject = session.createQuery(csQueryString); queryObject.setCacheable(true); queryObject.setParameterList("genes", genes); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); CommonQueries.addGenes(cs2gene, results); results.close(); if (timer.getTime() > 200) { CommonQueries.log.info("Get cs2gene for " + genes.size() + " :" + timer.getTime() + "ms"); } return cs2gene; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param session session//from w w w.jav a 2s . co m * @param probes probes * @return map of probes to all the genes 'detected' by those probes. Probes that don't map to genes will have an * empty gene collection. */ public static Map<Long, Collection<Long>> getCs2GeneMapForProbes(Collection<Long> probes, Session session) { if (probes.isEmpty()) return new HashMap<>(); Map<Long, Collection<Long>> cs2genes = new HashMap<>(); String queryString = "SELECT CS AS csid, GENE AS geneId FROM GENE2CS g WHERE g.CS IN (:probes) "; org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.addScalar("csid", LongType.INSTANCE); queryObject.addScalar("geneId", LongType.INSTANCE); queryObject.setParameterList("probes", probes, LongType.INSTANCE); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); CommonQueries.addGeneIds(cs2genes, results); results.close(); return cs2genes; }
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
public static Collection<Long> filterProbesByPlatform(Collection<Long> probes, Collection<Long> arrayDesignIds, Session session) {// w w w . j a va2s .c o m assert probes != null && !probes.isEmpty(); assert arrayDesignIds != null && !arrayDesignIds.isEmpty(); String queryString = "SELECT CS AS csid FROM GENE2CS WHERE AD IN (:adids) AND CS IN (:probes)"; org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.addScalar("csid", LongType.INSTANCE); queryObject.setParameterList("probes", probes, LongType.INSTANCE); queryObject.setParameterList("adids", arrayDesignIds, LongType.INSTANCE); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); List<Long> r = new ArrayList<>(); while (results.next()) { r.add(results.getLong(0)); } results.close(); return r; }
From source file:vn.vnpttech.ssdc.nms.dao.hibernate.DeviceDaoHibernate.java
License:Apache License
@Override public Map searchDevice(String deviceMAC, String deviceSerialNumber, String deviceStatus, String deviceFirmwareStatus, String deviceModel, String deviceFirmware, String deviceProvince, String deviceDistrict, List<Area> listArea, String ipAddress, String username, Long start, Long limit) { try {//from w w w . ja v a 2 s.com int total = 0; Map pagingMap = new HashMap(); List<Device> listDevice = new ArrayList<Device>(); Criteria criteria = getSession().createCriteria(Device.class); //MAC if (StringUtils.isNotBlank(deviceMAC)) { criteria.add(Restrictions.like("mac", deviceMAC.trim(), MatchMode.ANYWHERE).ignoreCase()); } //Serial Number if (StringUtils.isNotBlank(deviceSerialNumber)) { criteria.add(Restrictions.like("serialNumber", "%" + deviceSerialNumber.trim() + "%").ignoreCase()); } //Device status if (StringUtils.isNotBlank(deviceStatus)) { criteria.add(Restrictions.eq("cpeStatus", Integer.parseInt(deviceStatus.trim()))); } //Firmware Status if (StringUtils.isNotBlank(deviceFirmwareStatus)) { criteria.add(Restrictions.eq("firmwareStatus", Integer.parseInt(deviceFirmwareStatus.trim()))); } //Model if (StringUtils.isNotBlank(deviceModel)) { criteria.add(Restrictions.eq("deviceModel.id", Long.parseLong(deviceModel.trim()))); } //Firmware if (StringUtils.isNotBlank(deviceFirmware)) { criteria.add(Restrictions.eq("firmwareVersion", deviceFirmware.trim()).ignoreCase()); } //IP if (StringUtils.isNotBlank(ipAddress)) { criteria.add(Restrictions.like("ipAddress", ipAddress.trim(), MatchMode.ANYWHERE).ignoreCase()); } // username if (StringUtils.isNotBlank(username)) { criteria.add(Restrictions.like("stbUsername", username.trim(), MatchMode.ANYWHERE).ignoreCase()); } //Province if (!listArea.isEmpty()) { criteria.add(Restrictions.in("area", listArea)); } // if (StringUtils.isNotBlank(deviceProvince)) { // //District // if (StringUtils.isBlank(deviceDistrict)) { //province level // criteria.createCriteria("area").add(Restrictions.eq("area.id", Long.parseLong(deviceProvince.trim()))); // } else {//district level // criteria.add(Restrictions.eq("area.id", Long.parseLong(deviceDistrict.trim()))); // } // } criteria.addOrder(Order.desc("id")); //Paging if (limit != null && limit > 0) { // get the count ScrollableResults results = criteria.scroll(); results.last(); total = results.getRowNumber() + 1; results.close(); //End get count criteria.setFirstResult(start.intValue()); criteria.setMaxResults(limit.intValue()); } listDevice = criteria.list(); pagingMap.put("list", listDevice); pagingMap.put("totalCount", Long.parseLong(String.valueOf(total))); return pagingMap; } catch (Exception ex) { log.error("ERROR searchDevice: ", ex); return null; } }
From source file:vn.vnpttech.ssdc.nms.dao.hibernate.PolicyDaoHibernate.java
License:Apache License
@Override public Map searchPolicy(String policyName, String policyStatus, String enable, String startTime, String endTime, Long start, Long limit) { try {/* w w w.ja v a 2s . c om*/ int total = 0; Map pagingMap = new HashMap(); List<Policy> listPolicy = new ArrayList<Policy>(); Criteria criteria = getSession().createCriteria(Policy.class); //Name if (StringUtils.isNotBlank(policyName)) { criteria.add(Restrictions.like("name", "%" + policyName.trim() + "%").ignoreCase()); } //Status if (StringUtils.isNotBlank(policyStatus)) { criteria.add(Restrictions.eq("policyStatus", Integer.parseInt(policyStatus.trim()))); } //Enable if (StringUtils.isNotBlank(enable)) { criteria.add(Restrictions.eq("enable", Integer.parseInt(enable.trim()))); } //Start Time & End Time if (StringUtils.isNotBlank(startTime)) { Date startTimeInDate = sdf.parse(startTime); criteria.add(Restrictions.ge("startTime", startTimeInDate)); } if (StringUtils.isNotBlank(endTime)) { Date endTimeInDate = sdf.parse(endTime); criteria.add(Restrictions.le("endTime", endTimeInDate)); } criteria.addOrder(Order.desc("id")); //Paging if (limit != null && limit > 0) { // get the count ScrollableResults results = criteria.scroll(); results.last(); total = results.getRowNumber() + 1; results.close(); //End get count criteria.setFirstResult(start.intValue()); criteria.setMaxResults(limit.intValue()); } listPolicy = criteria.list(); pagingMap.put("list", listPolicy); pagingMap.put("totalCount", Long.parseLong(String.valueOf(total))); return pagingMap; } catch (Exception ex) { log.error("ERROR searchPolicy: ", ex); return null; } }
From source file:vn.vnpttech.ssdc.nms.dao.hibernate.PolicyHistoryDaoHibernate.java
License:Apache License
@Override public Map searchPolicyHistory(String policyId, String deviceId, Long start, Long limit) { try {/*w w w .j av a 2s . com*/ int total = 0; Map pagingMap = new HashMap(); List<PolicyHistory> listPolicyHistory = new ArrayList<>(); Criteria criteria = getSession().createCriteria(PolicyHistory.class); //Policy if (StringUtils.isNotBlank(policyId)) { criteria.add(Restrictions.eq("policy.id", Long.parseLong(policyId.trim()))); } //Device if (StringUtils.isNotBlank(deviceId)) { criteria.add(Restrictions.eq("device.id", Long.parseLong(deviceId.trim()))); } criteria.addOrder(Order.desc("id")); //Paging if (limit != null && limit > 0) { // get the count ScrollableResults results = criteria.scroll(); results.last(); total = results.getRowNumber() + 1; results.close(); //End get count criteria.setFirstResult(start.intValue()); criteria.setMaxResults(limit.intValue()); } listPolicyHistory = criteria.list(); pagingMap.put("list", listPolicyHistory); pagingMap.put("totalCount", Long.parseLong(String.valueOf(total))); return pagingMap; } catch (Exception ex) { log.error("ERROR searchPolicyHistory: ", ex); return null; } }