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.dao.orm.common.SQLTransformer;
23  import com.liferay.portal.kernel.dao.orm.LockMode;
24  import com.liferay.portal.kernel.dao.orm.ORMException;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.SQLQuery;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  
29  import java.io.Serializable;
30  
31  import java.sql.Connection;
32  
33  /**
34   * <a href="SessionImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class SessionImpl implements Session {
40  
41      public SessionImpl(org.hibernate.Session session) {
42          _session = session;
43      }
44  
45      public void clear() throws ORMException {
46          try {
47              _session.clear();
48          }
49          catch (Exception e) {
50              throw ExceptionTranslator.translate(e);
51          }
52      }
53  
54      public Connection close() throws ORMException {
55          try {
56              return _session.close();
57          }
58          catch (Exception e) {
59              throw ExceptionTranslator.translate(e);
60          }
61      }
62  
63      public boolean contains(Object object) throws ORMException {
64          try {
65              return _session.contains(object);
66          }
67          catch (Exception e) {
68              throw ExceptionTranslator.translate(e);
69          }
70      }
71  
72      public Query createQuery(String queryString) throws ORMException {
73          try {
74              queryString = SQLTransformer.transform(queryString);
75  
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              queryString = SQLTransformer.transform(queryString);
88  
89              return new SQLQueryImpl(_session.createSQLQuery(queryString));
90          }
91          catch (Exception e) {
92              throw ExceptionTranslator.translate(e);
93          }
94      }
95  
96      public void delete(Object object) throws ORMException {
97          try {
98              _session.delete(object);
99          }
100         catch (Exception e) {
101             throw ExceptionTranslator.translate(e);
102         }
103     }
104 
105     public void evict(Object object) throws ORMException {
106         try {
107             _session.evict(object);
108         }
109         catch (Exception e) {
110             throw ExceptionTranslator.translate(e);
111         }
112     }
113 
114     public void flush() throws ORMException {
115         try {
116             _session.flush();
117         }
118         catch (Exception e) {
119             throw ExceptionTranslator.translate(e);
120         }
121     }
122 
123     public Object get(Class clazz, Serializable id) throws ORMException {
124         try {
125             return _session.get(clazz, id);
126         }
127         catch (Exception e) {
128             throw ExceptionTranslator.translate(e);
129         }
130     }
131 
132     public Object get(Class clazz, Serializable id, LockMode lockMode)
133         throws ORMException {
134 
135         try {
136             return _session.get(
137                 clazz, id, LockModeTranslator.translate(lockMode));
138         }
139         catch (Exception e) {
140             throw ExceptionTranslator.translate(e);
141         }
142     }
143 
144     public org.hibernate.Session getWrappedSession() {
145         return _session;
146     }
147 
148     public Object load(Class clazz, Serializable id) throws ORMException {
149         try {
150             return _session.load(clazz, id);
151         }
152         catch (Exception e) {
153             throw ExceptionTranslator.translate(e);
154         }
155     }
156 
157     public Object merge(Object object) throws ORMException {
158         try {
159             return _session.merge(object);
160         }
161         catch (Exception e) {
162             throw ExceptionTranslator.translate(e);
163         }
164     }
165 
166     public Serializable save(Object object) throws ORMException {
167         try {
168             return _session.save(object);
169         }
170         catch (Exception e) {
171             throw ExceptionTranslator.translate(e);
172         }
173     }
174 
175     public void saveOrUpdate(Object object) throws ORMException {
176         try {
177             _session.saveOrUpdate(object);
178         }
179         catch (Exception e) {
180             throw ExceptionTranslator.translate(e);
181         }
182     }
183 
184     private org.hibernate.Session _session;
185 
186 }