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.List;
18: import org.araneaframework.example.main.business.model.GeneralMO;
19: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
20:
21: /**
22: * This is general data access object. It can retrieve all objects by class, one
23: * object by Id and class, add or edit an object or remove an object by it's Id
24: * and class.
25: *
26: * @author Rein Raudjärv <reinra@ut.ee>
27: */
28: public class GeneralDAO extends HibernateDaoSupport implements
29: IGeneralDAO {
30:
31: /* implements @see org.araneaframework.example.main.business.data.IGeneralDAO#getById(java.lang.Class, java.lang.Long) */
32: public GeneralMO getById(Class clazz, Long id) {
33: return (GeneralMO) getHibernateTemplate().get(clazz, id);
34: }
35:
36: /* implements @see org.araneaframework.example.main.business.data.IGeneralDAO#getAll(java.lang.Class) */
37: public List getAll(Class clazz) {
38: return getHibernateTemplate().find("from " + clazz.getName());
39: }
40:
41: /* implements @see org.araneaframework.example.main.business.data.IGeneralDAO#add(org.araneaframework.example.main.business.model.GeneralMO) */
42: public Long add(GeneralMO object) {
43: getHibernateTemplate().save(object);
44: return object.getId();
45: }
46:
47: /* implements @see org.araneaframework.example.main.business.data.IGeneralDAO#edit(org.araneaframework.example.main.business.model.GeneralMO) */
48: public void edit(GeneralMO object) {
49: getHibernateTemplate().update(object);
50: }
51:
52: /* implements @see org.araneaframework.example.main.business.data.IGeneralDAO#remove(java.lang.Class, java.lang.Long) */
53: public void remove(Class clazz, Long id) {
54: getHibernateTemplate().delete(getById(clazz, id));
55: }
56: }
|