1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.dao.orm.hibernate;
24  
25  import com.liferay.portal.kernel.dao.orm.LockMode;
26  import com.liferay.portal.kernel.dao.orm.ORMException;
27  import com.liferay.portal.kernel.dao.orm.Query;
28  import com.liferay.portal.kernel.dao.orm.SQLQuery;
29  import com.liferay.portal.kernel.dao.orm.Session;
30  
31  import java.io.Serializable;
32  
33  import java.sql.Connection;
34  
35  /**
36   * <a href="SessionImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class SessionImpl implements Session {
42  
43      public SessionImpl(org.hibernate.Session session) {
44          _session = session;
45      }
46  
47      public void clear() throws ORMException {
48          try {
49              _session.clear();
50          }
51          catch (Exception e) {
52              throw ExceptionTranslator.translate(e);
53          }
54      }
55  
56      public Connection close() throws ORMException {
57          try {
58              return _session.close();
59          }
60          catch (Exception e) {
61              throw ExceptionTranslator.translate(e);
62          }
63      }
64  
65      public boolean contains(Object object) throws ORMException {
66          try {
67              return _session.contains(object);
68          }
69          catch (Exception e) {
70              throw ExceptionTranslator.translate(e);
71          }
72      }
73  
74      public Query createQuery(String queryString) throws ORMException {
75          try {
76              return new QueryImpl(_session.createQuery(queryString));
77          }
78          catch (Exception e) {
79              throw ExceptionTranslator.translate(e);
80          }
81      }
82  
83      public SQLQuery createSQLQuery(String queryString)
84          throws ORMException {
85  
86          try {
87              return new SQLQueryImpl(_session.createSQLQuery(queryString));
88          }
89          catch (Exception e) {
90              throw ExceptionTranslator.translate(e);
91          }
92      }
93  
94      public void delete(Object object) throws ORMException {
95          try {
96              _session.delete(object);
97          }
98          catch (Exception e) {
99              throw ExceptionTranslator.translate(e);
100         }
101     }
102 
103     public void evict(Object object) throws ORMException {
104         try {
105             _session.evict(object);
106         }
107         catch (Exception e) {
108             throw ExceptionTranslator.translate(e);
109         }
110     }
111 
112     public void flush() throws ORMException {
113         try {
114             _session.flush();
115         }
116         catch (Exception e) {
117             throw ExceptionTranslator.translate(e);
118         }
119     }
120 
121     public Object get(Class clazz, Serializable id) throws ORMException {
122         try {
123             return _session.get(clazz, id);
124         }
125         catch (Exception e) {
126             throw ExceptionTranslator.translate(e);
127         }
128     }
129 
130     public Object get(Class clazz, Serializable id, LockMode lockMode)
131         throws ORMException {
132 
133         try {
134             return _session.get(
135                 clazz, id, LockModeTranslator.translate(lockMode));
136         }
137         catch (Exception e) {
138             throw ExceptionTranslator.translate(e);
139         }
140     }
141 
142     public org.hibernate.Session getWrappedSession() {
143         return _session;
144     }
145 
146     public Object load(Class clazz, Serializable id) throws ORMException {
147         try {
148             return _session.load(clazz, id);
149         }
150         catch (Exception e) {
151             throw ExceptionTranslator.translate(e);
152         }
153     }
154 
155     public Object merge(Object object) throws ORMException {
156         try {
157             return _session.merge(object);
158         }
159         catch (Exception e) {
160             throw ExceptionTranslator.translate(e);
161         }
162     }
163 
164     public Serializable save(Object object) throws ORMException {
165         try {
166             return _session.save(object);
167         }
168         catch (Exception e) {
169             throw ExceptionTranslator.translate(e);
170         }
171     }
172 
173     public void saveOrUpdate(Object object) throws ORMException {
174         try {
175             _session.saveOrUpdate(object);
176         }
177         catch (Exception e) {
178             throw ExceptionTranslator.translate(e);
179         }
180     }
181 
182     private org.hibernate.Session _session;
183 
184 }