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