public QEmployee employees(com.mysema.query.types.Expression<Integer> index) { return employees.get(index); }
@Override public <E> Path<List<E>> createListPath(Class<E> elementType, PathMetadata<?> metadata) { return new ListPath<E,EntityPathBase<E>>(elementType, (Class)EntityPathBase.class, metadata); }
@Override public Q get(int index) { if (cache.containsKey(index)) { return cache.get(index); } else { Q rv = create(index); cache.put(index, rv); return rv; } }
@Override public Q get(Expression<Integer> index) { PathMetadata<Integer> md = forListAccess(index); return newInstance(queryType, md); }
@Test public void Nested_Any_BooleanOperation() { QCompany company = QCompany.company; Predicate predicate = company.departments.any().employees.any().firstName.eq("Bob"); assertMatches("exists \\(select 1\n" + "from company.departments as company_departments_.*\n" + " inner join company_departments_.*.employees as company_departments_.*_employees_.*\n" + "where company_departments_.*_employees_.*.firstName = \\?1\\)", serialize(predicate)); }
@Test public void OrderBy_Any() { QCat cat = QCat.cat; QCat cat_kittens = new QCat("cat_kittens"); mixin.from(cat); mixin.orderBy(cat.kittens.any().name.asc()); QueryMetadata md = mixin.getMetadata(); assertEquals(Arrays.asList( new JoinExpression(JoinType.DEFAULT, cat), new JoinExpression(JoinType.LEFTJOIN, cat.kittens.as(cat_kittens))), md.getJoins()); assertEquals(Arrays.asList(cat_kittens.name.asc()), md.getOrderBy()); }
@Test public void Constant_InElements_List() { assertToString("?1 in elements(cat.kittens)", cat.kittens.contains(new Cat())); }
@Test public void CollectionOperations() { // HQL functions that take collection-valued path expressions: size(), // minelement(), maxelement(), minindex(), maxindex(), along with the // special elements() and indices functions which may be quantified // using some, all, exists, any, in. cat.kittens.size(); // minelement(cat.kittens); // maxelement(cat.kittens); // minindex(cat.kittens); // maxindex(cat.kittens); assertToString("cat.kittens[0]", cat.kittens(0)); assertToString("cat.kittens[0]", cat.kittens.get(0)); // some, all, exists, any, in. } }
@Test public void GroupingOperationsAndNullChecks() { // in, not in, between, is null, is not null, is empty, is not empty, // member of and not member of // in, // not in, // between, // is null, // is not null, // is empty, // is not empty, // member of // not member of kitten.in(cat.kittens); kitten.in(cat.kittens).not(); kitten.bodyWeight.between(10, 20); kitten.bodyWeight.isNull(); kitten.bodyWeight.isNotNull(); cat.kittens.isEmpty(); cat.kittens.isNotEmpty(); }
@Test public void Sum_3() throws RecognitionException, TokenStreamException { query().from(cat).where(cat.kittens.isEmpty()).select(cat).parse(); }
@Test public void DocoExamples98_8() throws Exception { query().from(cat).where(cat.kittens.isNotEmpty()).parse(); }
@Test public void Contains2() { assertEquals(1l, query().from(cat).where(cat.kittens.contains(savedCats.get(0))).count()); }
private Q create(int index) { PathMetadata<Integer> md = forListAccess(index); return newInstance(queryType, md); }
standardTest.runBooleanTests(cat.name.isNull(), otherCat.kittens.isEmpty()); standardTest.runCollectionTests(cat.kittens, otherCat.kittens, kitten, noKitten); standardTest.runDateTests(cat.dateField, otherCat.dateField, date);
@Test public void Sum_4() throws RecognitionException, TokenStreamException { query().from(cat).where(cat.kittens.isNotEmpty()).select(cat).parse(); }
public List<RoleEntity> findList(UserEntity userEntity) { QRoleEntity entity = QRoleEntity.roleEntity; BooleanExpression ex = entity.members.any().id.eq(userEntity.getId()); JPAQuery query = new JPAQuery(entityManager); List<RoleEntity> list = query.from(entity) .where( ex ) .list(entity); return list; }
public QItem items(int index) { return items.get(index); }
@Test public void test() { Company company = new Company(); Department department = new Department(); Employee employee = new Employee(); employee.department = department; department.company = company; session.save(company); session.save(department); session.save(employee); session.flush(); session.clear(); Company c = Alias.alias(Company.class); Department d = Alias.alias(Department.class); Employee e = Alias.alias(Employee.class); // count instances assertEquals(1l, session.from($(c)).count()); assertEquals(1l, session.from($(d)).count()); assertEquals(1l, session.from($(e)).count()); // direct assertEquals(1l, session.from($(d)).where($(d.getCompany()).eq(company)).count()); assertEquals(1l, session.from($(d)).where($(d.getCompany()).eq(company)).count()); assertEquals(1l, session.from($(e)).where($(e.getDepartment()).eq(department)).count()); // inverse assertEquals(1l, session.from($(c)).where($(c.getDepartment()).eq(department)).count()); assertEquals(1l, session.from($(c)).where($(c.getDepartments()).contains(department)).count()); assertEquals(1l, session.from($(d)).where($(d.getEmployees()).contains(employee)).count()); }
/** * Create a new List typed path * * @param <A> * @param <E> * @param property * @param type * @param queryType * @return */ @SuppressWarnings("unchecked") protected <A, E extends SimpleExpression<? super A>> ListPath<A, E> createList(String property, Class<? super A> type, Class<? super E> queryType, PathInits inits) { return add(new ListPath<A, E>(type, (Class) queryType, forProperty(property), inits)); }