use of org.jaffa.persistence.Criteria 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.Criteria 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.Criteria in project jaffa-framework by jaffa-projects.
the class StoredProcedureTest method testVoucherStoredProcedure.
/**
* This just executes the Voucher Stored Procedure. If a voucher gets generated, then everything went thru well.
* It then performs a rollback.
*/
public void testVoucherStoredProcedure() {
try {
// create a StoredProcedure Object
VoucherStoredProcedure obj = new VoucherStoredProcedure();
obj.updatePrefix("V");
obj.updateLength(new Long(15));
// create the criteria
Criteria c = new Criteria();
c.setTable(obj.getClass().getName());
c.addCriteria(null, obj);
m_uow.query(c);
// check if a voucher was generated
assertNotNull(obj.getVoucher());
m_uow.rollback();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class UpdateTest method testUpdateDecimalUsingProxy.
/**
* Executes the following query:
* update item set price=1234567890.12345 where item_id='Z-TESTITEM-01'
* It then ensures that the record was properly updated and then resets it back to the original value
*/
public void testUpdateDecimalUsingProxy() {
try {
String itemId = "Z-TESTITEM-01";
Double price = new Double(1234567890.12345);
Criteria c = new Criteria();
c.setTable(IItem.class.getName());
c.addCriteria(IItem.ITEM_ID, itemId);
Iterator i = m_uow.query(c).iterator();
IItem item = (IItem) i.next();
Double originalPrice = item.getPrice();
assertNull("The Price for Z-TESTITEM-01 should have been null", originalPrice);
item.setPrice(price);
m_uow.update(item);
m_uow.commit();
// Now ensure that the record got updated
m_uow = new UOW();
c = new Criteria();
c.setTable(IItem.class.getName());
c.addCriteria(IItem.ITEM_ID, itemId);
i = m_uow.query(c).iterator();
item = (IItem) i.next();
assertEquals(price, item.getPrice());
// Now reset to the original value
item.setPrice(originalPrice);
m_uow.update(item);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class UpdateTest method testUpdateUsingQuoteUsingProxy.
/**
* Executes the following query:
* update syci set description='JOHN'S DESC' WHERE CATEGORY_INSTRUMENT='Z-TESTCI-01'
* It then ensures that the record was properly updated and resets the description to the old value.
*/
public void testUpdateUsingQuoteUsingProxy() {
try {
String category = "Z-TESTCI-01";
String newDesc = "DE'SC WI'TH Q'UOTES'";
String oldDesc = null;
Criteria c = new Criteria();
c.setTable(ICategoryOfInstrument.class.getName());
c.addCriteria(ICategoryOfInstrument.CATEGORY_INSTRUMENT, category);
Iterator i = m_uow.query(c).iterator();
ICategoryOfInstrument syci = (ICategoryOfInstrument) i.next();
oldDesc = syci.getDescription();
syci.setDescription(newDesc);
m_uow.update(syci);
m_uow.commit();
// Now ensure that the record got updated
m_uow = new UOW();
c = new Criteria();
c.setTable(ICategoryOfInstrument.class.getName());
c.addCriteria(ICategoryOfInstrument.DESCRIPTION, newDesc);
i = m_uow.query(c).iterator();
syci = (ICategoryOfInstrument) i.next();
assertEquals(category, syci.getCategoryInstrument());
assertEquals(newDesc, syci.getDescription());
// Reset to the original value
syci.setDescription(oldDesc);
m_uow.update(syci);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations