001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.actiontaken.dao;
018:
019: import java.sql.Timestamp;
020: import java.util.Collection;
021: import java.util.List;
022:
023: import org.apache.ojb.broker.query.Criteria;
024: import org.apache.ojb.broker.query.QueryByCriteria;
025: import org.springmodules.orm.ojb.PersistenceBrokerTemplate;
026: import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
027:
028: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
029: import edu.iu.uis.eden.actiontaken.ActionTakenValue;
030:
031: /**
032: * OJB implementation of the {@link ActionTakenDAO}.
033: *
034: * @author rkirkend
035: */
036: public class ActionTakenDAOOjbImpl extends PersistenceBrokerDaoSupport
037: implements ActionTakenDAO {
038:
039: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(ActionTakenDAOOjbImpl.class);
041:
042: public ActionTakenValue load(Long id) {
043: LOG.debug("Loading Action Taken for the given id " + id);
044: Criteria crit = new Criteria();
045: crit.addEqualTo("actionTakenId", id);
046: return (ActionTakenValue) this .getPersistenceBrokerTemplate()
047: .getObjectByQuery(
048: new QueryByCriteria(ActionTakenValue.class,
049: crit));
050: }
051:
052: public void deleteActionTaken(ActionTakenValue actionTaken) {
053: LOG.debug("deleting ActionTaken "
054: + actionTaken.getActionTakenId());
055: this .getPersistenceBrokerTemplate().delete(actionTaken);
056: }
057:
058: public ActionTakenValue findByActionTakenId(Long actionTakenId) {
059: LOG.debug("finding Action Taken by actionTakenId "
060: + actionTakenId);
061: Criteria crit = new Criteria();
062: crit.addEqualTo("actionTakenId", actionTakenId);
063: crit.addEqualTo("currentIndicator", new Boolean(true));
064: return (ActionTakenValue) this .getPersistenceBrokerTemplate()
065: .getObjectByQuery(
066: new QueryByCriteria(ActionTakenValue.class,
067: crit));
068: }
069:
070: public Collection findByDocIdAndAction(Long routeHeaderId,
071: String action) {
072: LOG.debug("finding Action Taken by routeHeaderId "
073: + routeHeaderId + " and action " + action);
074: Criteria crit = new Criteria();
075: crit.addEqualTo("routeHeaderId", routeHeaderId);
076: crit.addEqualTo("actionTaken", action);
077: crit.addEqualTo("currentIndicator", new Boolean(true));
078: return this .getPersistenceBrokerTemplate()
079: .getCollectionByQuery(
080: new QueryByCriteria(ActionTakenValue.class,
081: crit));
082: }
083:
084: public Collection findByRouteHeaderId(Long routeHeaderId) {
085: LOG.debug("finding Action Takens by routeHeaderId "
086: + routeHeaderId);
087: Criteria crit = new Criteria();
088: crit.addEqualTo("routeHeaderId", routeHeaderId);
089: crit.addEqualTo("currentIndicator", new Boolean(true));
090: return this .getPersistenceBrokerTemplate()
091: .getCollectionByQuery(
092: new QueryByCriteria(ActionTakenValue.class,
093: crit));
094: }
095:
096: public List findByRouteHeaderIdWorkflowId(Long routeHeaderId,
097: String workflowId) {
098: LOG.debug("finding Action Takens by routeHeaderId "
099: + routeHeaderId + " and workflowId" + workflowId);
100: Criteria crit = new Criteria();
101: crit.addEqualTo("routeHeaderId", routeHeaderId);
102: crit.addEqualTo("workflowId", workflowId);
103: crit.addEqualTo("currentIndicator", new Boolean(true));
104: return (List) this .getPersistenceBrokerTemplate()
105: .getCollectionByQuery(
106: new QueryByCriteria(ActionTakenValue.class,
107: crit));
108: }
109:
110: public List findByRouteHeaderIdIgnoreCurrentInd(Long routeHeaderId) {
111: LOG
112: .debug("finding ActionsTaken ignoring currentInd by routeHeaderId:"
113: + routeHeaderId);
114: Criteria crit = new Criteria();
115: crit.addEqualTo("routeHeaderId", routeHeaderId);
116: return (List) this .getPersistenceBrokerTemplate()
117: .getCollectionByQuery(
118: new QueryByCriteria(ActionTakenValue.class,
119: crit));
120: }
121:
122: public void saveActionTaken(ActionTakenValue actionTaken) {
123: LOG.debug("saving ActionTaken");
124: checkNull(actionTaken.getRouteHeaderId(), "Document ID");
125: checkNull(actionTaken.getActionTaken(), "action taken code");
126: checkNull(actionTaken.getDocVersion(), "doc version");
127: checkNull(actionTaken.getWorkflowId(), "user workflowId");
128:
129: if (actionTaken.getActionDate() == null) {
130: actionTaken.setActionDate(new Timestamp(System
131: .currentTimeMillis()));
132: }
133: if (actionTaken.getCurrentIndicator() == null) {
134: actionTaken.setCurrentIndicator(new Boolean(true));
135: }
136: LOG.debug("saving ActionTaken: routeHeader "
137: + actionTaken.getRouteHeaderId() + ", actionTaken "
138: + actionTaken.getActionTaken() + ", workflowId "
139: + actionTaken.getWorkflowId());
140: this .getPersistenceBrokerTemplate().store(actionTaken);
141: }
142:
143: //TODO perhaps runtime isn't the best here, maybe a dao runtime exception
144: private void checkNull(Object value, String valueName)
145: throws RuntimeException {
146: if (value == null) {
147: throw new RuntimeException("Null value for " + valueName);
148: }
149: }
150:
151: public void deleteByRouteHeaderId(Long routeHeaderId) {
152: Criteria crit = new Criteria();
153: crit.addEqualTo("routeHeaderId", routeHeaderId);
154: this .getPersistenceBrokerTemplate().deleteByQuery(
155: new QueryByCriteria(ActionRequestValue.class, crit));
156: }
157: }
|