use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class CharFieldTest method testNotNullQuery.
/**
* Tests the sql:
* Select * from zz_jut_part_additional where field1 is not null and field1 != ' '
* This should return 1 record
*/
public void testNotNullQuery() {
UOW uow = null;
try {
uow = new UOW();
// Create a new object
PartAdditional object = (PartAdditional) uow.newPersistentInstance(PartAdditional.class);
object.setPart(PART);
// enter at least a blank string, since the field is mandatory
object.setField1(" ");
object.setField2("A VALUE");
uow.add(object);
uow.commit();
// Retrieve records where field2 is not null. Should get 1 record
uow = new UOW();
Criteria c = new Criteria();
c.setTable(PartAdditionalMeta.getName());
c.addCriteria(PartAdditionalMeta.FIELD2, Criteria.RELATIONAL_IS_NOT_NULL);
Collection col = uow.query(c);
assertEquals("One record should have been retrieved", 1, col.size());
object = (PartAdditional) col.iterator().next();
assertEquals(PART, object.getPart());
assertNull(object.getField1());
assertEquals("A VALUE", object.getField2());
assertNull(object.getField3());
// Retrieve records where field1 is not null. Nothing should be retrieved
uow = new UOW();
c = new Criteria();
c.setTable(PartAdditionalMeta.getName());
c.addCriteria(PartAdditionalMeta.FIELD1, Criteria.RELATIONAL_IS_NOT_NULL);
col = uow.query(c);
assertEquals("No record should have been retrieved", 0, col.size());
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
try {
if (uow != null)
uow.rollback();
} catch (Exception e) {
// do nothing
}
cleanupData(PART);
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class DeleteTest method testCheckRollbackAfterDelete.
/**
* Deletes a record from SYCD using the following query:
* delete from sycd WHERE condition='Z-TESTSYCD-03'
* It then does a rollback. This is followed by a commit.
* The test fails if the record is deleted.
*/
public void testCheckRollbackAfterDelete() {
try {
Criteria c = new Criteria();
c.setTable(ConditionMeta.getName());
c.addCriteria(ConditionMeta.CONDITION, "Z-TESTSYCD-03");
Iterator i = m_uow.query(c).iterator();
Condition sycd = (Condition) i.next();
m_uow.delete(sycd);
m_uow.rollback();
// Now ensure the record isn't deleted
m_uow = new UOW();
c = new Criteria();
c.setTable(ConditionMeta.getName());
c.addCriteria(ConditionMeta.CONDITION, "Z-TESTSYCD-03");
i = m_uow.query(c).iterator();
if (!i.hasNext())
fail("Record has been deleted even after a rollback");
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class DeleteTest method testCheckRollbackAfterDeleteUsingProxy.
/**
* Deletes a record from SYCD using the following query:
* delete from sycd WHERE condition='Z-TESTSYCD-03'
* It then does a rollback. This is followed by a commit.
* The test fails if the record is deleted.
*/
public void testCheckRollbackAfterDeleteUsingProxy() {
try {
Criteria c = new Criteria();
c.setTable(ICondition.class.getName());
c.addCriteria(ICondition.CONDITION, "Z-TESTSYCD-03");
Iterator i = m_uow.query(c).iterator();
ICondition sycd = (ICondition) i.next();
m_uow.delete(sycd);
m_uow.rollback();
// Now ensure the record isn't deleted
m_uow = new UOW();
c = new Criteria();
c.setTable(ICondition.class.getName());
c.addCriteria(ICondition.CONDITION, "Z-TESTSYCD-03");
i = m_uow.query(c).iterator();
if (!i.hasNext())
fail("Record has been deleted even after a rollback");
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class DeleteTest method testDeleteCondition.
/**
* Executes the following query:
* delete from sycd WHERE condition='Z-TESTSYCD-02'
* It then ensures that the record was got deleted.
*/
public void testDeleteCondition() {
try {
Criteria c = new Criteria();
c.setTable(ConditionMeta.getName());
c.addCriteria(ConditionMeta.CONDITION, "Z-TESTSYCD-02");
Iterator i = m_uow.query(c).iterator();
Condition sycd = (Condition) i.next();
String description = sycd.getDescription();
m_uow.delete(sycd);
m_uow.commit();
// Now ensure that the record got deleted
m_uow = new UOW();
c = new Criteria();
c.setTable(ConditionMeta.getName());
c.addCriteria(ConditionMeta.CONDITION, "Z-TESTSYCD-02");
i = m_uow.query(c).iterator();
if (i.hasNext())
fail();
// Finally, recreate the record
m_uow = new UOW();
sycd = (Condition) m_uow.newPersistentInstance(Condition.class);
sycd.setCondition("Z-TESTSYCD-02");
sycd.setDescription(description);
m_uow.add(sycd);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class FunctionTest method testMax.
/**
* Tests the max() function
* select max(CREATED_DATETIME) from item;
*/
public void testMax() {
try {
Criteria c = new Criteria();
c.setTable(ItemMeta.getName());
c.addFunction(Criteria.FUNCTION_MAX, ItemMeta.CREATED_DATETIME, "max");
Map m = (Map) m_uow.query(c).iterator().next();
assertEquals("max(CREATED_DATETIME)", new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0), m.get("max"));
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations