use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class RawTest method testUpdateRawAndLongRaw.
/**
* Creates ZZ_TEST_PART_PICTURE records having raw and longraw elements.
* It then retrieves and updates the rows. Finally it checks if the data has been updated.
*/
public void testUpdateRawAndLongRaw() {
try {
// create 3 records
PartPicture partPicture = null;
partPicture = (PartPicture) m_uow.newPersistentInstance(PartPicture.class);
partPicture.updatePart("Z-TESTPART-01");
partPicture.updateSmallPicture("Z-TESTSMALLPICTURE-01".getBytes());
partPicture.updatePicture((LONG_FIELD + "01").getBytes());
m_uow.add(partPicture);
partPicture = (PartPicture) m_uow.newPersistentInstance(PartPicture.class);
partPicture.updatePart("Z-TESTPART-02");
partPicture.updateSmallPicture("Z-TESTSMALLPICTURE-02".getBytes());
partPicture.updatePicture((LONG_FIELD + "02").getBytes());
m_uow.add(partPicture);
partPicture = (PartPicture) m_uow.newPersistentInstance(PartPicture.class);
partPicture.updatePart("Z-TESTPART-03");
partPicture.updateSmallPicture("Z-TESTSMALLPICTURE-03".getBytes());
partPicture.updatePicture((LONG_FIELD + "03").getBytes());
m_uow.add(partPicture);
m_uow.commit();
// now check if they have been added
m_uow = new UOW();
Criteria c = new Criteria();
c.setTable(PartPictureMeta.getName());
c.addCriteria(PartPictureMeta.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z");
c.addOrderBy(PartPictureMeta.PART, Criteria.ORDER_BY_ASC);
Collection col = m_uow.query(c);
// fetch in all the records
for (Iterator i = col.iterator(); i.hasNext(); ) i.next();
assertEquals(3, col.size());
PartPicture[] partPictures = (PartPicture[]) col.toArray(new PartPicture[0]);
assertEquals("Z-TESTPART-01", partPictures[0].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-01".getBytes(), partPictures[0].getSmallPicture()));
assertTrue(Arrays.equals((LONG_FIELD + "01").getBytes(), partPictures[0].getPicture()));
assertEquals("Z-TESTPART-02", partPictures[1].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-02".getBytes(), partPictures[1].getSmallPicture()));
assertTrue(Arrays.equals((LONG_FIELD + "02").getBytes(), partPictures[1].getPicture()));
assertEquals("Z-TESTPART-03", partPictures[2].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-03".getBytes(), partPictures[2].getSmallPicture()));
assertTrue(Arrays.equals((LONG_FIELD + "03").getBytes(), partPictures[2].getPicture()));
// now update the records
partPictures[0].updateSmallPicture(null);
partPictures[0].updatePicture(null);
partPictures[1].updateSmallPicture("Z-TESTSMALLPICTURE-022".getBytes());
partPictures[1].updatePicture("Z-TESTPICTURE-022".getBytes());
m_uow.update(partPictures[0]);
m_uow.update(partPictures[1]);
m_uow.commit();
// now check if the updates were successful
m_uow = new UOW();
c = new Criteria();
c.setTable(PartPictureMeta.getName());
c.addCriteria(PartPictureMeta.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z");
c.addOrderBy(PartPictureMeta.PART, Criteria.ORDER_BY_ASC);
col = m_uow.query(c);
// fetch in all the records
for (Iterator i = col.iterator(); i.hasNext(); ) i.next();
assertEquals(3, col.size());
partPictures = (PartPicture[]) col.toArray(new PartPicture[0]);
assertEquals("Z-TESTPART-01", partPictures[0].getPart());
assertNull(partPictures[0].getSmallPicture());
assertNull(partPictures[0].getPicture());
assertEquals("Z-TESTPART-02", partPictures[1].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-022".getBytes(), partPictures[1].getSmallPicture()));
assertTrue(Arrays.equals("Z-TESTPICTURE-022".getBytes(), partPictures[1].getPicture()));
assertEquals("Z-TESTPART-03", partPictures[2].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-03".getBytes(), partPictures[2].getSmallPicture()));
assertTrue(Arrays.equals((LONG_FIELD + "03").getBytes(), partPictures[2].getPicture()));
// now delete the records
m_uow.delete(partPictures[0]);
m_uow.delete(partPictures[1]);
m_uow.delete(partPictures[2]);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class RawTest method testUpdateRawAndLongRawUsingProxy.
/**
* Creates ZZ_TEST_PART_PICTURE records having raw and longraw elements.
* It then retrieves and updates the rows. Finally it checks if the data has been updated.
*/
public void testUpdateRawAndLongRawUsingProxy() {
try {
// create 3 records
IPartPicture partPicture = null;
partPicture = (IPartPicture) m_uow.newPersistentInstance(IPartPicture.class);
partPicture.setPart("Z-TESTPART-01");
partPicture.setSmallPicture("Z-TESTSMALLPICTURE-01".getBytes());
partPicture.setPicture((LONG_FIELD + "01").getBytes());
m_uow.add(partPicture);
partPicture = (IPartPicture) m_uow.newPersistentInstance(IPartPicture.class);
partPicture.setPart("Z-TESTPART-02");
partPicture.setSmallPicture("Z-TESTSMALLPICTURE-02".getBytes());
partPicture.setPicture((LONG_FIELD + "02").getBytes());
m_uow.add(partPicture);
partPicture = (IPartPicture) m_uow.newPersistentInstance(IPartPicture.class);
partPicture.setPart("Z-TESTPART-03");
partPicture.setSmallPicture("Z-TESTSMALLPICTURE-03".getBytes());
partPicture.setPicture((LONG_FIELD + "03").getBytes());
m_uow.add(partPicture);
m_uow.commit();
// now check if they have been added
m_uow = new UOW();
Criteria c = new Criteria();
c.setTable(IPartPicture.class.getName());
c.addCriteria(IPartPicture.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z");
c.addOrderBy(IPartPicture.PART, Criteria.ORDER_BY_ASC);
Collection col = m_uow.query(c);
// fetch in all the records
for (Iterator i = col.iterator(); i.hasNext(); ) i.next();
assertEquals(3, col.size());
IPartPicture[] partPictures = (IPartPicture[]) col.toArray(new IPartPicture[0]);
assertEquals("Z-TESTPART-01", partPictures[0].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-01".getBytes(), partPictures[0].getSmallPicture()));
assertTrue(Arrays.equals((LONG_FIELD + "01").getBytes(), partPictures[0].getPicture()));
assertEquals("Z-TESTPART-02", partPictures[1].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-02".getBytes(), partPictures[1].getSmallPicture()));
assertTrue(Arrays.equals((LONG_FIELD + "02").getBytes(), partPictures[1].getPicture()));
assertEquals("Z-TESTPART-03", partPictures[2].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-03".getBytes(), partPictures[2].getSmallPicture()));
assertTrue(Arrays.equals((LONG_FIELD + "03").getBytes(), partPictures[2].getPicture()));
// now update the records
partPictures[0].setSmallPicture(null);
partPictures[0].setPicture(null);
partPictures[1].setSmallPicture("Z-TESTSMALLPICTURE-022".getBytes());
partPictures[1].setPicture("Z-TESTPICTURE-022".getBytes());
m_uow.update(partPictures[0]);
m_uow.update(partPictures[1]);
m_uow.commit();
// now check if the updates were successful
m_uow = new UOW();
c = new Criteria();
c.setTable(IPartPicture.class.getName());
c.addCriteria(IPartPicture.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z");
c.addOrderBy(IPartPicture.PART, Criteria.ORDER_BY_ASC);
col = m_uow.query(c);
// fetch in all the records
for (Iterator i = col.iterator(); i.hasNext(); ) i.next();
assertEquals(3, col.size());
partPictures = (IPartPicture[]) col.toArray(new IPartPicture[0]);
assertEquals("Z-TESTPART-01", partPictures[0].getPart());
assertNull(partPictures[0].getSmallPicture());
assertNull(partPictures[0].getPicture());
assertEquals("Z-TESTPART-02", partPictures[1].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-022".getBytes(), partPictures[1].getSmallPicture()));
assertTrue(Arrays.equals("Z-TESTPICTURE-022".getBytes(), partPictures[1].getPicture()));
assertEquals("Z-TESTPART-03", partPictures[2].getPart());
assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-03".getBytes(), partPictures[2].getSmallPicture()));
assertTrue(Arrays.equals((LONG_FIELD + "03").getBytes(), partPictures[2].getPicture()));
// now delete the records
m_uow.delete(partPictures[0]);
m_uow.delete(partPictures[1]);
m_uow.delete(partPictures[2]);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class SpecialAddUpdateDeleteTest method createItem.
/**
* Inserts a record into Item using add() and addSpecial() methods.
* The receivedItemId field, which is set in the preAdd() method of Item, should get stamped during the add() invocation only.
*/
private void createItem(boolean useSpecial) {
try {
String itemId = "Z-TESTITEM-04";
if (m_uow == null || !m_uow.isActive())
m_uow = new UOW();
// Create an item using the add() or addSpecial() methods
Item obj = (Item) m_uow.newPersistentInstance(Item.class);
obj.setItemId(itemId);
if (!useSpecial)
m_uow.add(obj);
else
m_uow.addSpecial(obj);
m_uow.commit();
// Now retrieve the added record & check if the receivedItemId got stamped for the add() case only
m_uow = new UOW();
obj = Item.findByPK(m_uow, itemId);
if (!useSpecial)
assertEquals("ADD" + itemId, obj.getReceivedItemId());
else
assertNull("The preAdd trigger should not have been fired in the special case", obj.getReceivedItemId());
// Now delete the object
m_uow.delete(obj);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class SpecialAddUpdateDeleteTest method updateItem.
/**
* Creates an Item record and updates it using the update() and updateSpecial() methods.
* The receivedItemId field, which is set in the preUpdate() method of Item, should get stamped during the update() invocation only.
*/
private void updateItem(boolean useSpecial) {
try {
String itemId = "Z-TESTITEM-04";
if (m_uow == null || !m_uow.isActive())
m_uow = new UOW();
// Create an item
Item obj = (Item) m_uow.newPersistentInstance(Item.class);
obj.setItemId(itemId);
m_uow.add(obj);
m_uow.commit();
// update the item using update() or updateSpecial() methods
m_uow = new UOW();
if (!useSpecial) {
// retrieve the item, and update it
obj = Item.findByPK(m_uow, itemId);
obj.setReceivedItemId(null);
m_uow.update(obj);
} else {
// the updateSpecial should work well on both retrieved or 'new' objects
obj = (Item) m_uow.newPersistentInstance(Item.class);
obj.setItemId(itemId);
obj.setReceivedItemId(null);
m_uow.updateSpecial(obj);
}
m_uow.commit();
// Now retrieve the updated record & check if the receivedItemId got stamped for the update() case only
m_uow = new UOW();
obj = Item.findByPK(m_uow, itemId);
if (!useSpecial)
assertEquals("UPD" + itemId, obj.getReceivedItemId());
else
assertNull("The preUpdate trigger should not have been fired in the special case", obj.getReceivedItemId());
// Now delete the object
m_uow.delete(obj);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class SpecialAddUpdateDeleteTest method deleteItem.
/**
* Creates an Item record and deletes it using the delete() and deleteSpecial() methods.
* The receivedItemId field, which is set in the preDelete() method of Item, should get stamped during the delete() invocation only.
*/
private void deleteItem(boolean useSpecial) {
try {
String itemId = "Z-TESTITEM-04";
if (m_uow == null || !m_uow.isActive())
m_uow = new UOW();
// Create an item
Item obj = (Item) m_uow.newPersistentInstance(Item.class);
obj.setItemId(itemId);
m_uow.add(obj);
m_uow.commit();
// delete the item using delete() or deleteSpecial() methods
m_uow = new UOW();
if (!useSpecial) {
// retrieve the item, and delete it
obj = Item.findByPK(m_uow, itemId);
obj.setReceivedItemId(null);
m_uow.delete(obj);
} else {
// the deleteSpecial should work well on both retrieved or 'new' objects
obj = (Item) m_uow.newPersistentInstance(Item.class);
obj.setItemId(itemId);
obj.setReceivedItemId(null);
m_uow.deleteSpecial(obj);
}
m_uow.commit();
// Check if the receivedItemId got stamped for the update() case only
if (!useSpecial)
assertEquals("DEL" + itemId, obj.getReceivedItemId());
else
assertNull("The preDelete trigger should not have been fired in the special case", obj.getReceivedItemId());
// Ensure that the object has been deleted
m_uow = new UOW();
obj = Item.findByPK(m_uow, itemId);
assertNull("The item record should have been deleted", obj);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations