use of org.datanucleus.samples.metadata.user.User3 in project tests by datanucleus.
the class BasicTest method testUseOfObjectIdClass.
public void testUseOfObjectIdClass() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
User1 u1 = new User1();
u1.setId("u1");
u1.setName("user1");
UserGroup1 ug1 = new UserGroup1();
ug1.setId("ug1");
ug1.setName("userg1");
ug1.setUserGroupName("usergn1");
pm.makePersistent(ug1);
pm.makePersistent(u1);
User2 u2 = new User2();
u2.setId("u2");
u2.setName("user2");
UserGroup2 ug2 = new UserGroup2();
ug2.setId("ug2");
ug2.setName("userg2");
ug2.setUserGroupName("usergn2");
pm.makePersistent(ug2);
pm.makePersistent(u2);
User3 u3 = new User3();
u3.setId("u3");
u3.setName("user3");
UserGroup3 ug3 = new UserGroup3();
ug3.setId("ug3");
ug3.setName("userg3");
ug3.setUserGroupName("usergn3");
pm.makePersistent(ug3);
pm.makePersistent(u3);
tx.commit();
tx.begin();
u1 = (User1) pm.getObjectById(new UserId1("u1"), true);
assertTrue(u1.getName().equals("user1"));
ug1 = (UserGroup1) pm.getObjectById(new UserId1("ug1"), true);
assertTrue(ug1.getName().equals("userg1"));
u2 = (User2) pm.getObjectById(new UserId2("u2"), true);
assertTrue(u2.getName().equals("user2"));
ug2 = (UserGroup2) pm.getObjectById(new UserId2("ug2"), true);
assertTrue(ug2.getName().equals("userg2"));
u3 = (User3) pm.getObjectById(new UserId3("u3"), true);
assertTrue(u3.getName().equals("user3"));
ug3 = (UserGroup3) pm.getObjectById(new UserId3("ug3"), true);
assertTrue(ug3.getName().equals("userg3"));
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(UserGroup1.class);
clean(UserGroup2.class);
clean(UserGroup3.class);
clean(User1.class);
clean(User2.class);
clean(User3.class);
}
}
Aggregations