1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.dao.orm.hibernate;
16  
17  import com.liferay.portal.dao.orm.common.SQLTransformer;
18  import com.liferay.portal.kernel.dao.orm.LockMode;
19  import com.liferay.portal.kernel.dao.orm.ORMException;
20  import com.liferay.portal.kernel.dao.orm.Query;
21  import com.liferay.portal.kernel.dao.orm.SQLQuery;
22  import com.liferay.portal.kernel.dao.orm.Session;
23  
24  import java.io.Serializable;
25  
26  import java.sql.Connection;
27  
28  /**
29   * <a href="SessionImpl.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class SessionImpl implements Session {
34  
35      public SessionImpl(org.hibernate.Session session) {
36          _session = session;
37      }
38  
39      public void clear() throws ORMException {
40          try {
41              _session.clear();
42          }
43          catch (Exception e) {
44              throw ExceptionTranslator.translate(e);
45          }
46      }
47  
48      public Connection close() throws ORMException {
49          try {
50              return _session.close();
51          }
52          catch (Exception e) {
53              throw ExceptionTranslator.translate(e);
54          }
55      }
56  
57      public boolean contains(Object object) throws ORMException {
58          try {
59              return _session.contains(object);
60          }
61          catch (Exception e) {
62              throw ExceptionTranslator.translate(e);
63          }
64      }
65  
66      public Query createQuery(String queryString) throws ORMException {
67          try {
68              queryString = SQLTransformer.transform(queryString);
69  
70              return new QueryImpl(_session.createQuery(queryString));
71          }
72          catch (Exception e) {
73              throw ExceptionTranslator.translate(e);
74          }
75      }
76  
77      public SQLQuery createSQLQuery(String queryString)
78          throws ORMException {
79  
80          try {
81              queryString = SQLTransformer.transform(queryString);
82  
83              return new SQLQueryImpl(_session.createSQLQuery(queryString));
84          }
85          catch (Exception e) {
86              throw ExceptionTranslator.translate(e);
87          }
88      }
89  
90      public void delete(Object object) throws ORMException {
91          try {
92              _session.delete(object);
93          }
94          catch (Exception e) {
95              throw ExceptionTranslator.translate(e);
96          }
97      }
98  
99      public void evict(Object object) throws ORMException {
100         try {
101             _session.evict(object);
102         }
103         catch (Exception e) {
104             throw ExceptionTranslator.translate(e);
105         }
106     }
107 
108     public void flush() throws ORMException {
109         try {
110             _session.flush();
111         }
112         catch (Exception e) {
113             throw ExceptionTranslator.translate(e);
114         }
115     }
116 
117     public Object get(Class<?> clazz, Serializable id) throws ORMException {
118         try {
119             return _session.get(clazz, id);
120         }
121         catch (Exception e) {
122             throw ExceptionTranslator.translate(e);
123         }
124     }
125 
126     public Object get(Class<?> clazz, Serializable id, LockMode lockMode)
127         throws ORMException {
128 
129         try {
130             return _session.get(
131                 clazz, id, LockModeTranslator.translate(lockMode));
132         }
133         catch (Exception e) {
134             throw ExceptionTranslator.translate(e);
135         }
136     }
137 
138     public Object getWrappedSession() {
139         return _session;
140     }
141 
142     public Object load(Class<?> clazz, Serializable id) throws ORMException {
143         try {
144             return _session.load(clazz, id);
145         }
146         catch (Exception e) {
147             throw ExceptionTranslator.translate(e);
148         }
149     }
150 
151     public Object merge(Object object) throws ORMException {
152         try {
153             return _session.merge(object);
154         }
155         catch (Exception e) {
156             throw ExceptionTranslator.translate(e);
157         }
158     }
159 
160     public Serializable save(Object object) throws ORMException {
161         try {
162             return _session.save(object);
163         }
164         catch (Exception e) {
165             throw ExceptionTranslator.translate(e);
166         }
167     }
168 
169     public void saveOrUpdate(Object object) throws ORMException {
170         try {
171             _session.saveOrUpdate(object);
172         }
173         catch (Exception e) {
174             throw ExceptionTranslator.translate(e);
175         }
176     }
177 
178     private org.hibernate.Session _session;
179 
180 }