Пример #1
0
 public static TypedQuery<Pet> findPetsByOwner(Owner owner) {
   if (owner == null) throw new IllegalArgumentException("The owner argument is required");
   EntityManager em = Pet.entityManager();
   TypedQuery<Pet> q = em.createQuery("SELECT o FROM Pet AS o WHERE o.owner = :owner", Pet.class);
   q.setParameter("owner", owner);
   return q;
 }
Пример #2
0
 public static TypedQuery<Pet> findPetsBySendRemindersAndWeightLessThan(
     boolean sendReminders, Float weight) {
   if (weight == null) throw new IllegalArgumentException("The weight argument is required");
   EntityManager em = Pet.entityManager();
   TypedQuery<Pet> q =
       em.createQuery(
           "SELECT o FROM Pet AS o WHERE o.sendReminders = :sendReminders AND o.weight < :weight",
           Pet.class);
   q.setParameter("sendReminders", sendReminders);
   q.setParameter("weight", weight);
   return q;
 }
Пример #3
0
 public static TypedQuery<Pet> findPetsByNameAndWeight(String name, Float weight) {
   if (name == null || name.length() == 0)
     throw new IllegalArgumentException("The name argument is required");
   if (weight == null) throw new IllegalArgumentException("The weight argument is required");
   EntityManager em = Pet.entityManager();
   TypedQuery<Pet> q =
       em.createQuery(
           "SELECT o FROM Pet AS o WHERE o.name = :name AND o.weight = :weight", Pet.class);
   q.setParameter("name", name);
   q.setParameter("weight", weight);
   return q;
 }
Пример #4
0
 public static TypedQuery<Pet> findPetsByTypeAndNameLike(PetType type, String name) {
   if (type == null) throw new IllegalArgumentException("The type argument is required");
   if (name == null || name.length() == 0)
     throw new IllegalArgumentException("The name argument is required");
   name = name.replace('*', '%');
   if (name.charAt(0) != '%') {
     name = "%" + name;
   }
   if (name.charAt(name.length() - 1) != '%') {
     name = name + "%";
   }
   EntityManager em = Pet.entityManager();
   TypedQuery<Pet> q =
       em.createQuery(
           "SELECT o FROM Pet AS o WHERE o.type = :type AND LOWER(o.name) LIKE LOWER(:name)",
           Pet.class);
   q.setParameter("type", type);
   q.setParameter("name", name);
   return q;
 }