Search in sources :

Example 6 with PartAdditional

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

the class CharFieldTest method testNullQuery.

/**
 * Tests the sql:
 * Select * from zz_jut_part_additional where field1 is null or field1 = ' '
 * This should return 1 record
 */
public void testNullQuery() {
    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 field1 is null. Should get 1 record
        uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(PartAdditionalMeta.getName());
        c.addCriteria(PartAdditionalMeta.FIELD1, Criteria.RELATIONAL_IS_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 field2 is null. Nothing should be retrieved
        uow = new UOW();
        c = new Criteria();
        c.setTable(PartAdditionalMeta.getName());
        c.addCriteria(PartAdditionalMeta.FIELD2, Criteria.RELATIONAL_IS_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 7 with PartAdditional

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

the class CharFieldTest method testEndsWithQuery.

/**
 * Tests the sql:
 * Select * from zz_jut_part_additional where trim(part) like '%01'
 * This should return 1 record
 */
public void testEndsWithQuery() {
    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 query using the EndsWith clause
        uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(PartAdditionalMeta.getName());
        c.addCriteria(PartAdditionalMeta.PART, Criteria.RELATIONAL_ENDS_WITH, "01");
        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());
        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) Collection(java.util.Collection) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 8 with PartAdditional

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

the class CharFieldTest method testAdd.

/**
 * Inserts a new record.
 */
public void testAdd() {
    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());
        assertNull(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 9 with PartAdditional

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

the class Part method performPreDeleteReferentialIntegrity.

// .//GEN-END:performForeignKeyValidations_1_be
// .//GEN-BEGIN:performPreDeleteReferentialIntegrity_1_be
/**
 * This method is triggered by the UOW, before adding this object to the Delete-Store.
 * This will raise an exception if any associated/aggregated objects exist.
 * This will cascade delete all composite objects.
 * @throws PreDeleteFailedException if any error occurs during the process.
 */
public void performPreDeleteReferentialIntegrity() throws PreDeleteFailedException {
    Asset[] assetArray = null;
    try {
        assetArray = getAssetArray();
    } catch (FrameworkException e) {
        throw new PreDeleteFailedException(null, e);
    }
    if (assetArray != null && assetArray.length > 0) {
        try {
            // Perform cascade deletes
            for (int i = 0; i < assetArray.length; i++) getUOW().delete(assetArray[i]);
        } catch (Exception e) {
            throw new PreDeleteFailedException(null, e);
        }
    }
    Item[] itemArray = null;
    try {
        itemArray = getItemArray();
    } catch (FrameworkException e) {
        throw new PreDeleteFailedException(null, e);
    }
    if (itemArray != null && itemArray.length > 0) {
        try {
            // Perform cascade deletes
            for (int i = 0; i < itemArray.length; i++) getUOW().delete(itemArray[i]);
        } catch (Exception e) {
            throw new PreDeleteFailedException(null, e);
        }
    }
    PartRemarks partRemarksObject = null;
    try {
        partRemarksObject = getPartRemarksObject();
    } catch (FrameworkException e) {
        throw new PreDeleteFailedException(null, e);
    }
    if (partRemarksObject != null) {
        // Stop the deletion !!
        throw new PreDeleteFailedException(null, new RelatedDomainObjectFoundException(PartRemarksMeta.getLabelToken()));
    }
    PartPicture partPictureObject = null;
    try {
        partPictureObject = getPartPictureObject();
    } catch (FrameworkException e) {
        throw new PreDeleteFailedException(null, e);
    }
    if (partPictureObject != null) {
        try {
            // Perform cascade delete
            getUOW().delete(partPictureObject);
        } catch (Exception e) {
            throw new PreDeleteFailedException(null, e);
        }
    }
    PartRemarksPicture partRemarksPictureObject = null;
    try {
        partRemarksPictureObject = getPartRemarksPictureObject();
    } catch (FrameworkException e) {
        throw new PreDeleteFailedException(null, e);
    }
    if (partRemarksPictureObject != null) {
        try {
            // Perform cascade delete
            getUOW().delete(partRemarksPictureObject);
        } catch (Exception e) {
            throw new PreDeleteFailedException(null, e);
        }
    }
    PartAdditional partAdditionalObject = null;
    try {
        partAdditionalObject = getPartAdditionalObject();
    } catch (FrameworkException e) {
        throw new PreDeleteFailedException(null, e);
    }
    if (partAdditionalObject != null) {
        try {
            // Perform cascade delete
            getUOW().delete(partAdditionalObject);
        } catch (Exception e) {
            throw new PreDeleteFailedException(null, e);
        }
    }
}
Also used : FrameworkException(org.jaffa.exceptions.FrameworkException) PartRemarksPicture(org.jaffa.persistence.domainobjects.PartRemarksPicture) RelatedDomainObjectFoundException(org.jaffa.exceptions.RelatedDomainObjectFoundException) FrameworkException(org.jaffa.exceptions.FrameworkException) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) DuplicateKeyException(org.jaffa.exceptions.DuplicateKeyException) RelatedDomainObjectFoundException(org.jaffa.exceptions.RelatedDomainObjectFoundException) Item(org.jaffa.persistence.domainobjects.Item) PartRemarks(org.jaffa.persistence.domainobjects.PartRemarks) Asset(org.jaffa.persistence.domainobjects.Asset) PartAdditional(org.jaffa.persistence.domainobjects.PartAdditional) PartPicture(org.jaffa.persistence.domainobjects.PartPicture)

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