Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaQuery


    }

    @GET
    public List<Snapshot> all() {
        CriteriaBuilder cb = this.em.getCriteriaBuilder();
        CriteriaQuery q = cb.createQuery();
        CriteriaQuery<Snapshot> select = q.select(q.from(Snapshot.class));
        return this.em.createQuery(select)
                .getResultList();

    }
View Full Code Here


    public Student findStudent(int id) {
        return em.find(Student.class, id);
    }

    public List<Student> findAllStudent() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Student.class));
        return em.createQuery(cq).getResultList();
    }
View Full Code Here

        cq.select(cq.from(Student.class));
        return em.createQuery(cq).getResultList();
    }

    public int countStudent() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<Student> rt = cq.from(Student.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    }
View Full Code Here

        }
        return result;
    }

    public List<Course> findAllCourse() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Course.class));
        return em.createQuery(cq).getResultList();
    }
View Full Code Here

    public Student findStudent(int id) {
        return em.find(Student.class, id);
    }

    public List<Student> findAllStudent() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Student.class));
        return em.createQuery(cq).getResultList();
    }
View Full Code Here

        cq.select(cq.from(Student.class));
        return em.createQuery(cq).getResultList();
    }

    public int countStudent() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<Student> rt = cq.from(Student.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    }
View Full Code Here

        }
        return result;
    }

    public List<Course> findAllCourse() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Course.class));
        return em.createQuery(cq).getResultList();
    }
View Full Code Here

        em.persist(log);
    }

    public int count() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<Log> rt = cq.from(Log.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
//        System.out.println("in LogSessionBean.java, the count res is:"+((Long) q.getSingleResult()).intValue());
       return ((Long) q.getSingleResult()).intValue();
    }
View Full Code Here

    }

    public void testEqualWithAttributeAndLiteral() {
        String jpql = "select a from Account a where a.balance=100";

        CriteriaQuery c = cb.createQuery();
        Root<Account> account = c.from(Account.class);
        c.select(account).where(cb.equal(account.get(Account_.balance), 100));

        assertEquivalence(c, jpql);
    }
View Full Code Here

                cb.isTrue(cb.disjunction())));
        em.createQuery(c).getResultList();
    }
   
    public void testDefaultProjectionWithUntypedResult() {
        CriteriaQuery cquery = cb.createQuery();
        Root<Customer> customer = cquery.from(Customer.class);

        //Get Metamodel from Root
        EntityType<Customer> Customer_ = customer.getModel();

        cquery.where(cb.equal(
                customer.get(Customer_.getSingularAttribute("name", String.class)),
                cb.nullLiteral(String.class)));

        Query q = em.createQuery(cquery);
    }
View Full Code Here

TOP

Related Classes of javax.persistence.criteria.CriteriaQuery

Copyright © 2018 www.massapicom. 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.