01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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: **/package org.araneaframework.example.main.business.data;
16:
17: import java.util.ArrayList;
18: import java.util.Iterator;
19: import java.util.List;
20: import org.araneaframework.example.main.business.model.ContractMO;
21:
22: /**
23: * Quick'n'dirty fix for the ever annoying problem with broken contracts when persons or companies are deleted.
24: * @author Taimo Peelo (taimo@araneaframework.org)
25: */
26: public class ContractDAO extends GeneralDAO implements IContractDAO {
27:
28: public void removeByPersonId(Long personId) {
29: List l = getAll(ContractMO.class);
30: List toDelete = new ArrayList();
31: for (Iterator i = l.iterator(); i.hasNext();) {
32: ContractMO contract = (ContractMO) i.next();
33: if (contract.getPerson().getId().equals(personId)) {
34: toDelete.add(contract);
35: }
36: }
37: getHibernateTemplate().deleteAll(toDelete);
38: }
39:
40: public void removeByCompanyId(Long companyId) {
41: List l = getAll(ContractMO.class);
42: List toDelete = new ArrayList();
43: for (Iterator i = l.iterator(); i.hasNext();) {
44: ContractMO contract = (ContractMO) i.next();
45: if (contract.getCompany().getId().equals(companyId)) {
46: toDelete.add(contract);
47: }
48: }
49: getHibernateTemplate().deleteAll(toDelete);
50: }
51: }
|