01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.cg.dao.ojb;
17:
18: import java.util.Iterator;
19:
20: import org.apache.ojb.broker.query.Criteria;
21: import org.apache.ojb.broker.query.QueryByCriteria;
22: import org.apache.ojb.broker.query.QueryFactory;
23: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
24: import org.kuali.core.util.TransactionalServiceUtils;
25: import org.kuali.kfs.KFSConstants;
26: import org.kuali.module.cg.bo.Close;
27: import org.kuali.module.cg.dao.CloseDao;
28: import org.springmodules.orm.ojb.PersistenceBrokerTemplate;
29:
30: /**
31: * @see CloseDao
32: */
33: public class CloseDaoOjb extends PlatformAwareDaoBaseOjb implements
34: CloseDao {
35:
36: /**
37: * @see org.kuali.module.cg.dao.CloseDao#getMaxApprovedClose()
38: */
39: public Close getMaxApprovedClose() {
40: Criteria criteria = new Criteria();
41: criteria.addEqualTo(
42: "documentHeader.financialDocumentStatusCode",
43: KFSConstants.DocumentStatusCodes.APPROVED);
44: QueryByCriteria query = QueryFactory.newQuery(Close.class,
45: criteria);
46: query.addOrderByDescending("documentNumber");
47: PersistenceBrokerTemplate template = getPersistenceBrokerTemplate();
48: Iterator i = template.getIteratorByQuery(query);
49: if (null != i) {
50: if (i.hasNext()) {
51: Close close = (Close) TransactionalServiceUtils
52: .retrieveFirstAndExhaustIterator(i);
53: if (null == close.getAwardClosedCount()) {
54: close.setAwardClosedCount(0L);
55: }
56: if (null == close.getProposalClosedCount()) {
57: close.setProposalClosedCount(0L);
58: }
59: return close;
60: }
61: }
62: return null;
63: }
64:
65: /**
66: * @see org.kuali.module.cg.dao.CloseDao#save(org.kuali.module.cg.bo.Close)
67: */
68: public void save(Close close) {
69: getPersistenceBrokerTemplate().store(close);
70: }
71:
72: }
|