Search in sources :

Example 1 with PartAdditional

use of org.jaffa.persistence.domainobjects.PartAdditional in project jaffa-framework by jaffa-projects.

the class CharFieldTest method testDelete.

/**
 * Deletes a new record.
 */
public void testDelete() {
    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(" ");
        uow.add(object);
        uow.commit();
        // Now ensure that the record got created
        uow = new UOW();
        object = PartAdditional.findByPK(uow, PART);
        assertNotNull("A PartAdditional object should have been created", object);
        assertEquals(PART, object.getPart());
        // Delete the bugger
        uow.delete(object);
        uow.commit();
        // Now ensure that the record got deleted
        uow = new UOW();
        object = PartAdditional.findByPK(uow, PART);
        assertNull("A PartAdditional object should have been deleted", object);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    } finally {
        try {
            if (uow != null)
                uow.rollback();
        } catch (Exception e) {
        // do nothing
        }
        cleanupData(PART);
    }
}
Also used : PartAdditional(org.jaffa.persistence.domainobjects.PartAdditional) UOW(org.jaffa.persistence.UOW)

Example 2 with PartAdditional

use of org.jaffa.persistence.domainobjects.PartAdditional in project jaffa-framework by jaffa-projects.

the class CharFieldTest method testUpdate.

/**
 * Updates a record.
 */
public void testUpdate() {
    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(" ");
        uow.add(object);
        uow.commit();
        // Now ensure that the record got created
        uow = new UOW();
        object = PartAdditional.findByPK(uow, PART);
        assertNotNull("A PartAdditional object should have been created", object);
        assertEquals(PART, object.getPart());
        // Update the object
        object.setField1("NEW VALUE");
        object.setField2("");
        object.setField3("  ");
        uow.update(object);
        uow.commit();
        // Now ensure that the record got updated
        uow = new UOW();
        object = PartAdditional.findByPK(uow, PART);
        assertNotNull("A PartAdditional object should have been updated", object);
        assertEquals(PART, object.getPart());
        assertEquals("NEW VALUE", object.getField1());
        assertNull(object.getField2());
        assertNull(object.getField3());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    } finally {
        try {
            if (uow != null)
                uow.rollback();
        } catch (Exception e) {
        // do nothing
        }
        cleanupData(PART);
    }
}
Also used : PartAdditional(org.jaffa.persistence.domainobjects.PartAdditional) UOW(org.jaffa.persistence.UOW)

Example 3 with PartAdditional

use of org.jaffa.persistence.domainobjects.PartAdditional in project jaffa-framework by jaffa-projects.

the class CharFieldTest method testJoinQueryBetweenCharAndVarchar.

/**
 * Tests the sql:
 * Select * from zz_jut_part_additional Where exists
 * (select 1 from zz_jut_part Where zz_jut_part.part = trim(zz_jut_part_additional.part))
 * This should return 1 record
 */
public void testJoinQueryBetweenCharAndVarchar() {
    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(" ");
        uow.add(object);
        uow.commit();
        // Perform  a join between PartAdditional and Part
        uow = new UOW();
        Criteria c1 = new Criteria();
        c1.setTable(PartMeta.getName());
        c1.addInnerCriteria(PartMeta.PART, PartAdditionalMeta.PART);
        Criteria c2 = new Criteria();
        c2.setTable(PartAdditionalMeta.getName());
        c2.addAggregate(c1);
        Collection col = uow.query(c2);
        assertEquals("One record should have been retrieved", 1, col.size());
        object = (PartAdditional) col.iterator().next();
        assertEquals(PART, object.getPart());
        assertNull(object.getField1());
        assertNull(object.getField2());
        assertNull(object.getField3());
        // Now lets do a join between PartAdditional and Part, and a non-existent record
        c1 = new Criteria();
        c1.setTable(PartMeta.getName());
        c1.addInnerCriteria(PartMeta.PART, PartAdditionalMeta.PART);
        c2 = new Criteria();
        c2.setTable(PartAdditionalMeta.getName());
        c2.addAggregate(c1);
        c2.addCriteria(PartAdditionalMeta.PART, "NON-EXISTENT-PART");
        col = uow.query(c2);
        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);
    }
}
Also used : PartAdditional(org.jaffa.persistence.domainobjects.PartAdditional) Collection(java.util.Collection) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 4 with PartAdditional

use of org.jaffa.persistence.domainobjects.PartAdditional 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);
    }
}
Also used : PartAdditional(org.jaffa.persistence.domainobjects.PartAdditional) Collection(java.util.Collection) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 5 with PartAdditional

use of org.jaffa.persistence.domainobjects.PartAdditional in project jaffa-framework by jaffa-projects.

the class Part method newPartAdditionalObject.

/**
 * Creates a new PartAdditional object and initializes the related fields.
 * @throws ValidationException if an invalid value is passed.
 * @throws FrameworkException Indicates some system error
 * @return the related PartAdditional object with the initialized related fields.
 */
public PartAdditional newPartAdditionalObject() throws ValidationException, FrameworkException {
    PartAdditional partAdditional = new PartAdditional();
    partAdditional.setPart(getPart());
    // .//GEN-BEGIN:partAdditionalObject_2_be
    return partAdditional;
}
Also used : PartAdditional(org.jaffa.persistence.domainobjects.PartAdditional)

Aggregations

PartAdditional (org.jaffa.persistence.domainobjects.PartAdditional)9 UOW (org.jaffa.persistence.UOW)7 Collection (java.util.Collection)4 Criteria (org.jaffa.persistence.Criteria)4 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)1 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 RelatedDomainObjectFoundException (org.jaffa.exceptions.RelatedDomainObjectFoundException)1 Asset (org.jaffa.persistence.domainobjects.Asset)1 Item (org.jaffa.persistence.domainobjects.Item)1 PartPicture (org.jaffa.persistence.domainobjects.PartPicture)1 PartRemarks (org.jaffa.persistence.domainobjects.PartRemarks)1 PartRemarksPicture (org.jaffa.persistence.domainobjects.PartRemarksPicture)1