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.util.PortalClassLoaderUtil;
26  
27  import java.io.Serializable;
28  
29  import java.lang.Class;
30  import java.lang.Object;
31  import java.lang.String;
32  
33  import java.sql.Connection;
34  
35  import org.hibernate.CacheMode;
36  import org.hibernate.Criteria;
37  import org.hibernate.EntityMode;
38  import org.hibernate.Filter;
39  import org.hibernate.FlushMode;
40  import org.hibernate.HibernateException;
41  import org.hibernate.LockMode;
42  import org.hibernate.Query;
43  import org.hibernate.ReplicationMode;
44  import org.hibernate.SQLQuery;
45  import org.hibernate.Session;
46  import org.hibernate.SessionFactory;
47  import org.hibernate.Transaction;
48  import org.hibernate.jdbc.Work;
49  import org.hibernate.stat.SessionStatistics;
50  
51  /**
52   * <a href="LiferaySession.java.html"><b><i>View Source</i></b></a>
53   *
54   * <p>
55   * See http://support.liferay.com/browse/LEP-2996.
56   * </p>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   */
61  public class LiferaySession implements Session {
62  
63      public LiferaySession(Session session) {
64          _session = session;
65      }
66  
67      public Session getHibernateSession() {
68          return _session;
69      }
70  
71      public Transaction beginTransaction() throws HibernateException {
72          return _session.beginTransaction();
73      }
74  
75      public void cancelQuery() throws HibernateException {
76          _session.cancelQuery();
77      }
78  
79      public void clear() {
80          _session.clear();
81      }
82  
83      public Connection close() throws HibernateException {
84          return _session.close();
85      }
86  
87      /**
88       * @deprecated
89       */
90      public Connection connection() throws HibernateException {
91          Thread currentThread = Thread.currentThread();
92  
93          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
94  
95          try {
96              ClassLoader portalClassLoader =
97                  PortalClassLoaderUtil.getClassLoader();
98  
99              currentThread.setContextClassLoader(portalClassLoader);
100 
101             Connection connection = _session.connection();
102 
103             return connection;
104         }
105         finally {
106             currentThread.setContextClassLoader(contextClassLoader);
107         }
108     }
109 
110     public boolean contains(Object object) {
111         return _session.contains(object);
112     }
113 
114     public Criteria createCriteria(Class persistentClass) {
115         return _session.createCriteria(persistentClass);
116     }
117 
118     public Criteria createCriteria(Class persistentClass, String alias) {
119         return _session.createCriteria(persistentClass, alias);
120     }
121 
122     public Criteria createCriteria(String entityName) {
123         return _session.createCriteria(entityName);
124     }
125 
126     public Criteria createCriteria(String entityName, String alias) {
127         return _session.createCriteria(entityName, alias);
128     }
129 
130     public Query createFilter(Object collection, String queryString)
131         throws HibernateException {
132 
133         return _session.createFilter(collection, queryString);
134     }
135 
136     public Query createQuery(String queryString) throws HibernateException {
137         return _session.createQuery(queryString);
138     }
139 
140     public SQLQuery createSQLQuery(String queryString)
141         throws HibernateException {
142 
143         return _session.createSQLQuery(queryString);
144     }
145 
146     public void delete(Object object) throws HibernateException {
147         _session.delete(object);
148     }
149 
150     public void delete(String entityName, Object object)
151         throws HibernateException {
152 
153         _session.delete(entityName, object);
154     }
155 
156     public void disableFilter(String filterName) {
157         _session.disableFilter(filterName);
158     }
159 
160     public Connection disconnect() throws HibernateException {
161         return _session.disconnect();
162     }
163 
164     public void doWork(Work work) throws HibernateException {
165         _session.doWork(work);
166     }
167 
168     public Filter enableFilter(String filterName) {
169         return _session.enableFilter(filterName);
170     }
171 
172     public void evict(Object object) throws HibernateException {
173         _session.evict(object);
174     }
175 
176     public void flush() throws HibernateException {
177         _session.flush();
178     }
179 
180     public Object get(Class clazz, Serializable id) throws HibernateException {
181         return _session.get(clazz, id);
182     }
183 
184     public Object get(Class clazz, Serializable id, LockMode lockMode)
185         throws HibernateException {
186 
187         return _session.get(clazz, id, lockMode);
188     }
189 
190     public Object get(String entityName, Serializable id)
191         throws HibernateException {
192 
193         return _session.get(entityName, id);
194     }
195 
196     public Object get(String entityName, Serializable id, LockMode lockMode)
197         throws HibernateException {
198 
199         return _session.get(entityName, id, lockMode);
200     }
201 
202     public CacheMode getCacheMode() {
203         return _session.getCacheMode();
204     }
205 
206     public LockMode getCurrentLockMode(Object object)
207         throws HibernateException {
208 
209         return _session.getCurrentLockMode(object);
210     }
211 
212     public Filter getEnabledFilter(String filterName) {
213         return _session.getEnabledFilter(filterName);
214     }
215 
216     public EntityMode getEntityMode() {
217         return _session.getEntityMode();
218     }
219 
220     public String getEntityName(Object object) throws HibernateException {
221         return _session.getEntityName(object);
222     }
223 
224     public FlushMode getFlushMode() {
225         return _session.getFlushMode();
226     }
227 
228     public Serializable getIdentifier(Object object) throws HibernateException {
229         return _session.getIdentifier(object);
230     }
231 
232     public Query getNamedQuery(String queryName) throws HibernateException {
233         return _session.getNamedQuery(queryName);
234     }
235 
236     public Session getSession(EntityMode entityMode) {
237         return _session.getSession(entityMode);
238     }
239 
240     public SessionFactory getSessionFactory() {
241         return _session.getSessionFactory();
242     }
243 
244     public SessionStatistics getStatistics() {
245         return _session.getStatistics();
246     }
247 
248     public Transaction getTransaction() {
249         return _session.getTransaction();
250     }
251 
252     public boolean isConnected() {
253         return _session.isConnected();
254     }
255 
256     public boolean isDirty() throws HibernateException {
257         return _session.isDirty();
258     }
259 
260     public boolean isOpen() {
261         return _session.isOpen();
262     }
263 
264     public Object load(Class theClass, Serializable id, LockMode lockMode)
265         throws HibernateException {
266 
267         return _session.load(theClass, id, lockMode);
268     }
269 
270     public Object load(String entityName, Serializable id, LockMode lockMode)
271         throws HibernateException {
272 
273         return _session.load(entityName, id, lockMode);
274     }
275 
276     public Object load(Class theClass, Serializable id)
277         throws HibernateException {
278 
279         return _session.load(theClass, id);
280     }
281 
282     public Object load(String entityName, Serializable id)
283         throws HibernateException {
284 
285         return _session.load(entityName, id);
286     }
287 
288     public void load(Object object, Serializable id) throws HibernateException {
289         _session.load(object, id);
290     }
291 
292     public void lock(Object object, LockMode lockMode)
293         throws HibernateException {
294 
295         _session.lock(object, lockMode);
296     }
297 
298     public void lock(String entityName, Object object, LockMode lockMode)
299         throws HibernateException {
300 
301         _session.lock(entityName, object, lockMode);
302     }
303 
304     public Object merge(Object object) throws HibernateException {
305         return _session.merge(object);
306     }
307 
308     public Object merge(String entityName, Object object)
309         throws HibernateException {
310 
311         return _session.merge(entityName, object);
312     }
313 
314     public void persist(Object object) throws HibernateException {
315         _session.persist(object);
316     }
317 
318     public void persist(String entityName, Object object)
319         throws HibernateException {
320 
321         _session.persist(entityName, object);
322     }
323 
324     /**
325      * @deprecated
326      */
327     public void reconnect() throws HibernateException {
328         _session.reconnect();
329     }
330 
331     public void reconnect(Connection connection) throws HibernateException {
332         _session.reconnect(connection);
333     }
334 
335     public void refresh(Object object) throws HibernateException {
336         _session.refresh(object);
337     }
338 
339     public void refresh(Object object, LockMode lockMode)
340         throws HibernateException {
341 
342         _session.refresh(object, lockMode);
343     }
344 
345     public void replicate(Object object, ReplicationMode replicationMode)
346         throws HibernateException {
347 
348         _session.replicate(object, replicationMode);
349     }
350 
351     public void replicate(
352             String entityName, Object object, ReplicationMode replicationMode)
353         throws HibernateException {
354 
355         _session.replicate(entityName, object, replicationMode);
356     }
357 
358     public Serializable save(Object object) throws HibernateException {
359         return _session.save(object);
360     }
361 
362     public Serializable save(String entityName, Object object)
363         throws HibernateException {
364         return _session.save(entityName, object);
365     }
366 
367     public void saveOrUpdate(Object object) throws HibernateException {
368         _session.saveOrUpdate(object);
369     }
370 
371     public void saveOrUpdate(String entityName, Object object)
372         throws HibernateException {
373 
374         _session.saveOrUpdate(entityName, object);
375     }
376 
377     public void setCacheMode(CacheMode cacheMode) {
378         _session.setCacheMode(cacheMode);
379     }
380 
381     public void setFlushMode(FlushMode flushMode) {
382         _session.setFlushMode(flushMode);
383     }
384 
385     public void setReadOnly(Object entity, boolean readOnly) {
386         _session.setReadOnly(entity, readOnly);
387     }
388 
389     public void update(Object object) throws HibernateException {
390         _session.update(object);
391     }
392 
393     public void update(String entityName, Object object)
394         throws HibernateException {
395 
396         _session.update(entityName, object);
397     }
398 
399     private Session _session;
400 
401 }