List of usage examples for org.hibernate.criterion CriteriaSpecification ALIAS_TO_ENTITY_MAP
ResultTransformer ALIAS_TO_ENTITY_MAP
To view the source code for org.hibernate.criterion CriteriaSpecification ALIAS_TO_ENTITY_MAP.
Click Source Link
From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateUserDao.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w . ja v a 2s . c om public List<User> findAllTeamMembers(long teamId, PagingAndSorting paging, Filtering filtering) { Criteria crit = currentSession().createCriteria(Team.class, "Team").add(Restrictions.eq("Team.id", teamId)) .createCriteria("Team.members", "User") .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); /* add ordering */ String sortedAttribute = paging.getSortedAttribute(); if (sortedAttribute != null) { SortingUtils.addOrder(crit, paging); } /* add filtering */ if (filtering.isDefined()) { crit = crit.add(filterMembers(filtering)); } /* result range */ PagingUtils.addPaging(crit, paging); return collectFromMapList(crit.list(), "User"); }
From source file:org.squashtest.tm.service.internal.repository.hibernate.TeamDaoImpl.java
License:Open Source License
/** * @see CustomTeamDao#findSortedAssociatedTeams(long, PagingAndSorting, Filtering) *//* ww w . j av a 2 s. c o m*/ @Override @SuppressWarnings("unchecked") public List<Team> findSortedAssociatedTeams(long userId, PagingAndSorting paging, Filtering filtering) { Criteria crit = currentSession().createCriteria(User.class, "User").add(Restrictions.eq("User.id", userId)) .createCriteria("User.teams", "Team") .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); /* add ordering */ String sortedAttribute = paging.getSortedAttribute(); if (sortedAttribute != null) { SortingUtils.addOrder(crit, paging); } /* add filtering */ if (filtering.isDefined()) { crit = crit.add(filterAssociatedTeams(filtering)); } /* result range */ PagingUtils.addPaging(crit, paging); return collectFromMapList(crit.list(), "Team"); }
From source file:org.transitime.reports.RoutePerformanceQuery.java
License:Open Source License
public List<Object[]> query(String agencyId, Date startDate, Date endDate, double allowableEarlyMin, double allowableLateMin, String predictionType, String predictionSource) { int msecLo = (int) (allowableEarlyMin * 60 * 1000); int msecHi = (int) (allowableLateMin * 60 * 1000); // Project to: # of predictions in which route is on time / # of predictions // for route. This cannot be done with pure Criteria API. This could be // moved to a separate class or XML file. String sqlProjection = "avg(predictionAccuracyMsecs BETWEEN " + Integer.toString(msecLo) + " AND " + Integer.toString(msecHi) + ") AS avgAccuracy"; try {//from www. ja v a 2s . co m session = HibernateUtils.getSession(agencyId); Projection proj = Projections.projectionList().add(Projections.groupProperty("routeId"), "routeId") .add(Projections.sqlProjection(sqlProjection, new String[] { "avgAccuracy" }, new Type[] { DoubleType.INSTANCE }), "performance"); Criteria criteria = session.createCriteria(PredictionAccuracy.class).setProjection(proj) .add(Restrictions.between("arrivalDepartureTime", startDate, endDate)); if (predictionType == PREDICTION_TYPE_AFFECTED) criteria.add(Restrictions.eq("affectedByWaitStop", true)); else if (predictionType == PREDICTION_TYPE_NOT_AFFECTED) criteria.add(Restrictions.eq("affectedByWaitStop", false)); if (predictionSource != "") criteria.add(Restrictions.eq("predictionSource", predictionSource)); criteria.addOrder(Order.desc("performance")); criteria.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); @SuppressWarnings("unchecked") List<Object[]> results = criteria.list(); return results; } catch (HibernateException e) { logger.error(e.toString()); return null; } finally { session.close(); } }
From source file:service.MasterPosisiService.java
public static List<TrJabatan> getDataPosisi() { Session session = HibernateUtil.openSession(); String nativeSql = " select a.jabatan" + " from tr_jabatan a;"; SQLQuery query = session.createSQLQuery(nativeSql); query.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); List result = query.list();/*from w w w . ja va 2s . co m*/ session.getTransaction().commit(); List<TrJabatan> returnList = new ArrayList<TrJabatan>(); for (Object obj : result) { Map row = (Map) obj; TrJabatan everyRow = new TrJabatan(); everyRow.setJabatan((String) row.get("JABATAN")); returnList.add(everyRow); } return returnList; }
From source file:uk.ac.ox.oucs.vle.CourseDAOImpl.java
License:Educational Community License
public List<Map> findComponentSignups(final String componentId, final Set<Status> statuses, final Integer year) { // This is an optimisation for exports. It orders by component then return getHibernateTemplate().execute(new HibernateCallback<List<Map>>() { public List<Map> doInHibernate(Session session) throws HibernateException, SQLException { Criteria find = session.createCriteria(CourseComponentDAO.class) .createAlias("signups", "signup", CriteriaSpecification.LEFT_JOIN) .createAlias("signups.group", "group", CriteriaSpecification.LEFT_JOIN) .addOrder(Order.desc("presentationId")).addOrder(Order.desc("group.id")) .addOrder(Order.desc("signup.id")) .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); // If componentId is null then return all. if (componentId != null && !"all".equals(componentId)) { find.add(Restrictions.eq("presentationId", componentId)); }/*from w w w. j a va 2s.c o m*/ if (null != statuses && !statuses.isEmpty()) { find.add(Restrictions.in("signup.status", statuses)); } if (null != year) { LocalDate startYear = FIRST_DAY_OF_ACADEMIC_YEAR.toLocalDate(year); LocalDate endYear = FIRST_DAY_OF_ACADEMIC_YEAR.toLocalDate(year + 1); find.add(Restrictions.between("starts", startYear.toDate(), endYear.toDate())); } Object result = find.list(); return (List<Map>) result; } }); }