Search in sources :

Example 96 with UOW

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

the class UserTimeEntryMaintenanceTx method retrieve.

// .//GEN-END:_create_1_be
// .//GEN-BEGIN:_retrieve_1_be
/**
 * Returns the details for UserTimeEntry.
 * @param input The criteria based on which an object will be retrieved.
 * @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
 * @throws FrameworkException Indicates some system error.
 * @return The object details. A null indicates, the object was not found.
 */
public UserTimeEntryMaintenanceRetrieveOutDto retrieve(UserTimeEntryMaintenanceRetrieveInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled())
            log.debug("Input: " + input);
        // create the UOW
        uow = new UOW();
        // Preprocess the input
        preprocess(uow, input);
        // Retrieve the object
        UserTimeEntry domain = load(uow, input);
        // Convert the domain objects into the outbound dto
        UserTimeEntryMaintenanceRetrieveOutDto output = buildRetrieveOutDto(uow, input, domain);
        // Print Debug Information for the output
        if (log.isDebugEnabled())
            log.debug("Output: " + output);
        return output;
    } catch (FrameworkException e) {
        // If it is, then re-throw as ApplicationsExceptions, else throw the FrameworkException.
        if (e.getCause() != null && e.getCause() instanceof ApplicationExceptions) {
            throw (ApplicationExceptions) e.getCause();
        } else if (e.getCause() != null && e.getCause() instanceof ApplicationException) {
            ApplicationExceptions appExps = new ApplicationExceptions();
            appExps.add((ApplicationException) e.getCause());
            throw appExps;
        } else
            throw e;
    } finally {
        if (uow != null)
            uow.rollback();
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) UserTimeEntry(org.jaffa.applications.test.modules.time.domain.UserTimeEntry) UOW(org.jaffa.persistence.UOW)

Example 97 with UOW

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

the class UserTimeEntryLookupTx method find.

// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_find_1_be
/**
 * Searches for UserTimeEntry objects.
 * @param input The criteria based on which the search will be performed.
 * @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
 * @throws FrameworkException Indicates some system error
 * @return The search results.
 */
public UserTimeEntryLookupOutDto find(UserTimeEntryLookupInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled()) {
            log.debug("Input: " + input);
        }
        // create the UOW
        uow = new UOW();
        // Build the Criteria Object
        Criteria criteria = buildCriteria(input, uow);
        // .//GEN-END:_find_1_be
        // Add custom code before the query //GEN-FIRST:_find_1
        // .//GEN-LAST:_find_1
        // .//GEN-BEGIN:_find_2_be
        // Execute The Query
        Collection results = uow.query(criteria);
        // .//GEN-END:_find_2_be
        // Add custom code after the query //GEN-FIRST:_find_2
        // .//GEN-LAST:_find_2
        // .//GEN-BEGIN:_find_3_be
        // Convert the domain objects into the outbound dto
        UserTimeEntryLookupOutDto output = buildDto(uow, results, input);
        // Print Debug Information for the output
        if (log.isDebugEnabled()) {
            log.debug("Output: " + output);
        }
        return output;
    } finally {
        if (uow != null)
            uow.rollback();
    }
}
Also used : UserTimeEntryLookupOutDto(org.jaffa.applications.test.modules.time.components.usertimeentrylookup.dto.UserTimeEntryLookupOutDto) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 98 with UOW

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

the class ItemFinderTx method find.

// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_find_1_be
/**
 * Searches for Item objects.
 * @param input The criteria based on which the search will be performed.
 * @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
 * @throws FrameworkException Indicates some system error
 * @return The search results.
 */
public ItemFinderOutDto find(ItemFinderInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled()) {
            log.debug("Input: " + input);
        }
        // create the UOW
        uow = new UOW();
        // Build the Criteria Object
        Criteria criteria = buildCriteria(input, uow);
        // .//GEN-END:_find_1_be
        // Add custom code before the query //GEN-FIRST:_find_1
        // .//GEN-LAST:_find_1
        // .//GEN-BEGIN:_find_2_be
        // Execute The Query
        Collection results = uow.query(criteria);
        // .//GEN-END:_find_2_be
        // Add custom code after the query //GEN-FIRST:_find_2
        // .//GEN-LAST:_find_2
        // .//GEN-BEGIN:_find_3_be
        // Convert the domain objects into the outbound dto
        ItemFinderOutDto output = buildDto(uow, results, input);
        // Print Debug Information for the output
        if (log.isDebugEnabled()) {
            log.debug("Output: " + output);
        }
        return output;
    } finally {
        if (uow != null)
            uow.rollback();
    }
}
Also used : ItemFinderOutDto(org.jaffa.applications.test.modules.material.components.itemfinder.dto.ItemFinderOutDto) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 99 with UOW

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

the class BeanMoulder method updateBean.

/**
 * Take a source object and try and mold it back it its domain object
 * @param path The path of this object being processed. This identifies possible parent
 * and/or indexed entries where this object is contained.
 * @param source Source object to mould from, typically a DomainDAO
 * @param uow Transaction handle all creates/update will be performed within.
 * Throws an exception if null.
 * @param handler Possible bean handler to be used when processing this source object graph
 * @throws ApplicationExceptions Thrown if one or more application logic errors are generated during moulding
 * @throws FrameworkException Thrown if any runtime moulding error has occured.
 */
public static void updateBean(String path, DomainDAO source, UOW uow, MouldHandler handler) throws ApplicationExceptions, FrameworkException {
    log.debug("Update Bean " + path);
    // Call custom validation code in the DAO
    source.validate();
    ApplicationExceptions aes = new ApplicationExceptions();
    if (uow == null) {
        String err = "UOW Required";
        log.error(err);
        throw new RuntimeException(err);
    }
    try {
        IPersistent domainObject = null;
        GraphMapping mapping = MappingFactory.getInstance(source);
        Map keys = new LinkedHashMap();
        Class doClass = mapping.getDomainClass();
        // Get the key fields used in the domain object
        boolean gotKeys = fillInKeys(path, source, mapping, keys);
        // read DO based on key
        if (gotKeys) {
            // get the method on the DO to read via PK
            Method[] ma = doClass.getMethods();
            Method findByPK = null;
            for (int i = 0; i < ma.length; i++) {
                if (ma[i].getName().equals("findByPK")) {
                    if (ma[i].getParameterTypes().length == (keys.size() + 1) && (ma[i].getParameterTypes())[0] == UOW.class) {
                        // Found with name and correct no. of input params
                        findByPK = ma[i];
                        break;
                    }
                }
            }
            if (findByPK == null) {
                aes.add(new DomainObjectNotFoundException(doClass.getName() + " @ " + path));
                throw aes;
            }
            // Build input array
            Object[] inputs = new Object[keys.size() + 1];
            {
                inputs[0] = uow;
                int i = 1;
                for (Iterator it = keys.values().iterator(); it.hasNext(); i++) {
                    inputs[i] = it.next();
                }
            }
            // Find Object based on key
            domainObject = (IPersistent) findByPK.invoke(null, inputs);
        } else
            log.debug("Object " + path + " has either missing or null key values - Assume Create is needed");
        // Create object if not found
        if (domainObject == null) {
            // NEW OBJECT, create and reflect keys
            log.debug("DO '" + mapping.getDomainClassShortName() + "' not found with key, create a new one...");
            domainObject = (IPersistent) doClass.newInstance();
            // set the key fields
            for (Iterator it = keys.keySet().iterator(); it.hasNext(); ) {
                String keyField = (String) it.next();
                Object value = keys.get(keyField);
                updateProperty(mapping.getDomainFieldDescriptor(keyField), value, domainObject);
            }
        } else {
            log.debug("Found DO '" + mapping.getDomainClassShortName() + "' with key,");
        }
        // Now update all domain fields
        updateBeanData(path, source, uow, handler, mapping, domainObject);
    } catch (IllegalAccessException e) {
        MouldException me = new MouldException(MouldException.ACCESS_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    } catch (InvocationTargetException e) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof FrameworkException)
                throw (FrameworkException) e.getCause();
            if (e.getCause() instanceof ApplicationExceptions)
                throw (ApplicationExceptions) e.getCause();
            if (e.getCause() instanceof ApplicationException) {
                aes.add((ApplicationException) e.getCause());
                throw aes;
            }
        }
        MouldException me = new MouldException(MouldException.INVOCATION_ERROR, path, e);
        log.error(me.getLocalizedMessage(), me.getCause());
        throw me;
    } catch (InstantiationException e) {
        MouldException me = new MouldException(MouldException.INSTANTICATION_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) ApplicationException(org.jaffa.exceptions.ApplicationException) IPersistent(org.jaffa.persistence.IPersistent) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) Iterator(java.util.Iterator) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GraphMapping(org.jaffa.beans.moulding.mapping.GraphMapping)

Example 100 with UOW

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

the class BeanMoulder method deleteBean.

/**
 * Take a source object and delete it or delete is children if it has any
 * @param path The path of this object being processed. This identifies possible parent
 * and/or indexed entries where this object is contained.
 * @param source Source object to mould from, typically a DomainDAO
 * @param uow Transaction handle all creates/update will be performed within.
 * Throws an exception if null.
 * @param handler Possible bean handler to be used when processing this source object graph
 * @throws ApplicationExceptions Thrown if one or more application logic errors are generated during moulding
 * @throws FrameworkException Thrown if any runtime moulding error has occured.
 */
public static void deleteBean(String path, DomainDAO source, UOW uow, MouldHandler handler) throws ApplicationExceptions, FrameworkException {
    log.debug("Delete Bean " + path);
    // Call custom validation code in the DAO
    source.validate();
    ApplicationExceptions aes = new ApplicationExceptions();
    if (uow == null) {
        String err = "UOW Required";
        log.error(err);
        throw new RuntimeException(err);
    }
    try {
        IPersistent domainObject = null;
        GraphMapping mapping = MappingFactory.getInstance(source);
        Map keys = new LinkedHashMap();
        Class doClass = mapping.getDomainClass();
        // Get the key fields used in the domain object
        boolean gotKeys = fillInKeys(path, source, mapping, keys);
        // read DO based on key
        if (gotKeys) {
            // get the method on the DO to read via PK
            Method[] ma = doClass.getMethods();
            Method findByPK = null;
            for (int i = 0; i < ma.length; i++) {
                if (ma[i].getName().equals("findByPK")) {
                    if (ma[i].getParameterTypes().length == (keys.size() + 1) && (ma[i].getParameterTypes())[0] == UOW.class) {
                        // Found with name and correct no. of input params
                        findByPK = ma[i];
                        break;
                    }
                }
            }
            if (findByPK == null) {
                aes.add(new DomainObjectNotFoundException(doClass.getName()));
                throw aes;
            }
            // Build input array
            Object[] inputs = new Object[keys.size() + 1];
            {
                inputs[0] = uow;
                int i = 1;
                for (Iterator it = keys.values().iterator(); it.hasNext(); i++) {
                    inputs[i] = it.next();
                }
            }
            // Find Object based on key
            domainObject = (IPersistent) findByPK.invoke(null, inputs);
        } else
            log.debug("Object " + path + " has either missing or null key values - Assume Create is needed");
        // Error if DO not found
        if (domainObject == null) {
            String label = doClass.getName();
            // Try and use meta data to get domain objects label
            try {
                label = PersistentHelper.getLabelToken(doClass.getName());
            } catch (Exception e) {
            // ignore any problem trying to get the label!
            }
            aes.add(new DomainObjectNotFoundException(label + " (path=" + path + ")"));
            throw aes;
        }
        // Process the delete, either on this DO, or a related DO if there is one
        deleteBeanData(path, source, uow, handler, mapping, domainObject);
    } catch (IllegalAccessException e) {
        MouldException me = new MouldException(MouldException.ACCESS_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    } catch (InvocationTargetException e) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof FrameworkException)
                throw (FrameworkException) e.getCause();
            if (e.getCause() instanceof ApplicationExceptions)
                throw (ApplicationExceptions) e.getCause();
            if (e.getCause() instanceof ApplicationException) {
                aes.add((ApplicationException) e.getCause());
                throw aes;
            }
        }
        MouldException me = new MouldException(MouldException.INVOCATION_ERROR, path, e);
        log.error(me.getLocalizedMessage(), me.getCause());
        throw me;
    } catch (InstantiationException e) {
        MouldException me = new MouldException(MouldException.INSTANTICATION_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    }
// } catch (Exception e) {
// throw handleException(e,aes);
// }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) Method(java.lang.reflect.Method) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultipleDomainObjectsFoundException(org.jaffa.exceptions.MultipleDomainObjectsFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) ApplicationException(org.jaffa.exceptions.ApplicationException) IPersistent(org.jaffa.persistence.IPersistent) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) Iterator(java.util.Iterator) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GraphMapping(org.jaffa.beans.moulding.mapping.GraphMapping)

Aggregations

UOW (org.jaffa.persistence.UOW)260 Criteria (org.jaffa.persistence.Criteria)139 FrameworkException (org.jaffa.exceptions.FrameworkException)99 ApplicationException (org.jaffa.exceptions.ApplicationException)88 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)87 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)82 Iterator (java.util.Iterator)47 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)33 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)33 ArrayList (java.util.ArrayList)19 Transaction (org.jaffa.transaction.domain.Transaction)19 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)13 HashMap (java.util.HashMap)12 DateTime (org.jaffa.datatypes.DateTime)11 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)10 IPersistent (org.jaffa.persistence.IPersistent)10 Method (java.lang.reflect.Method)9 Collection (java.util.Collection)8 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)8