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.CustomerBank;
031: import org.kuali.module.pdp.bo.CustomerProfile;
032: import org.kuali.module.pdp.bo.UserRequired;
033: import org.kuali.module.pdp.dao.CustomerProfileDao;
034:
035: /**
036: * @author jsissom
037: */
038: public class CustomerProfileDaoOjb extends PlatformAwareDaoBaseOjb
039: implements CustomerProfileDao {
040: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
041: .getLogger(CustomerProfileDaoOjb.class);
042:
043: private UniversalUserService userService;
044:
045: public CustomerProfileDaoOjb() {
046: super ();
047: }
048:
049: // Inject
050: public void setUniversalUserService(UniversalUserService us) {
051: userService = us;
052: }
053:
054: private void updateUser(List l) {
055: for (Iterator iter = l.iterator(); iter.hasNext();) {
056: updateUser((CustomerProfile) iter.next());
057: }
058: }
059:
060: private void updateUser(CustomerProfile b) {
061: UserRequired ur = (UserRequired) b;
062: try {
063: ur.updateUser(userService);
064: } catch (UserNotFoundException e) {
065: b.setLastUpdateUser(null);
066: }
067: }
068:
069: public List getAll() {
070: LOG.debug("getAll() started");
071:
072: QueryByCriteria qbc = new QueryByCriteria(CustomerProfile.class);
073: qbc.addOrderByAscending("chartCode");
074: qbc.addOrderByAscending("orgCode");
075: qbc.addOrderByAscending("subUnitCode");
076:
077: List l = (List) getPersistenceBrokerTemplate()
078: .getCollectionByQuery(qbc);
079: updateUser(l);
080: return l;
081: }
082:
083: public CustomerProfile get(Integer custId) {
084: LOG.debug("get(id) started");
085:
086: Criteria criteria = new Criteria();
087: criteria.addEqualTo("id", custId);
088:
089: CustomerProfile cp = (CustomerProfile) getPersistenceBrokerTemplate()
090: .getObjectByQuery(
091: new QueryByCriteria(CustomerProfile.class,
092: criteria));
093: if (cp != null) {
094: updateUser(cp);
095: }
096: // List s = cp.getCustomerBanks();
097: // LOG.error("get() Banks (customerId: " + cp.getId() + "):");
098: // for (Iterator iter = s.iterator(); iter.hasNext();) {
099: // CustomerBank element = (CustomerBank) iter.next();
100: // LOG.error("get() BANK: " + element);
101: // }
102: return cp;
103: }
104:
105: public CustomerProfile get(String chartCode, String orgCode,
106: String subUnitCode) {
107: LOG.debug("get(chart,org,sub unit) started");
108:
109: Criteria criteria = new Criteria();
110: criteria.addEqualTo("chartCode", chartCode);
111: criteria.addEqualTo("orgCode", orgCode);
112: criteria.addEqualTo("subUnitCode", subUnitCode);
113:
114: CustomerProfile cp = (CustomerProfile) getPersistenceBrokerTemplate()
115: .getObjectByQuery(
116: new QueryByCriteria(CustomerProfile.class,
117: criteria));
118: if (cp != null) {
119: updateUser(cp);
120: }
121: return cp;
122: }
123:
124: public void save(CustomerProfile cp) {
125: LOG.debug("save() started");
126:
127: getPersistenceBrokerTemplate().store(cp);
128: }
129:
130: public void saveCustomerBank(CustomerBank cb) {
131: LOG.debug("saveCustomerBank() started");
132:
133: getPersistenceBrokerTemplate().store(cb);
134: }
135:
136: public void deleteCustomerBank(CustomerBank cb) {
137: LOG.debug("deleteCustomerBank() started");
138:
139: getPersistenceBrokerTemplate().delete(cb);
140: }
141: }
|