public void testHqlQueryPlanWithEnabledFilter() { Session s = openSession(); QueryPlanCache cache = ((SessionImplementor) s).getFactory().getQueryPlanCache(); HQLQueryPlan plan1A = cache.getHQLQueryPlan("from Person", true, getEnabledFilters(s)); HQLQueryPlan plan1B = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s)); s.enableFilter("sex").setParameter("sexCode", new Character('F')); HQLQueryPlan plan2A = cache.getHQLQueryPlan("from Person", true, getEnabledFilters(s)); HQLQueryPlan plan2B = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s)); s.disableFilter("sex"); HQLQueryPlan plan3A = cache.getHQLQueryPlan("from Person", true, getEnabledFilters(s)); HQLQueryPlan plan3B = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s)); s.enableFilter("sex").setParameter("sexCode", new Character('M')); HQLQueryPlan plan4A = cache.getHQLQueryPlan("from Person", true, getEnabledFilters(s)); HQLQueryPlan plan4B = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s)); assertSame(plan1A, plan3A); assertSame(plan1B, plan3B); assertSame(plan2A, plan4A); assertSame(plan2B, plan4B); assertNotSame(plan1A, plan1B); assertNotSame(plan1A, plan2A); assertNotSame(plan1A, plan2B); assertNotSame(plan1B, plan2A); assertNotSame(plan1B, plan2B); s.close(); }
@Override public CommandResult execute(GetMonitoredPoints cmd, User user) throws CommandException { final ArrayList<MonitoredPointDTO> dtos = new ArrayList<MonitoredPointDTO>(); final Session session = ((HibernateEntityManager) em).getSession(); session.disableFilter("userVisible"); // Use a set to be avoid duplicated entries. final HashSet<OrgUnit> units = new HashSet<OrgUnit>(); // Crawl the org units hierarchy from the user root org unit. GetProjectHandler.crawlUnits(user.getOrgUnitWithProfiles().getOrgUnit(), units, false); // Retrieves all the corresponding org units. for (final OrgUnit unit : units) { // Builds and executes the query. final Query query = em.createQuery( "SELECT p.pointsList.points FROM Project p WHERE :unit MEMBER OF p.partners"); query.setParameter("unit", unit); final List<MonitoredPoint> monitoredPoints = (List<MonitoredPoint>) query.getResultList(); for (final MonitoredPoint monitoredPoint : monitoredPoints) { if (monitoredPoint.getCompletionDate() == null) // Not completed only { MonitoredPointDTO pointDTO = mapper.map(monitoredPoint, MonitoredPointDTO.class); pointDTO.setDeleted(monitoredPoint.isDeleted()); dtos.add(pointDTO); } } } final MonitoredPointsResultList result = new MonitoredPointsResultList(); result.setList(dtos); return result; }
public void disableFilter(String filterName) { session.disableFilter(filterName); }