List of usage examples for org.hibernate SQLQuery setLong
@Deprecated @SuppressWarnings("unchecked") default Query<R> setLong(int position, long val)
From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java
License:Open Source License
public List<Long> getQuotaIdforAccountQuotaInSubDomains(AbstractDomain domain, QuotaType type, ContainerQuotaType containerType) { HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() { public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException { StringBuilder sb = new StringBuilder(); sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father"); sb.append(" JOIN quota AS child"); sb.append(" ON child.domain_parent_id = father.domain_id"); sb.append(" AND child.quota_type = :domainType "); sb.append(" AND father.domain_parent_id = :domainId "); sb.append(" AND father.default_account_quota_override = false"); if (containerType != null) { sb.append(" AND father.container_type = :containerType"); }//from w w w . j a v a2 s . c o m sb.append(" WHERE father.quota_type = :domainType"); if (containerType != null) { sb.append(" AND child.container_type = :containerType"); } sb.append(" AND child.account_quota_override = false"); sb.append(";"); final SQLQuery query = session.createSQLQuery(sb.toString()); query.setLong("domainId", domain.getPersistenceId()); query.addScalar("child_id", LongType.INSTANCE); query.setString("domainType", type.name()); if (containerType != null) { query.setString("containerType", containerType.name()); } @SuppressWarnings("unchecked") List<Long> res = query.list(); logger.debug("child_ids :" + res); return res; } }; return getHibernateTemplate().execute(action); }
From source file:org.linagora.linshare.core.repository.hibernate.GenericQuotaRepositoryImpl.java
License:Open Source License
public List<Long> getQuotaIdforDefaultQuotaInSubDomains(AbstractDomain domain, Long quota, QuotaType type, ContainerQuotaType containerType) { HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() { public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException { StringBuilder sb = new StringBuilder(); sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father"); sb.append(" JOIN quota AS child"); sb.append(" ON child.domain_parent_id = father.domain_id"); sb.append(" AND child.quota_type = :domainType "); sb.append(" AND father.domain_parent_id = :domainId "); sb.append(" AND father.default_quota_override = false"); sb.append(" WHERE father.quota_type = :domainType"); if (containerType != null) { sb.append(" AND child.container_type = :containerType"); }/*ww w . j a v a 2s . co m*/ sb.append(" AND child.default_quota_override = false"); sb.append(";"); final SQLQuery query = session.createSQLQuery(sb.toString()); query.setLong("domainId", domain.getPersistenceId()); query.addScalar("child_id", LongType.INSTANCE); query.setString("domainType", type.name()); if (containerType != null) { query.setString("containerType", containerType.name()); } @SuppressWarnings("unchecked") List<Long> res = query.list(); logger.debug("child_ids :" + res); return res; } }; return getHibernateTemplate().execute(action); }
From source file:org.linagora.linshare.core.repository.hibernate.GenericQuotaRepositoryImpl.java
License:Open Source License
public List<Long> getQuotaIdforQuotaInSubDomains(AbstractDomain domain, Long quota, QuotaType type, ContainerQuotaType containerType) { HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() { public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException { StringBuilder sb = new StringBuilder(); sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father"); sb.append(" JOIN quota AS child"); sb.append(" ON child.domain_parent_id = father.domain_id"); sb.append(" AND child.quota_type = :domainType "); sb.append(" AND father.domain_parent_id = :domainId "); sb.append(" AND father.quota_override = false"); if (containerType != null) { sb.append(" AND father.container_type = :containerType"); }// w ww.j a v a 2 s.com sb.append(" WHERE father.quota_type = :domainType"); if (containerType != null) { sb.append(" AND child.container_type = :containerType"); } sb.append(" AND child.quota_override = false"); sb.append(";"); final SQLQuery query = session.createSQLQuery(sb.toString()); query.setLong("domainId", domain.getPersistenceId()); query.addScalar("child_id", LongType.INSTANCE); query.setString("domainType", type.name()); if (containerType != null) { query.setString("containerType", containerType.name()); } @SuppressWarnings("unchecked") List<Long> res = query.list(); logger.debug("child_ids :" + res); return res; } }; return getHibernateTemplate().execute(action); }
From source file:org.mousephenotype.dcc.utils.persistence.HibernateManager.java
License:Apache License
public <T> List<T> nativeQuery(String query, Class<T> clazz, com.google.common.collect.Table<String, Class, Object> parameters) { this.refreshSession(); Transaction transaction = null;/*from w ww . jav a 2 s . c om*/ List<T> result = null; try { transaction = session.beginTransaction(); SQLQuery sqlQuery = session.createSQLQuery(query).addEntity(clazz); if (parameters != null) { for (com.google.common.collect.Table.Cell<String, Class, Object> entry : parameters.cellSet()) { if (entry.getColumnKey().equals(String.class)) { sqlQuery.setString(entry.getRowKey(), (String) entry.getValue()); continue; } if (entry.getColumnKey().equals(Long.class)) { sqlQuery.setLong(entry.getRowKey(), (Long) entry.getValue()); continue; } if (entry.getColumnKey().equals(BigInteger.class)) { sqlQuery.setBigInteger(entry.getRowKey(), (BigInteger) entry.getValue()); continue; } logger.error("Type {} not registered", entry.getValue().getClass()); } } result = sqlQuery.list(); transaction.commit(); } catch (RuntimeException ex) { if (transaction != null) { logger.error("rolling back transaction {}", ex); transaction.rollback(); } } return result; }
From source file:org.mousephenotype.dcc.utils.persistence.HibernateManager.java
License:Apache License
public List nativeQuery(String query, Map<String, org.hibernate.type.Type> scalars, com.google.common.collect.Table<String, Class, Object> parameters) { this.refreshSession(); Transaction transaction = null;//from w ww. j a va 2 s . c o m List result = null; try { transaction = session.beginTransaction(); SQLQuery sqlQuery = session.createSQLQuery(query); if (scalars != null) { for (Map.Entry<String, org.hibernate.type.Type> entry : scalars.entrySet()) { sqlQuery.addScalar(entry.getKey(), entry.getValue()); } } if (parameters != null) { for (com.google.common.collect.Table.Cell<String, Class, Object> entry : parameters.cellSet()) { if (entry.getColumnKey().equals(String.class)) { sqlQuery.setString(entry.getRowKey(), (String) entry.getValue()); continue; } if (entry.getColumnKey().equals(Long.class)) { sqlQuery.setLong(entry.getRowKey(), (Long) entry.getValue()); continue; } if (entry.getColumnKey().equals(BigInteger.class)) { sqlQuery.setBigInteger(entry.getRowKey(), (BigInteger) entry.getValue()); continue; } logger.error("Type {} not registered", entry.getValue().getClass()); } } result = sqlQuery.list(); transaction.commit(); } catch (RuntimeException ex) { if (transaction != null) { logger.error("rolling back transaction {}", ex); transaction.rollback(); } } return result; }
From source file:ubic.gemma.persistence.service.analysis.expression.diff.DifferentialExpressionResultDaoImpl.java
License:Apache License
@Override public List<Double> findGeneInResultSets(Gene gene, ExpressionAnalysisResultSet resultSet, Collection<Long> arrayDesignIds, Integer limit) { StopWatch timer = new StopWatch(); timer.start();/*from w ww . j a v a 2s . c o m*/ List<Double> results; Session session = this.getSessionFactory().getCurrentSession(); org.hibernate.SQLQuery queryObject = session .createSQLQuery(DifferentialExpressionResultDaoImpl.fetchResultsByResultSetAndGeneQuery); queryObject.setLong("gene_id", gene.getId()); queryObject.setLong("rs_id", resultSet.getId()); if (limit != null) { queryObject.setMaxResults(limit); } queryObject.addScalar("CORRECTED_PVALUE", new DoubleType()); //noinspection unchecked results = queryObject.list(); timer.stop(); if (AbstractDao.log.isDebugEnabled()) AbstractDao.log.debug("Fetching probeResults from resultSet " + resultSet.getId() + " for gene " + gene.getId() + "and " + arrayDesignIds.size() + "arrays took : " + timer.getTime() + " ms"); return results; }
From source file:ubic.gemma.persistence.service.association.coexpression.CoexpressionDaoImpl.java
License:Apache License
@Override public Map<SupportDetails, Gene2GeneCoexpression> initializeFromOldData(Gene gene, Map<Long, Gene> geneIdMap, Map<NonPersistentNonOrderedCoexpLink, SupportDetails> linksSoFar, Set<Long> skipGenes) { Session sess = this.getSessionFactory().getCurrentSession(); LinkCreator c = new LinkCreator(gene.getTaxon()); String geneLinkTableName = CoexpressionQueryUtils.getGeneLinkTableName(gene.getTaxon()); String oldGeneLinkTableName = geneLinkTableName.replace("COEX", "CO_EX"); assert oldGeneLinkTableName.contains("CO_EX"); int BATCH_SIZE = 1024; /*/*from www.j a v a 2s . c om*/ * Query the old table */ SQLQuery oldLinkQuery = sess.createSQLQuery("select FIRST_GENE_FK, SECOND_GENE_FK, EFFECT from " + oldGeneLinkTableName + " where FIRST_GENE_FK=?"); List<Object[]> oldLinks = oldLinkQuery.setLong(0, gene.getId()).list(); if (oldLinks.isEmpty()) { return null; } Map<SupportDetails, Gene2GeneCoexpression> linksToSave = new LinkedHashMap<>(); /* * Make new links. */ Collection<NonPersistentNonOrderedCoexpLink> links = new HashSet<>(); int i = 0; for (Object[] o : oldLinks) { Long fgid = ((BigInteger) o[0]).longValue(); Long sgid = ((BigInteger) o[1]).longValue(); if (skipGenes != null && (skipGenes.contains(fgid) || skipGenes.contains(sgid))) { continue; } Double eff = (Double) o[2]; if (fgid.equals(sgid)) { continue; } assert geneIdMap.containsKey(fgid); assert geneIdMap.containsKey(sgid); Gene2GeneCoexpression g2g = c.create(eff, fgid, sgid); /* * Check if we already have a link like this for the reverse - if so, reuse the supportdetails; the keys of * linksSoFar are id-less, so equals() is by genes and direction. */ SupportDetails sdOfFlipped = linksSoFar .get(new NonPersistentNonOrderedCoexpLink(geneIdMap.get(fgid), geneIdMap.get(sgid), eff > 0)); SupportDetails sd; if (sdOfFlipped != null) { sd = sdOfFlipped; } else { // we haven't saved the flipped link already so make a new support details. sd = c.createSupportDetails(geneIdMap.get(fgid), geneIdMap.get(sgid), eff > 0); sess.save(sd); } g2g.setNumDatasetsSupporting(0); g2g.setSupportDetails(sd); assert sd.getId() != null; linksToSave.put(sd, g2g); links.add(new NonPersistentNonOrderedCoexpLink(g2g)); if (i++ % BATCH_SIZE == 0) { sess.flush(); sess.clear(); } } for (SupportDetails sd : linksToSave.keySet()) { assert sd.getId() != null; sess.save(linksToSave.get(sd)); if (i++ % BATCH_SIZE == 0) { sess.flush(); sess.clear(); } } this.updateGeneCoexpressedWith(links); return linksToSave; }
From source file:ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentDaoImpl.java
License:Apache License
@Override public Collection<ExpressionExperiment> findByExpressedGene(Gene gene, Double rank) { //language=MySQL final String queryString = "SELECT DISTINCT ee.ID AS eeID FROM " + "GENE2CS g2s, COMPOSITE_SEQUENCE cs, PROCESSED_EXPRESSION_DATA_VECTOR dedv, INVESTIGATION ee " + "WHERE g2s.CS = cs.ID AND cs.ID = dedv.DESIGN_ELEMENT_FK AND dedv.EXPRESSION_EXPERIMENT_FK = ee.ID" + " AND g2s.gene = :geneID AND dedv.RANK_BY_MEAN >= :rank"; Collection<Long> eeIds; try {/* ww w . j a v a 2 s . c om*/ Session session = this.getSessionFactory().getCurrentSession(); org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.setLong("geneID", gene.getId()); queryObject.setDouble("rank", rank); queryObject.addScalar("eeID", new LongType()); ScrollableResults results = queryObject.scroll(); eeIds = new HashSet<>(); // Post Processing while (results.next()) eeIds.add(results.getLong(0)); session.clear(); } catch (org.hibernate.HibernateException ex) { throw super.convertHibernateAccessException(ex); } return this.load(eeIds); }
From source file:ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentDaoImpl.java
License:Apache License
@Override public Collection<ExpressionExperiment> findByGene(Gene gene) { /*// www . j a va 2 s . c om * uses GENE2CS table. */ //language=MySQL final String queryString = "SELECT DISTINCT ee.ID AS eeID FROM " + "GENE2CS g2s, COMPOSITE_SEQUENCE cs, ARRAY_DESIGN ad, BIO_ASSAY ba, INVESTIGATION ee " + "WHERE g2s.CS = cs.ID AND ad.ID = cs.ARRAY_DESIGN_FK AND ba.ARRAY_DESIGN_USED_FK = ad.ID AND" + " ba.EXPRESSION_EXPERIMENT_FK = ee.ID AND g2s.GENE = :geneID"; Collection<Long> eeIds; Session session = this.getSessionFactory().getCurrentSession(); org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.setLong("geneID", gene.getId()); queryObject.addScalar("eeID", new LongType()); ScrollableResults results = queryObject.scroll(); eeIds = new HashSet<>(); while (results.next()) { eeIds.add(results.getLong(0)); } return this.load(eeIds); }