use of org.datanucleus.samples.annotations.array.ArrayHolder in project tests by datanucleus.
the class ArrayTest method testArrayOfLongViaJoin.
public void testArrayOfLongViaJoin() {
try {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
ArrayHolder h1 = new ArrayHolder(1);
long[] longs = new long[] { 123, 6789, 25000 };
h1.setLongArray(longs);
em.persist(h1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
emf.getCache().evictAll();
em = emf.createEntityManager();
tx = em.getTransaction();
try {
tx.begin();
ArrayHolder h1 = em.find(ArrayHolder.class, 1);
assertNotNull(h1);
long[] longs = h1.getLongArray();
assertNotNull(longs);
assertEquals(3, longs.length);
assertEquals(123, longs[0]);
assertEquals(6789, longs[1]);
assertEquals(25000, longs[2]);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(ArrayHolder.class);
}
}
use of org.datanucleus.samples.annotations.array.ArrayHolder in project tests by datanucleus.
the class ArrayTest method testArrayOfPersistablesViaJoin.
public void testArrayOfPersistablesViaJoin() {
try {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
ArrayHolder h1 = new ArrayHolder(1);
Permission p1 = new Permission(101, "Admin");
Permission p2 = new Permission(102, "Developer");
Permission[] perms = new Permission[] { p1, p2 };
h1.setPermissions(perms);
em.persist(h1);
em.persist(p1);
em.persist(p2);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
emf.getCache().evictAll();
em = emf.createEntityManager();
tx = em.getTransaction();
try {
tx.begin();
ArrayHolder h1 = em.find(ArrayHolder.class, 1);
assertNotNull(h1);
Permission[] perms = h1.getPermissions();
assertNotNull(perms);
assertEquals(2, perms.length);
assertEquals(101, perms[0].getId());
assertEquals(102, perms[1].getId());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(ArrayHolder.class);
clean(Permission.class);
}
}
use of org.datanucleus.samples.annotations.array.ArrayHolder in project tests by datanucleus.
the class ArrayTest method testArrayOfIntViaLob.
public void testArrayOfIntViaLob() {
try {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
ArrayHolder h1 = new ArrayHolder(1);
int[] ints = new int[] { 123, 6789, 25000 };
h1.setIntArray(ints);
em.persist(h1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
emf.getCache().evictAll();
em = emf.createEntityManager();
tx = em.getTransaction();
try {
tx.begin();
ArrayHolder h1 = em.find(ArrayHolder.class, 1);
assertNotNull(h1);
int[] ints = h1.getIntArray();
assertNotNull(ints);
assertEquals(3, ints.length);
assertEquals(123, ints[0]);
assertEquals(6789, ints[1]);
assertEquals(25000, ints[2]);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(ArrayHolder.class);
}
}
Aggregations