List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(String tableAlias, Class entityType);
From source file:org.generationcp.middleware.dao.ScaleDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Scale> getByTraitId(Integer traitId) throws MiddlewareQueryException { try {/*from w ww . j ava 2s . co m*/ SQLQuery query = getSession().createSQLQuery(Scale.GET_BY_TRAIT_ID); query.addEntity("s", Scale.class); query.setParameter("traitid", traitId); return query.list(); } catch (HibernateException e) { throw new MiddlewareQueryException( "Error with getByTraitId(traitId=" + traitId + ") query from Scale: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.StudyDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getByCountryUsingEqual(String country, int start, int numOfRows) throws MiddlewareQueryException { try {/*from w ww . j a v a 2 s. c om*/ SQLQuery query = getSession().createSQLQuery(Study.GET_BY_COUNTRY_USING_EQUAL); query.setParameter("country", country); query.addEntity("s", Study.class); query.setFirstResult(start); query.setMaxResults(numOfRows); return query.list(); } catch (HibernateException e) { throw new MiddlewareQueryException("Error with getByCountryUsingEqual(country=" + country + ") query from Study: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.StudyDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getByCountryUsingLike(String country, int start, int numOfRows) throws MiddlewareQueryException { try {/*from w w w . ja v a2 s .com*/ SQLQuery query = getSession().createSQLQuery(Study.GET_BY_COUNTRY_USING_LIKE); query.setParameter("country", country); query.addEntity("s", Study.class); query.setFirstResult(start); query.setMaxResults(numOfRows); return query.list(); } catch (HibernateException e) { throw new MiddlewareQueryException( "Error with getByCountryUsingLike(country=" + country + ") query from Study: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.StudyDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Study> getBySeason(Season season, int start, int numOfRows) throws MiddlewareQueryException { try {/* w w w . java 2 s . c o m*/ SQLQuery query = getSession().createSQLQuery(Study.GET_BY_SEASON); if (season == Season.DRY) { query = getSession().createSQLQuery(Study.GET_BY_SEASON + Study.DRY_SEASON_CONDITION); } else if (season == Season.WET) { query = getSession().createSQLQuery(Study.GET_BY_SEASON + Study.WET_SEASON_CONDITION); } query.addEntity("s", Study.class); query.setFirstResult(start); query.setMaxResults(numOfRows); return query.list(); } catch (HibernateException e) { throw new MiddlewareQueryException( "Error with getBySeason(season=" + season + ") query from Study: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.TraitMethodDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<TraitMethod> getByTraitId(Integer traitId) throws MiddlewareQueryException { try {// w ww. ja v a2 s . c o m SQLQuery query = getSession().createSQLQuery(TraitMethod.GET_BY_TRAIT_ID); query.addEntity("m", TraitMethod.class); query.setParameter("traitid", traitId); return query.list(); } catch (HibernateException e) { throw new MiddlewareQueryException( "Error with getByTraitId(traitId=" + traitId + ") query from TraitMethod: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.UserDefinedFieldDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<UserDefinedField> getAttributeTypesByGIDList(final List<Integer> gidList) { List<UserDefinedField> returnList = new ArrayList<>(); if (gidList != null && !gidList.isEmpty()) { try {/*from ww w . ja v a2 s .c o m*/ final String sql = "SELECT DISTINCT {u.*}" + " FROM atributs a" + " INNER JOIN udflds u" + " WHERE a.atype=u.fldno" + " AND a.gid in (:gidList)" + " ORDER BY u.fname"; final SQLQuery query = this.getSession().createSQLQuery(sql); query.addEntity("u", UserDefinedField.class); query.setParameterList("gidList", gidList); returnList = query.list(); } catch (final HibernateException e) { throw new MiddlewareQueryException( "Error with getAttributesByGIDList(gidList=" + gidList + "): " + e.getMessage(), e); } } return returnList; }
From source file:org.generationcp.middleware.dao.UserDefinedFieldDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<UserDefinedField> getNameTypesByGIDList(final List<Integer> gidList) { List<UserDefinedField> returnList = new ArrayList<>(); if (gidList != null && !gidList.isEmpty()) { try {/* w w w . j av a 2 s .c o m*/ final String sql = "SELECT DISTINCT {u.*}" + " FROM names n" + " INNER JOIN udflds u" + " WHERE n.ntype=u.fldno" + " AND n.gid in (:gidList)" + " ORDER BY u.fname"; final SQLQuery query = this.getSession().createSQLQuery(sql); query.addEntity("u", UserDefinedField.class); query.setParameterList("gidList", gidList); returnList = query.list(); } catch (final HibernateException e) { throw new MiddlewareQueryException( "Error with getNameTypesByGIDList(gidList=" + gidList + "): " + e.getMessage(), e); } } return returnList; }
From source file:org.generationcp.middleware.dao.VariateDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Variate> getByRepresentationId(Integer representationId) throws MiddlewareQueryException { try {//from w ww . j av a 2 s .c o m SQLQuery query = getSession().createSQLQuery(Variate.GET_BY_REPRESENTATION_ID); query.setParameter("representationId", representationId); query.addEntity("v", Variate.class); return (List<Variate>) query.list(); } catch (HibernateException e) { throw new MiddlewareQueryException("Error with getByRepresentationId(representationId=" + representationId + ") query from Variate: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.manager.GermplasmDataManagerImpl.java
License:Open Source License
/** * (non-Javadoc)//from ww w. j a v a 2 s . c o m * * @see org.generationcp.middleware.manager.api.GermplasmDataManager#getGermplasmWithAllNamesAndAncestry(java.util.Set, int) */ @SuppressWarnings("unchecked") @Override public List<Germplasm> getGermplasmWithAllNamesAndAncestry(final Set<Integer> gids, final int numberOfLevelsToTraverse) { final Monitor monitor = MonitorFactory.start("org.generationcp.middleware.manager.GermplasmDataManagerImpl" + ".getGermplasmWithAllNamesAndAncestry(Set<Integer> - SetSize(" + gids.size() + ") , int)"); try { final StringBuilder commaSeparatedListOfGids = this.getGidsAsCommaSeparatedList(gids); final SQLQuery storedProcedure = this.getActiveSession() .createSQLQuery("CALL getGermplasmWithNamesAndAncestry(:gids, :numberOfLevelsToTraverse) "); storedProcedure.setParameter("gids", commaSeparatedListOfGids.toString()); storedProcedure.setParameter("numberOfLevelsToTraverse", numberOfLevelsToTraverse); storedProcedure.addEntity("g", Germplasm.class); storedProcedure.addJoin("n", "g.names"); // Be very careful changing anything here. // The entity has been added again because the distinct root entity works on the // Last added entity storedProcedure.addEntity("g", Germplasm.class); storedProcedure.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return storedProcedure.list(); } finally { monitor.stop(); } }
From source file:org.hyperic.hq.grouping.CritterTranslator.java
License:Open Source License
private SQLQuery translate(CritterTranslationContext ctx, CritterList cList, boolean issueCount, boolean desc) { StringBuilder sql = new StringBuilder(); Map txContexts = new HashMap(cList.getCritters().size()); if (issueCount) { sql.append("select count(1) from "); } else {//from w w w. j av a2s. c om sql.append("select {res.*} from "); } if (cList.isAll()) { sql.append("EAM_RESOURCE res \n"); sql.append(getSQLConstraints(ctx, cList, txContexts)); sql.append(PermissionManagerFactory.getInstance().getSQLWhere(ctx.getSubject().getId())); } else { sql.append(getUnionStmts(ctx, cList, txContexts)); sql.append(PermissionManagerFactory.getInstance().getSQLWhere(ctx.getSubject().getId())); sql.append(") res "); } if (!issueCount) { sql.append(" ORDER BY res.name "); if (desc) sql.append("DESC"); } if (_log.isDebugEnabled()) { _log.debug("Created SQL: [" + sql + "]"); } SQLQuery res = ctx.getSession().createSQLQuery(sql.toString()); if (_log.isDebugEnabled()) { _log.debug("Translated into: [" + res.getQueryString() + "]"); } if (!issueCount) { res.addEntity("res", Resource.class); } for (Iterator i = cList.getCritters().iterator(); i.hasNext();) { Critter c = (Critter) i.next(); c.bindSqlParams((CritterTranslationContext) txContexts.get(c), res); } return res; }