Search in sources :

Example 1 with Condition

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

the class Item method findConditionObject.

/**
 * Finds the related foreign Condition object.
 * If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
 */
private void findConditionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_conditionObject == null && getCondition() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(ConditionMeta.getName());
            criteria.addCriteria(ConditionMeta.CONDITION, getCondition());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_conditionObject = (Condition) itr.next();
            }
            if (m_conditionObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(ItemMeta.META_CONDITION.getLabelToken(), new Object[] { ConditionMeta.getLabelToken(), ConditionMeta.META_CONDITION.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : Condition(org.jaffa.persistence.domainobjects.Condition) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 2 with Condition

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

the class Asset method findConditionObject.

/**
 * Finds the related foreign Condition object.
 * If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
 */
private void findConditionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_conditionObject == null && getCondition() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(ConditionMeta.getName());
            criteria.addCriteria(ConditionMeta.CONDITION, getCondition());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_conditionObject = (Condition) itr.next();
            }
            if (m_conditionObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(AssetMeta.META_CONDITION.getLabelToken(), new Object[] { ConditionMeta.getLabelToken(), ConditionMeta.META_CONDITION.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : Condition(org.jaffa.persistence.domainobjects.Condition) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Aggregations

InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)2 Condition (org.jaffa.persistence.domainobjects.Condition)2