Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaBuilder.equal()


            if ((values != null) && !values.isEmpty())
            {
                Predicate predicate = null;
                for (Map.Entry<String,Object> value : values.entrySet())
                {
                    Predicate valuePredicate = ((value.getValue() != null) ? criteriaBuilder.equal(beanRoot.get(value.getKey()), value.getValue()) : criteriaBuilder.isNull(beanRoot.get(value.getKey())));
                    predicate = ((predicate != null) ? criteriaBuilder.and(predicate, valuePredicate) : valuePredicate);
                }
                criteriaQuery.where(predicate);
            }
            if (orderBy != null)
View Full Code Here


    // select c from Customer c where c.firstName = 'Vincent'
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Customer24> criteriaQuery = builder.createQuery(Customer24.class);
    Root<Customer24> c = criteriaQuery.from(Customer24.class);
    criteriaQuery.select(c).where(builder.equal(c.get("firstName"), "Vincent"));
    assertEquals(2, em.createQuery(criteriaQuery).getResultList().size());
  }

  @Test(expected = IllegalArgumentException.class)
  public void shouldFailBecauseFirstnameIsSpelledIncorrectly() throws Exception {
View Full Code Here

    // select c from Customer c where c.firstName = 'Vincent'
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Customer24> query = builder.createQuery(Customer24.class);
    Root<Customer24> c = query.from(Customer24.class);
    query.select(c).where(builder.equal(c.get("firstname"), "Vincent"));
    assertEquals(2, em.createQuery(query).getResultList().size());
  }

//  @Test
//  public void shouldFindVincentCustomersWithMetaModel() throws Exception {
View Full Code Here

    // select c from Customer c where c.firstName = 'Vincent'
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Customer24> query = builder.createQuery(Customer24.class);
    Root<Customer24> c = query.from(Customer24.class);
    EntityType<Customer24> c_ = c.getModel();
    query.select(c).where(builder.equal(c.get(c_.getSingularAttribute("firstName")), "Vincent"));
    assertEquals(2, em.createQuery(query).getResultList().size());
  }

  @Test
  public void shouldFindCustomersOlderThan40() throws Exception {
View Full Code Here

    Root<ImageContent> imageContent = cq.from(ImageContent.class);
    cq.select(imageContent);

    ParameterExpression<String> p = cb.parameter(String.class);
    if (!(category == null || category.equals(ALL_CATEGORY))) {
      cq.where(cb.equal(imageContent.get("category"), p));
    }
    cq.orderBy(cb.desc(imageContent.get("createAt")));

    TypedQuery<ImageContent> query = em.createQuery(cq);
    query.setParameter(p, category);
View Full Code Here

    CriteriaQuery<Invoice> critQuery = critBuilder.createQuery(Invoice.class);

    // select-clause
    Root<Invoice> root = critQuery.from(Invoice.class);
    critQuery.select(root)
        .where(critBuilder.equal(root.get(Invoice_.year), year))
        .orderBy(critBuilder.desc(root.get(Invoice_.number)));
   
    TypedQuery<Invoice> query = em.createQuery(critQuery).setMaxResults(1);
   
    Invoice invoice = null;
View Full Code Here

      CriteriaBuilder builder = em.getCriteriaBuilder();
      CriteriaQuery<?> criteria = builder.createQuery(credentialTypeNameProp.getDeclaringClass());
      Root<?> root = criteria.from(credentialTypeNameProp.getDeclaringClass());
     
      List<Predicate> predicates = new ArrayList<Predicate>();
      predicates.add(builder.equal(root.get(credentialTypeNameProp.getName()), name));     
      criteria.where(predicates.toArray(new Predicate[predicates.size()]));

      return em.createQuery(criteria).getSingleResult();
   }
  
View Full Code Here

         CriteriaBuilder builder = em.getCriteriaBuilder();
         CriteriaQuery<?> criteria = builder.createQuery(relationshipTypeNameProp.getDeclaringClass());
         Root<?> root = criteria.from(relationshipTypeNameProp.getDeclaringClass());
        
         List<Predicate> predicates = new ArrayList<Predicate>();
         predicates.add(builder.equal(root.get(relationshipTypeNameProp.getName()), relationshipType.getName()));     
         criteria.where(predicates.toArray(new Predicate[predicates.size()]));

         return em.createQuery(criteria).getSingleResult();
      }
      else
View Full Code Here

     
      List<Predicate> predicates = new ArrayList<Predicate>();
     
      if (identityType != null)
      {
         predicates.add(builder.equal(root.get(identityTypeProp.getName()),
               lookupIdentityType(identityType.getName(), em)));
      }
     
      criteria.where(predicates.toArray(new Predicate[predicates.size()]));
     
View Full Code Here

     
      Property<?> identityToProperty = modelProperties.get(PROPERTY_RELATIONSHIP_TO);
      Property<?> relationshipNameProperty = modelProperties.get(PROPERTY_RELATIONSHIP_NAME);
     
      List<Predicate> predicates = new ArrayList<Predicate>();
      predicates.add(builder.equal(root.get(identityToProperty.getName()),
            lookupIdentity(identity, em)));
     
      criteria.where(predicates.toArray(new Predicate[predicates.size()]));
     
      List<?> results = em.createQuery(criteria).getResultList();
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.