01: package com.technoetic.xplanner.db.hibernate;
02:
03: import java.io.Serializable;
04: import java.util.List;
05:
06: import net.sf.hibernate.Session;
07: import net.sf.hibernate.HibernateException;
08: import net.sf.hibernate.type.Type;
09: import org.springframework.orm.hibernate.HibernateOperations;
10:
11: /**
12: * User: Mateusz Prokopowicz
13: * Date: Apr 21, 2005
14: * Time: 11:18:09 AM
15: */
16: public class HibernateOperationsWrapper {
17: private Session session;
18: private HibernateOperations hibernateOperations;
19:
20: public HibernateOperationsWrapper(Session session) {
21: this .session = session;
22: }
23:
24: public HibernateOperationsWrapper(
25: HibernateOperations hibernateOperations) {
26: this .hibernateOperations = hibernateOperations;
27: }
28:
29: public Object load(Class theClass, Serializable id)
30: throws HibernateException {
31: if (session != null)
32: return session.load(theClass, id);
33: else
34: return hibernateOperations.load(theClass, id);
35: }
36:
37: public List find(String query, Object[] values, Type[] types)
38: throws HibernateException {
39: if (session != null)
40: return session.find(query, values, types);
41: else
42: return hibernateOperations.find(query, values, types);
43: }
44:
45: public Serializable save(Object object) throws HibernateException {
46: if (session != null)
47: return session.save(object);
48: else
49: return hibernateOperations.save(object);
50: }
51: }
|