KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > dao > AbstractDAO


1 /*
2  * $Id: AbstractDAO.java,v 1.1 2005/01/17 21:36:10 michelson Exp $
3  *
4  * Copyright (c) 2005 j2biz Group, http://www.j2biz.com Koeln / Duesseldorf ,
5  * Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License as published by the Free Software
12  * Foundation; either version 2 of the License, or (at your option) any later
13  * version.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License along with
21  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  * Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.dao;
27
28 import java.io.Serializable JavaDoc;
29
30 import net.sf.hibernate.HibernateException;
31 import net.sf.hibernate.Session;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 import com.j2biz.blogunity.util.HibernateUtil;
37
38 public abstract class AbstractDAO {
39     /**
40      * Logger for this class
41      */

42     private static final Log log = LogFactory.getLog(AbstractDAO.class);
43
44     public AbstractDAO() {
45
46         if (log.isDebugEnabled()) {
47             log.debug("Beginning Transcation...");
48         }
49
50         HibernateUtil.beginTransaction();
51     }
52
53     public Object JavaDoc getByID(Class JavaDoc clazz, Long JavaDoc id) throws HibernateException {
54         Session session = HibernateUtil.getSession();
55         return session.load(clazz, id);
56     }
57
58     protected void delete(Object JavaDoc o) throws HibernateException {
59         Session session = HibernateUtil.getSession();
60         session.delete(o);
61     }
62
63     protected void update(Object JavaDoc o) throws HibernateException {
64         Session session = HibernateUtil.getSession();
65         session.update(o);
66
67     }
68
69     protected Serializable JavaDoc create(Object JavaDoc o) throws HibernateException {
70         Session session = HibernateUtil.getSession();
71         return session.save(o);
72     }
73
74 }
Popular Tags