Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.OpenJPAEntityManager.createQuery()


        em = (OpenJPAEntityManager) factory.createEntityManager();
        OpenJPAQuery q;
        Collection c;
        try {
            q = em.createQuery("select a FROM "
                + CacheObjectE.class.getSimpleName()
                + " a where a.str = 'e'");
            c = new ArrayList((Collection) q.getResultList());
            assertEquals(1, c.size());
            q.closeAll();
View Full Code Here


            endEm(em);
        }

        try {
            em = (OpenJPAEntityManager) factory.createEntityManager();
            q = em.createQuery("select a FROM "
                + CacheObjectE.class.getSimpleName()
                + " a where a.str = 'e'");
            q.setCandidateCollection(new ArrayList(0));
            c = (Collection) q.getResultList();
            assertEquals(0, c.size());
View Full Code Here

        startTx(em);
        OpenJPAQuery q;
        Collection c;
        try {

            q = em.createQuery(
                "select a FROM " + CacheObjectA.class.getSimpleName()
                    + " a where a.name = :pName").setParameter("pName",
                ORIG_NAME);

            c = new ArrayList((Collection) q.getResultList());
View Full Code Here

    /**
         * Verify that if A refers to B then A must be a member of the set
     * referred by B
     */
    em.getTransaction().begin();
        List<Translation> result = em.createQuery("SELECT p FROM Translation p")
      .getResultList();
    assertTrue(!result.isEmpty());
    for (Translation translation : result) {
      assertTrue(translation.getTranslatable()
                    .getTranslations().contains(translation));
View Full Code Here

  /**
     * Count the number of instances in the given class by aggregate JPQL query.
   */
  public int count(Class c) {
    OpenJPAEntityManager em = emf.createEntityManager();
    Number n = ((Number) em.createQuery("SELECT COUNT(p) FROM " +
                c.getSimpleName() + " p").getSingleResult()).intValue();
    closeEM(em);
    return n.intValue();
  }
 
View Full Code Here

    public void testEntityTypeForTablePerClassInheritance() {
        populate();
        OpenJPAEntityManager em = emf.createEntityManager();
        String query = "select tr from Translatable tr join tr.translations t where " +
                "TYPE(tr) = EnglishParagraph";
        List rs = em.createQuery(query).getResultList();
        assertEquals(2, rs.size());
        for (int i=0; i < rs.size(); i++)
            assertTrue(rs.get(i) instanceof EnglishParagraph);
       
        query = "select distinct tr from Translatable tr join tr.translations t where " +
View Full Code Here

        for (int i=0; i < rs.size(); i++)
            assertTrue(rs.get(i) instanceof EnglishParagraph);
       
        query = "select distinct tr from Translatable tr join tr.translations t where " +
            "TYPE(tr) = EnglishParagraph or TYPE(tr) = FrenchParagraph";
        rs = em.createQuery(query).getResultList();
        assertEquals(2, rs.size());
        for (int i=0; i < rs.size(); i++)
            assertTrue(!(rs.get(i) instanceof GermanParagraph));
       
        query = "select distinct tr from Translatable tr join tr.translations t where " +
View Full Code Here

            assertTrue(!(rs.get(i) instanceof GermanParagraph));
       
        query = "select distinct tr from Translatable tr join tr.translations t where " +
            "TYPE(tr) in (?1, ?2)";
        try {
            rs = em.createQuery(query).setParameter(1, EnglishParagraph.class).
            setParameter(2, FrenchParagraph.class).getResultList();
        } catch(ArgumentException e) {
            // as expected
            //System.out.println(e.getMessage());
        }
View Full Code Here

        }
       
        query = "select tr from Translatable tr join tr.translations t where " +
            "TYPE(tr) <> EnglishParagraph";
        try {
            rs = em.createQuery(query).getResultList();
        } catch(ArgumentException e) {
            // as expected
            //System.out.println(e.getMessage());
        }
View Full Code Here

            //System.out.println(e.getMessage());
        }

        String query1 = "select t from Translation t where TYPE(t.translatable) = EnglishParagraph";
        try {
            rs = em.createQuery(query1).getResultList();
        } catch(ArgumentException e) {
            // as expected
            //System.out.println(e.getMessage());
        }
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.