Examples of EntityManagerImpl


Examples of me.prettyprint.hom.EntityManagerImpl

  public static void main(String[] args) {
    Cluster cluster = HFactory.getOrCreateCluster("TestPool", "localhost:9160");
    Keyspace keyspace = HFactory.createKeyspace("TestKeyspace", cluster);

    EntityManagerImpl em = new EntityManagerImpl(keyspace, "com.mycompany");

    MyPojo pojo1 = new MyPojo();
    pojo1.setId(UUID.randomUUID());
    pojo1.setLongProp1(123L);
    pojo1.setColor(Colors.RED);

    em.save(pojo1);

    // do some stuff

    MyPojo pojo2 = em.load(MyPojo.class, pojo1.getId());

    // do some more stuff

    System.out.println( "Color = " + pojo2.getColor() );
  }
View Full Code Here

Examples of me.prettyprint.hom.EntityManagerImpl

    Cluster cluster = HFactory.getOrCreateCluster("TestPool", "localhost:9170");
    createKeyspace(cluster, "TestKeyspace", "org.apache.cassandra.locator.SimpleStrategy", 1, cfDefList);
    keyspace = HFactory.createKeyspace("TestKeyspace", cluster);

    entityMgr = new EntityManagerImpl(keyspace, "com.mycompany.furniture");
  }
View Full Code Here

Examples of me.prettyprint.hom.EntityManagerImpl

public class EntityManagerTest extends CassandraTestBase {

  @Test
  public void testInitializeSaveLoad() {
    EntityManagerImpl em = new EntityManagerImpl(keyspace, "me.prettyprint.hom.beans");
    MyTestBean o1 = new MyTestBean();
    o1.setBaseId(UUID.randomUUID());
    o1.setIntProp1(1);
    o1.setBoolProp1(Boolean.TRUE);
    o1.setLongProp1(123L);
    em.persist(o1);
    MyTestBean o2 = em.find(MyTestBean.class, o1.getBaseId());

    assertEquals(o1.getBaseId(), o2.getBaseId());
    assertEquals(o1.getIntProp1(), o2.getIntProp1());
    assertEquals(o1.isBoolProp1(), o2.isBoolProp1());
    assertEquals(o1.getLongProp1(), o2.getLongProp1());
View Full Code Here

Examples of me.prettyprint.hom.EntityManagerImpl

  }

  @Test
  @Ignore
  public void testInitializeSaveLoadCustomId() {
    EntityManagerImpl em = new EntityManagerImpl(keyspace, "me.prettyprint.hom.beans");
    MyCustomIdBean o1 = new MyCustomIdBean();
    o1.setId(Colors.GREEN);
    o1.setLongProp1(111L);
    em.save(o1);
    MyCustomIdBean o2 = em.load(MyCustomIdBean.class, Colors.GREEN);

    assertEquals(o1.getId(), o2.getId());
    assertEquals(o1.getLongProp1(), o2.getLongProp1());
  }
View Full Code Here

Examples of me.prettyprint.hom.EntityManagerImpl

    }

    @Bean
    public EntityManagerImpl entityManager(Keyspace keyspace) {
        String[] packagesToScan = {"fr.ippon.tatami.domain", "fr.ippon.tatami.bot.config"};
        return new EntityManagerImpl(keyspace, packagesToScan);
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.EntityManagerImpl

    public void setUp() {
        super.setUp(p);
    }

    public void testCacheHit() throws Exception {
        EntityManagerImpl em = (EntityManagerImpl) emf.createEntityManager();
        // Change the eager field to lazy to make testing easier.
        ClassMetaData cmd =
            em.getConfiguration().getMetaDataRepositoryInstance().getMetaData(CachedEntityStatistics.class, null, true);
        cmd.getField("eagerList").setInDefaultFetchGroup(false);
        try {
            em.getTransaction().begin();
            CachedEntityStatistics e = new CachedEntityStatistics();
            CachedEntityStatistics lazy = new CachedEntityStatistics();
            Set<CachedEntityStatistics> lazyList = new HashSet<CachedEntityStatistics>();
            lazyList.add(lazy);
            e.setLazyList(lazyList);
            em.persist(e);
            em.persist(lazy);
            em.flush();
            em.clear();

            // Should prime the cache
            em.find(CachedEntityStatistics.class, e.getId()).getLazyList();
            em.clear();
            sql.clear();

            CachedEntityStatistics c = em.find(CachedEntityStatistics.class, e.getId());
            c.getLazyList();
            assertEquals(0, sql.size());

            em.getTransaction().commit();
        } finally {
            if (em.getTransaction().isActive())
                em.getTransaction().rollback();
            em.close();
        }
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.EntityManagerImpl

    public void testRoundtrip() {
        List<String> list = new ArrayList<String>();
        list.add("xxx");
        list.add("yyy");
        ResultList resultList = new ListResultList(list);
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        em.close();
        RuntimeExceptionTranslator trans = PersistenceExceptions.getRollbackTranslator(em);
        DistinctResultList distinctResultList = new DistinctResultList(resultList, trans);
        try {
            roundtrip(distinctResultList);
        } catch (Exception e) {
View Full Code Here

Examples of org.apache.openjpa.persistence.EntityManagerImpl

    public void testRoundtrip() {
        List<String> list = new ArrayList<String>();
        list.add("xxx");
        list.add("yyy");
        ResultList resultList = new ListResultList(list);
        EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
        em.close();
        RuntimeExceptionTranslator trans = PersistenceExceptions.getRollbackTranslator(em);
        DistinctResultList distinctResultList = new DistinctResultList(resultList, trans);
        try {
            roundtrip(distinctResultList);
        } catch (Exception e) {
View Full Code Here

Examples of org.apache.openjpa.persistence.EntityManagerImpl

        props.put("openjpa.jdbc.QuerySQLCache", "true");

        OpenJPAEntityManagerFactorySPI emf1 = (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.
                                             cast(Persistence.createEntityManagerFactory("test", props));
        try {
            EntityManagerImpl em = (EntityManagerImpl)emf1.createEntityManager();
   
            em.getTransaction().begin();
   
            for (int i = 1; i < 3; i++) {
                TblParent p = new TblParent();
                p.setParentId(i);
                TblChild c = new TblChild();
                c.setChildId(i);
                c.setTblParent(p);
                p.addTblChild(c);
                em.persist(p);
                em.persist(c);
   
                TblGrandChild gc = new TblGrandChild();
                gc.setGrandChildId(i);
                gc.setTblChild(c);
                c.addTblGrandChild(gc);
   
                em.persist(p);
                em.persist(c);
                em.persist(gc);
            }
            em.flush();
            em.getTransaction().commit();
            em.clear();
   
            for (int i = 1; i < 3; i++) {
                TblParent p = em.find(TblParent.class, i);
                int pid = p.getParentId();
                assertEquals(pid, i);
                Collection<TblChild> children = p.getTblChildren();
                boolean hasChild = false;
                for (TblChild c : children) {
                    hasChild = true;
                    Collection<TblGrandChild> gchildren = c.getTblGrandChildren();
                    int cid = c.getChildId();
                    assertEquals(cid, i);
                    boolean hasGrandChild = false;
                    for (TblGrandChild gc : gchildren) {
                        hasGrandChild = true;
                        int gcId = gc.getGrandChildId();
                        assertEquals(gcId, i);
                    }
                    assertTrue(hasGrandChild);
                }
                assertTrue(hasChild);
                em.close();
            }
        } finally {
            closeEMF(emf1);
        }
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.EntityManagerImpl

   
    public void testEMConfig001() {
        Map propMap = new HashMap();
        EntityManager em = emf.createEntityManager(propMap);
       
        EntityManagerImpl eml = (EntityManagerImpl) em;
        assertTrue(eml.getQuerySQLCache());
    }
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.