List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:fr.mael.microrss.dao.impl.UserDaoImpl.java
License:Open Source License
@Override public UserConfig getConfig(User user) { StringBuffer query = new StringBuffer("from UserConfig "); query.append("where user = :user"); Query q = getSession().createQuery(query.toString()); q.setEntity("user", user); return (UserConfig) q.uniqueResult(); }
From source file:fr.mael.microrss.dao.impl.UserDaoImpl.java
License:Open Source License
@Override public void updateConfig(User user, String name, String value) { StringBuffer query = new StringBuffer("update UserConfig set " + name + " = :value "); query.append("where user = :user"); Query q = getSession().createQuery(query.toString()); q.setString("value", value); q.setEntity("user", user); q.executeUpdate();/* ww w .j av a2 s. c o m*/ }
From source file:gov.nih.nci.caarray.dao.ArrayDaoImpl.java
License:BSD License
/** * {@inheritDoc}/*from w w w. j ava 2s . c o m*/ */ @Override @SuppressWarnings("unchecked") public List<ArrayDesign> getArrayDesigns(Organization provider, Set<AssayType> assayTypes, boolean importedOnly) { boolean containsAssayType = false; if (assayTypes != null && !assayTypes.isEmpty()) { containsAssayType = true; } final StringBuilder queryStr = generateArrayDesignQuery(provider, containsAssayType, assayTypes, importedOnly); final Query query = getCurrentSession().createQuery(queryStr.toString()); if (provider != null) { query.setEntity("provider", provider); } if (containsAssayType) { int i = 0; for (final AssayType type : assayTypes) { query.setLong("assayType" + i, type.getId()); i++; } } if (importedOnly) { query.setString("status1", FileStatus.IMPORTED.name()); query.setString("status2", FileStatus.IMPORTED_NOT_PARSED.name()); } return query.list(); }
From source file:gov.nih.nci.caarray.dao.ProjectDaoImpl.java
License:BSD License
/** * {@inheritDoc}//from ww w. j a v a 2 s. c o m */ @Override public List<Project> getProjectsForOwner(User user) { final String q = "SELECT DISTINCT p FROM " + Project.class.getName() + " p left join fetch p.experiment e where p.id in" + "(select pe.value from " + ProtectionElement.class.getName() + " pe where pe.objectId = :objectId and pe.attribute = :attribute and " + " pe.application = :application and :user in elements(pe.owners)) "; final Query query = getCurrentSession().createQuery(q); query.setString("objectId", Project.class.getName()); query.setString("attribute", "id"); query.setEntity("application", SecurityUtils.getApplication()); query.setEntity("user", user); @SuppressWarnings("unchecked") final List<Project> projects = query.list(); return projects; // NOPMD }
From source file:gov.nih.nci.caarray.dao.ProjectDaoImpl.java
License:BSD License
@SuppressWarnings({ "PMD.ExcessiveMethodLength", "PMD.NPathComplexity" }) private Query getProjectsForUserQuery(boolean count, PageSortParams<Project> pageSortParams) { final User user = CaArrayUsernameHolder.getCsmUser(); @SuppressWarnings("deprecation") final SortCriterion<Project> sortCrit = pageSortParams != null ? pageSortParams.getSortCriterion() : null; final String ownerSubqueryStr = "(select pe.value from " + ProtectionElement.class.getName() + " pe where pe.objectId = :objectId and pe.attribute = :attribute and " + " pe.application = :application and :user in elements(pe.owners)) "; final String collabSubqueryStr = "(select ap.projectForGroupProfile.id from " + AccessProfile.class.getName() + " ap join ap.group cg, Group g " + " where ap.securityLevelInternal != :noneSecLevel and cg.groupId = g.groupId " + " and :user in elements(g.users))"; final String selectClause = count ? "SELECT COUNT(DISTINCT p)" : "SELECT DISTINCT p"; final StringBuilder queryStr = new StringBuilder(selectClause).append(" from ") .append(Project.class.getName()).append(" p "); if (!count) { queryStr.append(" left join fetch p.experiment e"); }// w ww . j av a 2 s. c o m queryStr.append(" where (p.id in ").append(ownerSubqueryStr).append(" or p.id in ") .append(collabSubqueryStr).append(")"); if (!count && sortCrit != null) { queryStr.append(" ORDER BY p.").append(sortCrit.getOrderField()); if (pageSortParams.isDesc()) { queryStr.append(" desc"); } } final Query query = getCurrentSession().createQuery(queryStr.toString()); query.setString("objectId", Project.class.getName()); query.setString("attribute", "id"); query.setEntity("application", SecurityUtils.getApplication()); query.setEntity("user", user); query.setParameter("noneSecLevel", SecurityLevel.NONE); return query; }
From source file:gov.nih.nci.caarray.dao.ProjectDaoImpl.java
License:BSD License
private Query generateArbitraryCharacteristicsCategoriesPreparedQuery(Experiment experiment, String entityToken) {/* ww w . j a v a 2s . c om*/ String sQuery = "select distinct @ENTITY@ " + "from @EXPERIMENT@ e " + " left join e.biomaterials abs " + " left join abs.characteristics acs " + "where (abs.class = :sample_class or abs.class = :source_class) " + " and e.id = :exp"; sQuery = sQuery.replaceAll("@ENTITY@", entityToken).replaceAll("@EXPERIMENT@", Experiment.class.getName()); Query q = getCurrentSession().createQuery(sQuery); q.setString("sample_class", Sample.DISCRIMINATOR); q.setString("source_class", Source.DISCRIMINATOR); q.setEntity("exp", experiment); return q; }
From source file:gov.nih.nci.caarray.dao.ProtocolDaoImpl.java
License:BSD License
/** * {@inheritDoc}// w w w. jav a 2s. co m */ public Protocol getProtocol(String name, TermSource source) { if (StringUtils.isEmpty(name) || source == null || source.getId() == null) { // all of these fields are required return null; } String hsql = "from " + Protocol.class.getName() + " where name = :name and source = :source"; Query q = getCurrentSession().createQuery(hsql); q.setString(NAME_FIELD, name); q.setEntity("source", source); return (Protocol) q.uniqueResult(); }
From source file:gov.nih.nci.caarray.dao.ProtocolDaoImpl.java
License:BSD License
/** * {@inheritDoc}//w w w . j av a2s .c o m */ public Parameter getParameter(String name, Protocol protocol) { if (protocol == null || protocol.getId() == null) { return null; } String hsql = "from " + Parameter.class.getName() + " where name = :name and protocol = :protocol"; Query q = getCurrentSession().createQuery(hsql); q.setString(NAME_FIELD, name); q.setEntity("protocol", protocol); return (Parameter) q.uniqueResult(); }
From source file:gov.nih.nci.caarray.dao.SampleDaoImpl.java
License:BSD License
/** * {@inheritDoc}//from www . ja v a 2s . c o m */ @SuppressWarnings(UNCHECKED) public List<Sample> searchSamplesByExperimentAndCategory(String keyword, Experiment e, SearchSampleCategory... c) { StringBuffer sb = new StringBuffer(); sb.append(SELECT_DISTINCT + "s"); sb.append(FROM_KEYWORD + Sample.class.getName() + " s"); sb.append(getJoinClause(false, null, c)); sb.append(getWhereClause(singletonClass(Sample.class), c)); sb.append(" AND s.experiment = :exp" + ORDER_BY + "s.name"); Query q = getCurrentSession().createQuery(sb.toString()); q.setEntity("exp", e); q.setString(KEYWORD_SUB, "%" + keyword + "%"); return q.list(); }
From source file:gov.nih.nci.caarray.dao.SampleDaoImpl.java
License:BSD License
/** * {@inheritDoc}//from w ww . j av a2s .co m */ @SuppressWarnings({ "unchecked" }) public List<Sample> searchSamplesByExperimentAndArbitraryCharacteristicValue(String keyword, Experiment experiment, Category category) { String sQueryPattern = "select distinct s " + "from @CHARACTERISTIC@ ch " + " join ch.bioMaterial s " + "where s.class = :cls" + " and s.experiment = :exp " + " and ch.category = :cat " + " and @VALUE@ like :keyw"; Map<String, String> sQuerySubstitutes = Maps.newHashMap(); sQuerySubstitutes.put("TermBasedCharacteristic", "ch.term.value"); sQuerySubstitutes.put("UserDefinedCharacteristic", "ch.value"); sQuerySubstitutes.put("MeasurementCharacteristic", "ch.value"); List<Sample> sampleList = Lists.newArrayList(); for (String materialType : Sets.newHashSet(Sample.DISCRIMINATOR, Source.DISCRIMINATOR)) { for (Entry<String, String> substitute : sQuerySubstitutes.entrySet()) { String sQuery = sQueryPattern.replaceAll("@CHARACTERISTIC@", substitute.getKey()) .replaceAll("@VALUE@", substitute.getValue()); Query query = getCurrentSession().createQuery(sQuery); query.setString("cls", materialType); query.setEntity("exp", experiment); query.setEntity("cat", category); query.setString("keyw", "%" + keyword + "%"); List<AbstractBioMaterial> bioMaterialList = (List<AbstractBioMaterial>) query.list(); for (AbstractBioMaterial bioMaterial : bioMaterialList) { if (bioMaterial instanceof Sample) { sampleList.add((Sample) bioMaterial); } else { sampleList.addAll(((Source) bioMaterial).getSamples()); } } } } return sampleList; }