/**
 * @author dgeorge
 * 
 * $Id: BaseManager.java,v 1.3 2005-09-29 18:31:14 georgeda Exp $
 * 
 * $Log: not supported by cvs2svn $
 * Revision 1.2  2005/09/26 14:02:38  georgeda
 * Added common code
 *
 * 
 */
package gov.nih.nci.camod.service.impl;

import gov.nih.nci.camod.service.Manager;
import gov.nih.nci.common.persistence.Persist;
import gov.nih.nci.common.persistence.Search;
import gov.nih.nci.common.persistence.exception.PersistenceException;
import gov.nih.nci.common.persistence.hibernate.HibernateUtil;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Base class for managers.  Provides the generic Object based calls.
 */
public class BaseManager implements Manager {
    protected final Log log = LogFactory.getLog(getClass());
    
    /**
     * Get all of the objects models in the DB
     * 
     * @return the list of all objects
     * 
     * @exception throws
     *                an Exception if an error occurred
     */
    protected List getAll(Class inClass) throws Exception {

        log.trace("Entering BaseManager.getAll");

        List theObjects = null;

        try {
            theObjects = Search.query(inClass);
        } catch (Exception e) {
            log.error("Exception occurred in BaseManager.getAll", e);
            throw e;
        }

        log.trace("Exiting BaseManager.getAll");

        return theObjects;
    }

    /**
     * Get a specific object by unique ID
     * 
     * @param id
     *            The unique id for the object
     * 
     * @return the object if found, null otherwise
     * @throws Exception
     * 
     * @exception Exception
     *                if an error occurred
     */
    protected Object get(String inId, Class inClass) throws Exception {

        log.trace("Entering BaseManager.get");

        Object theObject = null;

        try {
            log.debug("Querying for id: " + inId);
            theObject = Search.queryById(inClass, new Long(inId));
        } catch (PersistenceException pe) {
            log.error("Exception occurred in BaseManager.get", pe);
            throw pe;
        } catch (Exception e) {
            log.error("Exception occurred in BaseManager.get", e);
            throw e;
        }

        log.trace("Exiting BaseManager.get");
        return theObject;
    }

    /**
     * Save an object
     * 
     * @param inObject
     *            The object to save
     * 
     * @exception Exception
     *                if an error occurred
     */
    protected void save(Object inObject) throws Exception {

        log.trace("Entering BaseManager.save");

        try {
            // Begin an transaction
            HibernateUtil.beginTransaction();

            //Save the object
            log.debug("Saving object");
            Persist.save(inObject);

            // Commit all changes or none
            HibernateUtil.commitTransaction();

        } catch (PersistenceException pe) {
            HibernateUtil.rollbackTransaction();
            log.error("PersistenceException in BaseManager.save", pe);
            throw pe;
        } catch (Exception e) {
            HibernateUtil.rollbackTransaction();
            log.error("Exception in BaseManager.save", e);
            throw e;
        }
    }

    /**
     * Remove an object from the system. Should remove all associated
     * data as well
     * 
     * @param inId
     *            The unique id of the object to delete
     * 
     * @throws Exception
     *             An error occurred when attempting to delete the object
     */
    protected void remove(String inId, Class inClass) throws Exception {

        log.trace("Entering BaseManager.remove");

        try {
            log.debug("Removing object: " + inId);
            Persist.deleteById(inClass, new Long(inId));
        } catch (PersistenceException pe) {
            log.error("Unable to delete object: ", pe);
            throw pe;
        } catch (Exception e) {
            log.error("Unable to delete object: ", e);
            throw e;
        }

        log.trace("Exiting BaseManager.remove");
    }
}

@@ -53,29 +53,29 @@
 v 1.
-3
+4
  2005-
-09-29 18:31:14
+10-26 20:54:51
  geo
@@ -126,16 +126,119 @@
 s2svn $%0A
+ * Revision 1.3  2005/09/29 18:31:14  georgeda%0A * Changed visibility of base functions to protected%0A *%0A
  * Revis
@@ -759,17 +759,16 @@
 anagers.
- 
  Provide
@@ -851,16 +851,17 @@
 nager %7B%0A
+%0A
     prot
@@ -913,20 +913,16 @@
 ass());%0A
-    
 %0A    /**
@@ -2868,16 +2868,17 @@
       //
+ 
 Save the
@@ -3497,23 +3497,16 @@
 ated
-%0A     *
  data as
  wel
@@ -3501,16 +3501,23 @@
  data as
+%0A     *
  well%0A  
@@ -3843,32 +3843,115 @@
 %0A%0A        try %7B%0A
+            // Begin an transaction%0A            HibernateUtil.beginTransaction();%0A%0A
             log.
@@ -4034,32 +4034,123 @@
 ew Long(inId));%0A
+%0A            // Commit all changes or none%0A            HibernateUtil.commitTransaction();%0A%0A
         %7D catch 
@@ -4169,32 +4169,81 @@
 Exception pe) %7B%0A
+            HibernateUtil.rollbackTransaction();%0A
             log.
@@ -4328,32 +4328,81 @@
 (Exception e) %7B%0A
+            HibernateUtil.rollbackTransaction();%0A
             log.

Put transaction around remove