Examples of JPAQuery


Examples of com.mysema.query.jpa.impl.JPAQuery

        return cacheableQuery().from(domain).where(domain.id.eq(id)).uniqueResult(domain);
    }

    @Override
    public List<Domain> get(Long... ids) {
        JPAQuery query = query().from(domain).where(domain.id.in(ids));
        List<Domain> list = query.list(domain);
        return list;
    }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

                .where(group.organization.in(
                        adminOrganizations.list(organization)
                ));

        // Main Query - All Groups which the user is a direct admin (ROLE_GROUP_ADMIN) or through organizations which the user is an admin (ROLE_ORG_ADMIN)
        JPAQuery mainQuery = cacheableQuery().from(group)
                .where((group.in(
                        adminOrganizationGroups.list(group))
                        .or(group.in(groupAdminDomains.list(domain.as(group.getClass()))))).and(getActiveOrganizationBooleanExpression(group.organization, user))
                );

        return mainQuery.distinct().list(group);
    }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

    @Override
    public List<Group> getGroupsForUser(User user) {
        JPASubQuery userGroups = getAllGroupsForUser(user);

        // Main query - All Groups which the user is a direct member (ROLE_GROUP_ADMIN or ROLE_GROUP_USER) or through organizations which the user is an admin (ROLE_ORG_ADMIN)
        JPAQuery mainQuery = cacheableQuery().from(group)
                .where(group.in(
                        userGroups.list(group)));

        return mainQuery.distinct().list(group);
    }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

    @Override
    public List<Group> getGroupsForUserActiveOrganization(User user) {
        JPASubQuery userGroups = getAllGroupsForUser(user);

        // Main query - All Groups which the user is a direct member (ROLE_GROUP_ADMIN or ROLE_GROUP_USER) or through organizations which the user is an admin (ROLE_ORG_ADMIN)
        JPAQuery mainQuery = query().from(group)
                .join(group.organization, organization)
                .where(group.in(userGroups.list(group))
                        .and(getActiveOrganizationBooleanExpression(organization, user)));

        return mainQuery.distinct().list(group);
    }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

    /**
     * @return JPAQuery with the default JPQLTemplate to provide operator patterns for JPQL
     */
    public JPAQuery query() {
        return new JPAQuery(getEntityManager(), JPQLTemplates.DEFAULT);
    }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

    /**
     * @return JPAQuery with a hint to set the query as cacheable
     */
    public JPAQuery cacheableQuery() {
        JPAQuery query = query();
        query.setHint("org.hibernate.cacheable", true);
        return query;
    }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

    }

    @Override
    public List<Application> getAllForUser(User user, ApplicationType... applicationTypes) {

        JPAQuery query = cacheableQuery().from(application)
                .where(getApplicationForUserBooleanExpression(user, applicationTypes));

        return query.distinct().list(application);
    }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

   */
  public AbstractJPAQuery<JPAQuery> createQuery() {

    switch (provider) {
      case ECLIPSELINK:
        return new JPAQuery(em, EclipseLinkTemplates.DEFAULT);
      case HIBERNATE:
        return new JPAQuery(em, HQLTemplates.DEFAULT);
      case OPEN_JPA:
        return new JPAQuery(em, OpenJPATemplates.DEFAULT);
      case GENERIC_JPA:
      default:
        return new JPAQuery(em);
    }
  }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

   * @param predicate
   * @return the Querydsl {@link JPQLQuery}.
   */
  protected JPQLQuery createQuery(Predicate... predicate) {

    JPAQuery query = querydsl.createQuery(path).where(predicate);
    CrudMethodMetadata metadata = getRepositoryMethodMetadata();

    if (metadata == null) {
      return query;
    }

    LockModeType type = metadata.getLockModeType();
    query = type == null ? query : query.setLockMode(type);

    for (Entry<String, Object> hint : metadata.getQueryHints().entrySet()) {
      query.setHint(hint.getKey(), hint.getValue());
    }

    JpaEntityGraph jpaEntityGraph = metadata.getEntityGraph();

    if (jpaEntityGraph == null) {
      return query;
    }

    EntityGraph<?> entityGraph = Jpa21Utils.tryGetFetchGraph(em, jpaEntityGraph);

    if (entityGraph == null) {
      return query;
    }

    query.setHint(jpaEntityGraph.getType().getKey(), entityGraph);

    return query;
  }
View Full Code Here

Examples of com.mysema.query.jpa.impl.JPAQuery

    private EntityManager entityManager;
   
    @Test
    public void test() throws IOException, ClassNotFoundException{
        // create query
        JPAQuery query = new JPAQuery(entityManager);
        query.from(cat).where(cat.name.eq("Kate")).list(cat);
       
        // get metadata
        QueryMetadata metadata = query.getMetadata();
        assertFalse(metadata.getJoins().isEmpty());
        assertTrue(metadata.getWhere() != null);
        assertTrue(metadata.getProjection().isEmpty());
       
        // serialize metadata
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(baos);
        out.writeObject(metadata);
        out.close();
       
        // deserialize metadata
        ByteArrayInputStream bain = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream in = new ObjectInputStream(bain);
        QueryMetadata  metadata2 = (QueryMetadata) in.readObject();
        in.close();
       
        // validate it
        assertEquals(metadata.getJoins(), metadata2.getJoins());
        assertEquals(metadata.getWhere(), metadata2.getWhere());
        assertEquals(metadata.getProjection(), metadata2.getProjection());
       
        // create new query
        JPAQuery query2 = new JPAQuery(entityManager, metadata2);
        assertEquals("select cat\nfrom Cat cat\nwhere cat.name = ?1", query2.toString());
        query2.list(cat);       
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.