001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * Created on Aug 7, 2004
018: *
019: */
020: package org.kuali.module.pdp.dao.ojb;
021:
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.apache.ojb.broker.query.Criteria;
026: import org.apache.ojb.broker.query.QueryByCriteria;
027: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
028: import org.kuali.core.exceptions.UserNotFoundException;
029: import org.kuali.core.service.UniversalUserService;
030: import org.kuali.module.pdp.bo.Bank;
031: import org.kuali.module.pdp.bo.UserRequired;
032: import org.kuali.module.pdp.dao.BankDao;
033:
034: /**
035: * @author jsissom
036: */
037: public class BankDaoOjb extends PlatformAwareDaoBaseOjb implements
038: BankDao {
039: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(BankDaoOjb.class);
041:
042: private UniversalUserService userService;
043:
044: public BankDaoOjb() {
045: super ();
046: }
047:
048: // Inject
049: public void setUniversalUserService(UniversalUserService us) {
050: userService = us;
051: }
052:
053: public List getAll() {
054: LOG.debug("getAll() started");
055:
056: QueryByCriteria qbc = new QueryByCriteria(Bank.class);
057: qbc.addOrderBy("name", true);
058:
059: List l = (List) getPersistenceBrokerTemplate()
060: .getCollectionByQuery(qbc);
061: updateUser(l);
062:
063: return l;
064: }
065:
066: public List getAll(boolean active) {
067: LOG.debug("getAll() started");
068:
069: Criteria c = new Criteria();
070: c.addEqualTo("active", new Boolean(active));
071:
072: QueryByCriteria qbc = new QueryByCriteria(Bank.class, c);
073: qbc.addOrderBy("name", true);
074:
075: List l = (List) getPersistenceBrokerTemplate()
076: .getCollectionByQuery(qbc);
077: updateUser(l);
078: return l;
079: }
080:
081: private void updateUser(List l) {
082: for (Iterator iter = l.iterator(); iter.hasNext();) {
083: updateUser((Bank) iter.next());
084: }
085: }
086:
087: private void updateUser(Bank b) {
088: UserRequired ur = (UserRequired) b;
089: try {
090: ur.updateUser(userService);
091: } catch (UserNotFoundException e) {
092: b.setLastUpdateUser(null);
093: }
094: }
095:
096: public Bank get(Integer bankId) {
097: LOG.debug("get() started");
098:
099: Criteria criteria = new Criteria();
100: criteria.addEqualTo("id", bankId);
101:
102: Bank b = (Bank) getPersistenceBrokerTemplate()
103: .getObjectByQuery(
104: new QueryByCriteria(Bank.class, criteria));
105: if (b != null) {
106: updateUser(b);
107: }
108: return b;
109: }
110:
111: public List getAllBanksForDisbursementType(String type) {
112: LOG.debug("getAllBanksForDisbursementType() started");
113:
114: Criteria criteria = new Criteria();
115: criteria.addEqualTo("disbursementTypeCode", type);
116:
117: QueryByCriteria qbc = new QueryByCriteria(Bank.class, criteria);
118: qbc.addOrderBy("name", true);
119:
120: List l = (List) getPersistenceBrokerTemplate()
121: .getObjectByQuery(
122: new QueryByCriteria(Bank.class, criteria));
123: updateUser(l);
124: return l;
125: }
126:
127: public void save(Bank b) {
128: LOG.debug("save() started");
129:
130: getPersistenceBrokerTemplate().store(b);
131: }
132: }
|