1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.dao.orm.hibernate;
21  
22  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
23  
24  import java.io.Serializable;
25  
26  import java.lang.Class;
27  import java.lang.Object;
28  import java.lang.String;
29  
30  import java.sql.Connection;
31  
32  import org.hibernate.CacheMode;
33  import org.hibernate.Criteria;
34  import org.hibernate.EntityMode;
35  import org.hibernate.Filter;
36  import org.hibernate.FlushMode;
37  import org.hibernate.HibernateException;
38  import org.hibernate.LockMode;
39  import org.hibernate.Query;
40  import org.hibernate.ReplicationMode;
41  import org.hibernate.SQLQuery;
42  import org.hibernate.Session;
43  import org.hibernate.SessionFactory;
44  import org.hibernate.Transaction;
45  import org.hibernate.stat.SessionStatistics;
46  
47  /**
48   * <a href="LiferaySession.java.html"><b><i>View Source</i></b></a>
49   *
50   * <p>
51   * See http://support.liferay.com/browse/LEP-2996.
52   * </p>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class LiferaySession implements Session {
58  
59      public LiferaySession(Session session) {
60          _session = session;
61      }
62  
63      public Session getHibernateSession() {
64          return _session;
65      }
66  
67      public Transaction beginTransaction() throws HibernateException {
68          return _session.beginTransaction();
69      }
70  
71      public void cancelQuery() throws HibernateException {
72          _session.cancelQuery();
73      }
74  
75      public void clear() {
76          _session.clear();
77      }
78  
79      public Connection close() throws HibernateException {
80          return _session.close();
81      }
82  
83      /**
84       * @deprecated
85       */
86      public Connection connection() throws HibernateException {
87          Thread currentThread = Thread.currentThread();
88  
89          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
90  
91          try {
92              ClassLoader portalClassLoader =
93                  PortalClassLoaderUtil.getClassLoader();
94  
95              currentThread.setContextClassLoader(portalClassLoader);
96  
97              Connection connection = _session.connection();
98  
99              return connection;
100         }
101         finally {
102             currentThread.setContextClassLoader(contextClassLoader);
103         }
104     }
105 
106     public boolean contains(Object object) {
107         return _session.contains(object);
108     }
109 
110     public Criteria createCriteria(Class persistentClass) {
111         return _session.createCriteria(persistentClass);
112     }
113 
114     public Criteria createCriteria(Class persistentClass, String alias) {
115         return _session.createCriteria(persistentClass, alias);
116     }
117 
118     public Criteria createCriteria(String entityName) {
119         return _session.createCriteria(entityName);
120     }
121 
122     public Criteria createCriteria(String entityName, String alias) {
123         return _session.createCriteria(entityName, alias);
124     }
125 
126     public Query createFilter(Object collection, String queryString)
127         throws HibernateException {
128 
129         return _session.createFilter(collection, queryString);
130     }
131 
132     public Query createQuery(String queryString) throws HibernateException {
133         return _session.createQuery(queryString);
134     }
135 
136     public SQLQuery createSQLQuery(String queryString)
137         throws HibernateException {
138 
139         return _session.createSQLQuery(queryString);
140     }
141 
142     public void delete(Object object) throws HibernateException {
143         _session.delete(object);
144     }
145 
146     public void delete(String entityName, Object object)
147         throws HibernateException {
148 
149         _session.delete(entityName, object);
150     }
151 
152     public void disableFilter(String filterName) {
153         _session.disableFilter(filterName);
154     }
155 
156     public Connection disconnect() throws HibernateException {
157         return _session.disconnect();
158     }
159 
160     public Filter enableFilter(String filterName) {
161         return _session.enableFilter(filterName);
162     }
163 
164     public void evict(Object object) throws HibernateException {
165         _session.evict(object);
166     }
167 
168     public void flush() throws HibernateException {
169         _session.flush();
170     }
171 
172     public Object get(Class clazz, Serializable id) throws HibernateException {
173         return _session.get(clazz, id);
174     }
175 
176     public Object get(Class clazz, Serializable id, LockMode lockMode)
177         throws HibernateException {
178 
179         return _session.get(clazz, id, lockMode);
180     }
181 
182     public Object get(String entityName, Serializable id)
183         throws HibernateException {
184 
185         return _session.get(entityName, id);
186     }
187 
188     public Object get(String entityName, Serializable id, LockMode lockMode)
189         throws HibernateException {
190 
191         return _session.get(entityName, id, lockMode);
192     }
193 
194     public CacheMode getCacheMode() {
195         return _session.getCacheMode();
196     }
197 
198     public LockMode getCurrentLockMode(Object object)
199         throws HibernateException {
200 
201         return _session.getCurrentLockMode(object);
202     }
203 
204     public Filter getEnabledFilter(String filterName) {
205         return _session.getEnabledFilter(filterName);
206     }
207 
208     public EntityMode getEntityMode() {
209         return _session.getEntityMode();
210     }
211 
212     public String getEntityName(Object object) throws HibernateException {
213         return _session.getEntityName(object);
214     }
215 
216     public FlushMode getFlushMode() {
217         return _session.getFlushMode();
218     }
219 
220     public Serializable getIdentifier(Object object) throws HibernateException {
221         return _session.getIdentifier(object);
222     }
223 
224     public Query getNamedQuery(String queryName) throws HibernateException {
225         return _session.getNamedQuery(queryName);
226     }
227 
228     public Session getSession(EntityMode entityMode) {
229         return _session.getSession(entityMode);
230     }
231 
232     public SessionFactory getSessionFactory() {
233         return _session.getSessionFactory();
234     }
235 
236     public SessionStatistics getStatistics() {
237         return _session.getStatistics();
238     }
239 
240     public Transaction getTransaction() {
241         return _session.getTransaction();
242     }
243 
244     public boolean isConnected() {
245         return _session.isConnected();
246     }
247 
248     public boolean isDirty() throws HibernateException {
249         return _session.isDirty();
250     }
251 
252     public boolean isOpen() {
253         return _session.isOpen();
254     }
255 
256     public Object load(Class theClass, Serializable id, LockMode lockMode)
257         throws HibernateException {
258 
259         return _session.load(theClass, id, lockMode);
260     }
261 
262     public Object load(String entityName, Serializable id, LockMode lockMode)
263         throws HibernateException {
264 
265         return _session.load(entityName, id, lockMode);
266     }
267 
268     public Object load(Class theClass, Serializable id)
269         throws HibernateException {
270 
271         return _session.load(theClass, id);
272     }
273 
274     public Object load(String entityName, Serializable id)
275         throws HibernateException {
276 
277         return _session.load(entityName, id);
278     }
279 
280     public void load(Object object, Serializable id) throws HibernateException {
281         _session.load(object, id);
282     }
283 
284     public void lock(Object object, LockMode lockMode)
285         throws HibernateException {
286 
287         _session.lock(object, lockMode);
288     }
289 
290     public void lock(String entityName, Object object, LockMode lockMode)
291         throws HibernateException {
292 
293         _session.lock(entityName, object, lockMode);
294     }
295 
296     public Object merge(Object object) throws HibernateException {
297         return _session.merge(object);
298     }
299 
300     public Object merge(String entityName, Object object)
301         throws HibernateException {
302 
303         return _session.merge(entityName, object);
304     }
305 
306     public void persist(Object object) throws HibernateException {
307         _session.persist(object);
308     }
309 
310     public void persist(String entityName, Object object)
311         throws HibernateException {
312 
313         _session.persist(entityName, object);
314     }
315 
316     /**
317      * @deprecated
318      */
319     public void reconnect() throws HibernateException {
320         _session.reconnect();
321     }
322 
323     public void reconnect(Connection connection) throws HibernateException {
324         _session.reconnect(connection);
325     }
326 
327     public void refresh(Object object) throws HibernateException {
328         _session.refresh(object);
329     }
330 
331     public void refresh(Object object, LockMode lockMode)
332         throws HibernateException {
333 
334         _session.refresh(object, lockMode);
335     }
336 
337     public void replicate(Object object, ReplicationMode replicationMode)
338         throws HibernateException {
339 
340         _session.replicate(object, replicationMode);
341     }
342 
343     public void replicate(
344             String entityName, Object object, ReplicationMode replicationMode)
345         throws HibernateException {
346 
347         _session.replicate(entityName, object, replicationMode);
348     }
349 
350     public Serializable save(Object object) throws HibernateException {
351         return _session.save(object);
352     }
353 
354     public Serializable save(String entityName, Object object)
355         throws HibernateException {
356         return _session.save(entityName, object);
357     }
358 
359     public void saveOrUpdate(Object object) throws HibernateException {
360         _session.saveOrUpdate(object);
361     }
362 
363     public void saveOrUpdate(String entityName, Object object)
364         throws HibernateException {
365 
366         _session.saveOrUpdate(entityName, object);
367     }
368 
369     public void setCacheMode(CacheMode cacheMode) {
370         _session.setCacheMode(cacheMode);
371     }
372 
373     public void setFlushMode(FlushMode flushMode) {
374         _session.setFlushMode(flushMode);
375     }
376 
377     public void setReadOnly(Object entity, boolean readOnly) {
378         _session.setReadOnly(entity, readOnly);
379     }
380 
381     public void update(Object object) throws HibernateException {
382         _session.update(object);
383     }
384 
385     public void update(String entityName, Object object)
386         throws HibernateException {
387 
388         _session.update(entityName, object);
389     }
390 
391     private Session _session;
392 
393 }