Package org.apache.cayenne.jpa.itest.ch5.entity

Examples of org.apache.cayenne.jpa.itest.ch5.entity.SimpleEntity


        Query query = em.createQuery("SELECT a FROM SimpleEntity a ORDER BY a.property1");
        query.setMaxResults(2);
       
        List<?> results = query.getResultList();
        assertEquals(2, results.size());
        SimpleEntity e1 = (SimpleEntity) results.get(0);
        SimpleEntity e2 = (SimpleEntity) results.get(1);
        assertEquals("A", e1.getProperty1());
        assertEquals("B", e2.getProperty1());
    }
View Full Code Here


        Query query = em.createQuery("SELECT a FROM SimpleEntity a ORDER BY a.property1");
        query.setFirstResult(2);
       
        List<?> results = query.getResultList();
        assertEquals(2, results.size());
        SimpleEntity e1 = (SimpleEntity) results.get(0);
        SimpleEntity e2 = (SimpleEntity) results.get(1);
        assertEquals("C", e1.getProperty1());
        assertEquals("D", e2.getProperty1());
    }
View Full Code Here

        query.setFirstResult(1);
        query.setMaxResults(1);
       
        List<?> results = query.getResultList();
        assertEquals(1, results.size());
        SimpleEntity e1 = (SimpleEntity) results.get(0);
        assertEquals("B", e1.getProperty1());
    }
View Full Code Here

public class _3_1_1_EntityManagerTest extends EntityManagerCase {

    public void testPersist() throws Exception {
        getDbHelper().deleteAll("SimpleEntity");

        SimpleEntity e = new SimpleEntity();
        e.setProperty1("XXX");
        getEntityManager().persist(e);
        getEntityManager().getTransaction().commit();

        assertEquals(1, getDbHelper().getRowCount("SimpleEntity"));
    }
View Full Code Here

            // expected
        }
    }

    public void testPersistEntityExistsException() {
        SimpleEntity e1 = new SimpleEntity();
        e1.updateIdField(3);

        SimpleEntity e2 = new SimpleEntity();
        e2.updateIdField(3);

        getEntityManager().persist(e1);

        try {
            getEntityManager().persist(e2);
View Full Code Here

                "id", "property1"
        }, new Object[] {
                1, "XXX"
        });

        SimpleEntity e1 = new SimpleEntity();
        e1.setProperty1("YYY");
        e1.updateIdField(1);

        // detailed merge logic is described in chapter 3.2.4.1
        Object merged = getEntityManager().merge(e1);
        assertNotNull(merged);
        assertTrue(merged instanceof SimpleEntity);

        SimpleEntity e2 = (SimpleEntity) merged;

        assertEquals("YYY", e2.getProperty1());

        getEntityManager().getTransaction().commit();
        assertEquals(1, getDbHelper().getRowCount("SimpleEntity"));
        assertEquals("YYY", getDbHelper().getObject("SimpleEntity", "property1"));
    }
View Full Code Here

                "id", "property1"
        }, new Object[] {
                1, "XXX"
        });

        SimpleEntity e1 = (SimpleEntity) getEntityManager().find(SimpleEntity.class, 1);
        assertNotNull(e1);
        getEntityManager().remove(e1);

        try {
            getEntityManager().merge(e1);
View Full Code Here

                "id", "property1"
        }, new Object[] {
                1, "XXX"
        });

        SimpleEntity e1 = (SimpleEntity) getEntityManager().find(SimpleEntity.class, 1);
        assertNotNull(e1);
        getEntityManager().remove(e1);
        getEntityManager().getTransaction().commit();

        assertEquals(0, getDbHelper().getRowCount("SimpleEntity"));
View Full Code Here

        }
    }

    public void testRemoveDetachedEntity() throws Exception {
        try {
            getEntityManager().remove(new SimpleEntity());
            fail("Must have thrown IllegalArgumentException on detached entity");
        }
        catch (IllegalArgumentException e) {
            // expected
        }
View Full Code Here

            // Per spec, The EntityTransaction instance may be used serially to
            // begin and commit multiple transactions

            tx.begin();
            SimpleEntity e1 = new SimpleEntity();
            e1.setProperty1("X");
            entityManager.persist(e1);
            tx.commit();

            tx.begin();
            SimpleEntity e2 = new SimpleEntity();
            e2.setProperty1("Y");
            entityManager.persist(e2);
            tx.commit();
        }
        finally {
            entityManager.close();
View Full Code Here

TOP

Related Classes of org.apache.cayenne.jpa.itest.ch5.entity.SimpleEntity

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.