1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class LiferaySession implements Session {
61  
62      public LiferaySession(Session session) {
63          _session = session;
64      }
65  
66      public Session getHibernateSession() {
67          return _session;
68      }
69  
70      public Transaction beginTransaction() throws HibernateException {
71          return _session.beginTransaction();
72      }
73  
74      public void cancelQuery() throws HibernateException {
75          _session.cancelQuery();
76      }
77  
78      public void clear() {
79          _session.clear();
80      }
81  
82      public Connection close() throws HibernateException {
83          return _session.close();
84      }
85  
86      /**
87       * @deprecated
88       */
89      public Connection connection() throws HibernateException {
90          Thread currentThread = Thread.currentThread();
91  
92          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
93  
94          try {
95              ClassLoader portalClassLoader =
96                  PortalClassLoaderUtil.getClassLoader();
97  
98              currentThread.setContextClassLoader(portalClassLoader);
99  
100             Connection connection = _session.connection();
101 
102             return connection;
103         }
104         finally {
105             currentThread.setContextClassLoader(contextClassLoader);
106         }
107     }
108 
109     public boolean contains(Object object) {
110         return _session.contains(object);
111     }
112 
113     public Criteria createCriteria(Class persistentClass) {
114         return _session.createCriteria(persistentClass);
115     }
116 
117     public Criteria createCriteria(Class persistentClass, String alias) {
118         return _session.createCriteria(persistentClass, alias);
119     }
120 
121     public Criteria createCriteria(String entityName) {
122         return _session.createCriteria(entityName);
123     }
124 
125     public Criteria createCriteria(String entityName, String alias) {
126         return _session.createCriteria(entityName, alias);
127     }
128 
129     public Query createFilter(Object collection, String queryString)
130         throws HibernateException {
131 
132         return _session.createFilter(collection, queryString);
133     }
134 
135     public Query createQuery(String queryString) throws HibernateException {
136         return _session.createQuery(queryString);
137     }
138 
139     public SQLQuery createSQLQuery(String queryString)
140         throws HibernateException {
141 
142         return _session.createSQLQuery(queryString);
143     }
144 
145     public void delete(Object object) throws HibernateException {
146         _session.delete(object);
147     }
148 
149     public void delete(String entityName, Object object)
150         throws HibernateException {
151 
152         _session.delete(entityName, object);
153     }
154 
155     public void disableFilter(String filterName) {
156         _session.disableFilter(filterName);
157     }
158 
159     public Connection disconnect() throws HibernateException {
160         return _session.disconnect();
161     }
162 
163     public void doWork(Work work) throws HibernateException {
164         _session.doWork(work);
165     }
166 
167     public Filter enableFilter(String filterName) {
168         return _session.enableFilter(filterName);
169     }
170 
171     public void evict(Object object) throws HibernateException {
172         _session.evict(object);
173     }
174 
175     public void flush() throws HibernateException {
176         _session.flush();
177     }
178 
179     public Object get(Class clazz, Serializable id) throws HibernateException {
180         return _session.get(clazz, id);
181     }
182 
183     public Object get(Class clazz, Serializable id, LockMode lockMode)
184         throws HibernateException {
185 
186         return _session.get(clazz, id, lockMode);
187     }
188 
189     public Object get(String entityName, Serializable id)
190         throws HibernateException {
191 
192         return _session.get(entityName, id);
193     }
194 
195     public Object get(String entityName, Serializable id, LockMode lockMode)
196         throws HibernateException {
197 
198         return _session.get(entityName, id, lockMode);
199     }
200 
201     public CacheMode getCacheMode() {
202         return _session.getCacheMode();
203     }
204 
205     public LockMode getCurrentLockMode(Object object)
206         throws HibernateException {
207 
208         return _session.getCurrentLockMode(object);
209     }
210 
211     public Filter getEnabledFilter(String filterName) {
212         return _session.getEnabledFilter(filterName);
213     }
214 
215     public EntityMode getEntityMode() {
216         return _session.getEntityMode();
217     }
218 
219     public String getEntityName(Object object) throws HibernateException {
220         return _session.getEntityName(object);
221     }
222 
223     public FlushMode getFlushMode() {
224         return _session.getFlushMode();
225     }
226 
227     public Serializable getIdentifier(Object object) throws HibernateException {
228         return _session.getIdentifier(object);
229     }
230 
231     public Query getNamedQuery(String queryName) throws HibernateException {
232         return _session.getNamedQuery(queryName);
233     }
234 
235     public Session getSession(EntityMode entityMode) {
236         return _session.getSession(entityMode);
237     }
238 
239     public SessionFactory getSessionFactory() {
240         return _session.getSessionFactory();
241     }
242 
243     public SessionStatistics getStatistics() {
244         return _session.getStatistics();
245     }
246 
247     public Transaction getTransaction() {
248         return _session.getTransaction();
249     }
250 
251     public boolean isConnected() {
252         return _session.isConnected();
253     }
254 
255     public boolean isDirty() throws HibernateException {
256         return _session.isDirty();
257     }
258 
259     public boolean isOpen() {
260         return _session.isOpen();
261     }
262 
263     public Object load(Class theClass, Serializable id, LockMode lockMode)
264         throws HibernateException {
265 
266         return _session.load(theClass, id, lockMode);
267     }
268 
269     public Object load(String entityName, Serializable id, LockMode lockMode)
270         throws HibernateException {
271 
272         return _session.load(entityName, id, lockMode);
273     }
274 
275     public Object load(Class theClass, Serializable id)
276         throws HibernateException {
277 
278         return _session.load(theClass, id);
279     }
280 
281     public Object load(String entityName, Serializable id)
282         throws HibernateException {
283 
284         return _session.load(entityName, id);
285     }
286 
287     public void load(Object object, Serializable id) throws HibernateException {
288         _session.load(object, id);
289     }
290 
291     public void lock(Object object, LockMode lockMode)
292         throws HibernateException {
293 
294         _session.lock(object, lockMode);
295     }
296 
297     public void lock(String entityName, Object object, LockMode lockMode)
298         throws HibernateException {
299 
300         _session.lock(entityName, object, lockMode);
301     }
302 
303     public Object merge(Object object) throws HibernateException {
304         return _session.merge(object);
305     }
306 
307     public Object merge(String entityName, Object object)
308         throws HibernateException {
309 
310         return _session.merge(entityName, object);
311     }
312 
313     public void persist(Object object) throws HibernateException {
314         _session.persist(object);
315     }
316 
317     public void persist(String entityName, Object object)
318         throws HibernateException {
319 
320         _session.persist(entityName, object);
321     }
322 
323     /**
324      * @deprecated
325      */
326     public void reconnect() throws HibernateException {
327         _session.reconnect();
328     }
329 
330     public void reconnect(Connection connection) throws HibernateException {
331         _session.reconnect(connection);
332     }
333 
334     public void refresh(Object object) throws HibernateException {
335         _session.refresh(object);
336     }
337 
338     public void refresh(Object object, LockMode lockMode)
339         throws HibernateException {
340 
341         _session.refresh(object, lockMode);
342     }
343 
344     public void replicate(Object object, ReplicationMode replicationMode)
345         throws HibernateException {
346 
347         _session.replicate(object, replicationMode);
348     }
349 
350     public void replicate(
351             String entityName, Object object, ReplicationMode replicationMode)
352         throws HibernateException {
353 
354         _session.replicate(entityName, object, replicationMode);
355     }
356 
357     public Serializable save(Object object) throws HibernateException {
358         return _session.save(object);
359     }
360 
361     public Serializable save(String entityName, Object object)
362         throws HibernateException {
363         return _session.save(entityName, object);
364     }
365 
366     public void saveOrUpdate(Object object) throws HibernateException {
367         _session.saveOrUpdate(object);
368     }
369 
370     public void saveOrUpdate(String entityName, Object object)
371         throws HibernateException {
372 
373         _session.saveOrUpdate(entityName, object);
374     }
375 
376     public void setCacheMode(CacheMode cacheMode) {
377         _session.setCacheMode(cacheMode);
378     }
379 
380     public void setFlushMode(FlushMode flushMode) {
381         _session.setFlushMode(flushMode);
382     }
383 
384     public void setReadOnly(Object entity, boolean readOnly) {
385         _session.setReadOnly(entity, readOnly);
386     }
387 
388     public void update(Object object) throws HibernateException {
389         _session.update(object);
390     }
391 
392     public void update(String entityName, Object object)
393         throws HibernateException {
394 
395         _session.update(entityName, object);
396     }
397 
398     private Session _session;
399 
400 }