Example #1
0
  @Test
  public void testPuts() {
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();

    MyTestObject object = new MyTestObject();
    object.setName("Scooby doo");
    object.setAge(100);
    Date now = new Date();
    object.setBirthday(now);
    em.persist(object);

    System.out.println(em.getTotalOpStats());
    Assert.assertEquals(1, em.getTotalOpStats().getPuts());

    object.setId(null);
    em.persist(object);
    Assert.assertEquals(2, em.getTotalOpStats().getPuts());

    em.close();

    // New EntityManager and same op
    em = (EntityManagerSimpleJPA) factory.createEntityManager();

    object = new MyTestObject();
    object.setName("Scooby doo");
    object.setAge(100);
    object.setBirthday(now);
    em.persist(object);

    System.out.println(em.getTotalOpStats());
    Assert.assertEquals(1, em.getTotalOpStats().getPuts());
    Assert.assertEquals(3, em.getGlobalOpStats().getPuts());

    em.close();
  }
Example #2
0
  @Test
  public void testLazyListRetrievalPerformance() throws InterruptedException, ExecutionException {
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();

    Query query;
    List<MyTestObject> obs;

    long start = System.currentTimeMillis();
    int numItems = 120;
    Future future = null;
    for (int i = 0; i < numItems; i++) {
      MyTestObject object = new MyTestObject();
      object.setName("Scooby doo");
      object.setAge(i);
      System.out.println("persisting " + i);
      future = em.persistAsync(object);
    }

    // let them save
    System.out.println("Waiting for all persists to complete.");
    future.get();
    long duration = System.currentTimeMillis() - start;
    printAndLog("duration of persists=" + duration);

    start = System.currentTimeMillis();
    System.out.println("querying for all objects...");
    query = em.createQuery("select o from MyTestObject o ");
    obs = query.getResultList();
    for (MyTestObject ob : obs) {
      System.out.println("ob=" + ob);
    }
    duration = System.currentTimeMillis() - start;
    printAndLog("duration of retreival and prints=" + duration);

    start = System.currentTimeMillis();
    System.out.println("querying for all objects...");
    query = em.createQuery("select o from MyTestObject o ");
    obs = query.getResultList();
    for (MyTestObject ob : obs) {
      System.out.println("ob=" + ob);
    }
    duration = System.currentTimeMillis() - start;
    printAndLog("duration of retreival and prints after first load=" + duration);

    em.close();
  }