01: /*
02: * Copyright 2006-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.purap.dao.ojb;
17:
18: import java.util.Iterator;
19:
20: import org.apache.ojb.broker.query.Criteria;
21: import org.apache.ojb.broker.query.ReportQueryByCriteria;
22: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
23: import org.kuali.core.util.TransactionalServiceUtils;
24: import org.kuali.kfs.KFSPropertyConstants;
25: import org.kuali.module.purap.PurapPropertyConstants;
26: import org.kuali.module.purap.dao.RequisitionDao;
27: import org.kuali.module.purap.document.RequisitionDocument;
28:
29: /**
30: * OJB implementation of RequisitionDao.
31: */
32: public class RequisitionDaoOjb extends PlatformAwareDaoBaseOjb
33: implements RequisitionDao {
34: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
35: .getLogger(RequisitionDaoOjb.class);
36:
37: /**
38: * @see org.kuali.module.purap.dao.RequisitionDao#getDocumentNumberForRequisitionId(java.lang.Integer)
39: */
40: public String getDocumentNumberForRequisitionId(Integer id) {
41: Criteria criteria = new Criteria();
42: criteria.addEqualTo(PurapPropertyConstants.PURAP_DOC_ID, id);
43:
44: ReportQueryByCriteria rqbc = new ReportQueryByCriteria(
45: RequisitionDocument.class, criteria);
46: rqbc
47: .setAttributes(new String[] { KFSPropertyConstants.DOCUMENT_NUMBER });
48: rqbc.addOrderByAscending(KFSPropertyConstants.DOCUMENT_NUMBER);
49: Iterator iter = getPersistenceBrokerTemplate()
50: .getReportQueryIteratorByQuery(rqbc);
51: if (iter.hasNext()) {
52: Object[] cols = (Object[]) iter.next();
53: if (iter.hasNext()) {
54: // the iterator should have held only a single doc id of data but it holds 2 or more
55: String errorMsg = "Expected single document number for given criteria but multiple (at least 2) were returned";
56: LOG.error(errorMsg);
57: TransactionalServiceUtils.exhaustIterator(iter);
58: throw new RuntimeException();
59: }
60: // at this part of the code, we know there's no more elements in iterator
61: return (String) cols[0];
62: }
63: return null;
64: }
65:
66: }
|