List of usage examples for org.hibernate.criterion Projections projectionList
public static ProjectionList projectionList()
From source file:com.evolveum.midpoint.repo.sql.query.QueryInterpreter.java
License:Apache License
public Criteria interpret(ObjectQuery query, Class<? extends ObjectType> type, Collection<SelectorOptions<GetOperationOptions>> options, PrismContext prismContext, boolean countingObjects, Session session) throws QueryException { Validate.notNull(type, "Type must not be null."); Validate.notNull(session, "Session must not be null."); Validate.notNull(prismContext, "Prism context must not be null."); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Interpreting query for type '{}', query:\n{}", new Object[] { type, query }); }//from w ww .j ava 2s .c om Criteria criteria; if (query != null && query.getFilter() != null) { criteria = interpretQuery(query, type, prismContext, session); } else { criteria = session.createCriteria(ClassMapper.getHQLTypeClass(type)); } if (!countingObjects && query != null && query.getPaging() != null) { criteria = updatePagingAndSorting(criteria, type, query.getPaging()); } if (!countingObjects) { ProjectionList projections = Projections.projectionList(); projections.add(Projections.property("fullObject")); projections.add(Projections.property("stringsCount")); projections.add(Projections.property("longsCount")); projections.add(Projections.property("datesCount")); projections.add(Projections.property("referencesCount")); projections.add(Projections.property("polysCount")); criteria.setProjection(projections); } return criteria; }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryOrganizationNorm() throws Exception { Session session = open();/*from w ww. jav a2 s. co m*/ try { ObjectFilter filter = EqualFilter.createEqual(UserType.F_ORGANIZATION, UserType.class, prismContext, PolyStringNormMatchingRule.NAME, new PolyString("asdf", "asdf")); ObjectQuery query = ObjectQuery.createObjectQuery(filter); Criteria main = session.createCriteria(RUser.class, "u"); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("u", projections, false); main.setProjection(projections); Criteria o = main.createCriteria("organization", "o", JoinType.LEFT_OUTER_JOIN); o.add(Restrictions.eq("o.norm", "asdf")); String expected = HibernateToSqlTranslator.toSql(main); String real = getInterpretedQuery(session, UserType.class, query); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryOrganizationOrig() throws Exception { Session session = open();//from ww w . j a va2 s.co m try { ObjectFilter filter = EqualFilter.createEqual(UserType.F_ORGANIZATION, UserType.class, prismContext, PolyStringOrigMatchingRule.NAME, new PolyString("asdf", "asdf")); ObjectQuery query = ObjectQuery.createObjectQuery(filter); Criteria main = session.createCriteria(RUser.class, "u"); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("u", projections, false); main.setProjection(projections); Criteria o = main.createCriteria("organization", "o", JoinType.LEFT_OUTER_JOIN); o.add(Restrictions.eq("o.orig", "asdf")); String expected = HibernateToSqlTranslator.toSql(main); String real = getInterpretedQuery(session, UserType.class, query); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryOrganizationStrict() throws Exception { Session session = open();/*from w w w. j a v a 2 s.c om*/ try { ObjectFilter filter = EqualFilter.createEqual(UserType.F_ORGANIZATION, UserType.class, prismContext, null, new PolyString("asdf", "asdf")); ObjectQuery query = ObjectQuery.createObjectQuery(filter); Criteria main = session.createCriteria(RUser.class, "u"); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("u", projections, false); main.setProjection(projections); Criteria o = main.createCriteria("organization", "o", JoinType.LEFT_OUTER_JOIN); o.add(Restrictions.conjunction().add(Restrictions.eq("o.orig", "asdf")) .add(Restrictions.eq("o.norm", "asdf"))); String expected = HibernateToSqlTranslator.toSql(main); String real = getInterpretedQuery(session, UserType.class, query); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryDependent() throws Exception { Session session = open();//from w ww .j av a2 s .c o m try { Criteria main = session.createCriteria(RTask.class, "t"); Criteria d = main.createCriteria("dependent", "d", JoinType.LEFT_OUTER_JOIN); d.add(Restrictions.eq("d.elements", "123456")); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("t", projections, false); main.setProjection(projections); String expected = HibernateToSqlTranslator.toSql(main); ObjectFilter filter = EqualFilter.createEqual(TaskType.F_DEPENDENT, TaskType.class, prismContext, null, "123456"); ObjectQuery query = ObjectQuery.createObjectQuery(filter); String real = getInterpretedQuery(session, TaskType.class, query); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryEnum() throws Exception { Session session = open();/*w w w .jav a 2 s . c om*/ try { Criteria main = session.createCriteria(RTask.class, "t"); main.add(Restrictions.eq("executionStatus", RTaskExecutionStatus.WAITING)); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("t", projections, false); main.setProjection(projections); String expected = HibernateToSqlTranslator.toSql(main); ObjectFilter filter = EqualFilter.createEqual(TaskType.F_EXECUTION_STATUS, TaskType.class, prismContext, null, TaskExecutionStatusType.WAITING); ObjectQuery query = ObjectQuery.createObjectQuery(filter); String real = getInterpretedQuery(session, TaskType.class, query); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryEnabled() throws Exception { Session session = open();/*from w ww. j a v a 2 s. c o m*/ try { Criteria main = session.createCriteria(RUser.class, "u"); main.add(Restrictions.eq("activation.administrativeStatus", RActivationStatus.ENABLED)); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("u", projections, false); main.setProjection(projections); String expected = HibernateToSqlTranslator.toSql(main); String real = getInterpretedQuery(session, UserType.class, new File(TEST_DIR, "query-user-by-enabled.xml")); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryGenericLong() throws Exception { Session session = open();/*from w ww . j av a 2s. co m*/ try { Criteria main = session.createCriteria(RGenericObject.class, "g"); Criteria stringExt = main.createCriteria("longs", "l", JoinType.LEFT_OUTER_JOIN); //and Criterion c1 = Restrictions.eq("name.norm", "generic object"); //and Conjunction c2 = Restrictions.conjunction(); c2.add(Restrictions.eq("l.ownerType", RObjectExtensionType.EXTENSION)); c2.add(Restrictions.eq("l.name", new QName("http://example.com/p", "intType"))); c2.add(Restrictions.eq("l.value", 123L)); Conjunction conjunction = Restrictions.conjunction(); conjunction.add(c1); conjunction.add(c2); main.add(conjunction); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("g", projections, false); main.setProjection(projections); String expected = HibernateToSqlTranslator.toSql(main); String real = getInterpretedQuery(session, GenericObjectType.class, new File(TEST_DIR, "query-and-generic.xml")); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryOrComposite() throws Exception { Session session = open();/* w w w . j a v a 2 s . c o m*/ try { Criteria main = session.createCriteria(RShadow.class, "r"); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("r", projections, false); main.setProjection(projections); Criteria stringExt = main.createCriteria("strings", "s1", JoinType.LEFT_OUTER_JOIN); //or Criterion c1 = Restrictions.eq("intent", "some account type"); //or Conjunction c2 = Restrictions.conjunction(); c2.add(Restrictions.eq("s1.ownerType", RObjectExtensionType.ATTRIBUTES)); c2.add(Restrictions.eq("s1.name", new QName("http://midpoint.evolveum.com/blabla", "foo"))); c2.add(Restrictions.eq("s1.value", "foo value")); //or Conjunction c3 = Restrictions.conjunction(); c3.add(Restrictions.eq("s1.ownerType", RObjectExtensionType.EXTENSION)); c3.add(Restrictions.eq("s1.name", new QName("http://example.com/p", "stringType"))); c3.add(Restrictions.eq("s1.value", "uid=test,dc=example,dc=com")); //or Conjunction c4 = Restrictions.conjunction(); c4.add(Restrictions.eq("r.resourceRef.targetOid", "d0db5be9-cb93-401f-b6c1-86ffffe4cd5e")); c4.add(Restrictions.eq("r.resourceRef.type", QNameUtil.qNameToUri(ResourceType.COMPLEX_TYPE))); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(c1); disjunction.add(c2); disjunction.add(c3); disjunction.add(c4); main.add(disjunction); String expected = HibernateToSqlTranslator.toSql(main); String real = getInterpretedQuery(session, ShadowType.class, new File(TEST_DIR, "query-or-composite.xml")); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }
From source file:com.evolveum.midpoint.repo.sql.QueryInterpreterTest.java
License:Apache License
@Test public void queryObjectByName() throws Exception { Session session = open();/*from ww w . j a v a 2 s . co m*/ try { Criteria main = session.createCriteria(RObject.class, "o"); main.add(Restrictions.and(Restrictions.eq("name.orig", "cpt. Jack Sparrow"), Restrictions.eq("name.norm", "cpt jack sparrow"))); main.addOrder(Order.asc("name.orig")); ProjectionList projections = Projections.projectionList(); addFullObjectProjectionList("o", projections, false); main.setProjection(projections); String expected = HibernateToSqlTranslator.toSql(main); EqualFilter filter = EqualFilter.createEqual(ObjectType.F_NAME, ObjectType.class, prismContext, null, new PolyString("cpt. Jack Sparrow", "cpt jack sparrow")); ObjectQuery query = ObjectQuery.createObjectQuery(filter); query.setPaging(ObjectPaging.createPaging(null, null, ObjectType.F_NAME, OrderDirection.ASCENDING)); String real = getInterpretedQuery(session, ObjectType.class, query); LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[] { expected, real }); AssertJUnit.assertEquals(expected, real); } finally { close(session); } }