Esempio n. 1
0
  // Test multi-valued properties and custom keys
  public void testMultiValued() throws Exception {
    EntityManager em;

    TestViewpoint viewpoint = new TestViewpoint(Guid.createNew());

    /////////////////////////////////////////////////
    // Setup

    em = support.beginSessionRW(viewpoint);

    TestUser bob = new TestUser("Bob");
    Guid bobId = bob.getGuid();
    em.persist(bob);

    TestUser jane = new TestUser("Jane");
    Guid janeId = jane.getGuid();
    em.persist(jane);

    TestGroup group = new TestGroup("BobAndJane");
    Guid groupId = group.getGuid();
    em.persist(group);

    TestGroupMember groupMember;

    groupMember = new TestGroupMember(group, bob);
    em.persist(groupMember);
    group.getMembers().add(groupMember);

    groupMember = new TestGroupMember(group, jane);
    em.persist(groupMember);
    group.getMembers().add(groupMember);

    em.getTransaction().commit();

    /////////////////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    // Check that the group looks OK read as DMO's from a new transaction.
    logger.debug("===== Checking the group in a new transaction ====\n");
    checkGroupValidity(groupId, bobId, janeId);

    // Check again with everything cached in the sesssion
    logger.debug("===== Checking the group again in the same transaction ====\n");
    checkGroupValidity(groupId, bobId, janeId);

    em.getTransaction().commit();

    em = support.beginSessionRO(viewpoint);

    // Now check once again in another new transaction to test reading
    // back from the global cache
    logger.debug("===== Checking the group again in a different new transaction ====\n");
    checkGroupValidity(groupId, bobId, janeId);

    em.getTransaction().commit();
  }
Esempio n. 2
0
  // Test whether properties can be retrieved from the session and global caches
  public void testCaching() throws NotFoundException {
    TestGroup group;
    TestGroupDMO groupDMO;
    EntityManager em;
    ReadOnlySession session;
    Guid guid;
    TestViewpoint viewpoint = new TestViewpoint(Guid.createNew());

    em = support.beginSessionRW(viewpoint);

    group = new TestGroup("Hippos");
    guid = group.getGuid();
    em.persist(group);

    em.getTransaction().commit();

    //////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    session = support.currentSessionRO();

    // First time stores in session-local and global caches
    groupDMO = session.find(TestGroupDMO.class, guid);
    assertTrue(groupDMO != null);
    assertTrue(groupDMO.getKey().equals(guid));
    assertTrue(groupDMO.getName().equals("Hippos"));

    // Second time within session finds the existing DMO in
    // the session-local cache. The property value is cached
    // in the DMO.
    groupDMO = session.find(TestGroupDMO.class, guid);
    assertTrue(groupDMO != null);
    assertTrue(groupDMO.getKey().equals(guid));
    assertTrue(groupDMO.getName().equals("Hippos"));

    em.getTransaction().commit();

    //////////////////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    session = support.currentSessionRO();

    // Creates a new GroupDMO. The property value will be found
    // from the global cache
    groupDMO = session.find(TestGroupDMO.class, guid);
    assertTrue(groupDMO != null);
    assertTrue(groupDMO.getKey().equals(guid));
    assertTrue(groupDMO.getName().equals("Hippos"));

    em.getTransaction().commit();
  }
Esempio n. 3
0
  // Test looking up objects by String resource ID
  public void testStringResourceId() throws NotFoundException {
    EntityManager em;

    TestViewpoint viewpoint = new TestViewpoint(Guid.createNew());

    /////////////////////////////////////////////////
    // Setup

    em = support.beginSessionRW(viewpoint);

    TestUser bob = new TestUser("Bob");
    em.persist(bob);

    TestGroup group = new TestGroup("BobOnly");
    Guid groupId = group.getGuid();
    em.persist(group);

    TestGroupMember groupMember;

    groupMember = new TestGroupMember(group, bob);
    em.persist(groupMember);
    group.getMembers().add(groupMember);

    em.getTransaction().commit();

    /////////////////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    ReadOnlySession session = support.currentSessionRO();

    // Test for a GUID key
    TestGroupDMO groupDMO = session.find(TestGroupDMO.class, groupId);
    assertEquals(groupDMO, session.find(groupDMO.getResourceId()));

    // Test for a custom key
    TestGroupMemberDMO groupMemberDMO = groupDMO.getMembers().get(0);
    assertEquals(groupMemberDMO, session.find(groupMemberDMO.getResourceId()));

    em.getTransaction().commit();
  }