1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.dao.orm.common.SQLTransformer;
26  import com.liferay.portal.kernel.dao.orm.LockMode;
27  import com.liferay.portal.kernel.dao.orm.ORMException;
28  import com.liferay.portal.kernel.dao.orm.Query;
29  import com.liferay.portal.kernel.dao.orm.SQLQuery;
30  import com.liferay.portal.kernel.dao.orm.Session;
31  
32  import java.io.Serializable;
33  
34  import java.sql.Connection;
35  
36  /**
37   * <a href="SessionImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class SessionImpl implements Session {
42  
43      public SessionImpl(org.hibernate.Session session) {
44          _session = session;
45      }
46  
47      public void clear() throws ORMException {
48          try {
49              _session.clear();
50          }
51          catch (Exception e) {
52              throw ExceptionTranslator.translate(e);
53          }
54      }
55  
56      public Connection close() throws ORMException {
57          try {
58              return _session.close();
59          }
60          catch (Exception e) {
61              throw ExceptionTranslator.translate(e);
62          }
63      }
64  
65      public boolean contains(Object object) throws ORMException {
66          try {
67              return _session.contains(object);
68          }
69          catch (Exception e) {
70              throw ExceptionTranslator.translate(e);
71          }
72      }
73  
74      public Query createQuery(String queryString) throws ORMException {
75          try {
76              queryString = SQLTransformer.transform(queryString);
77  
78              return new QueryImpl(_session.createQuery(queryString));
79          }
80          catch (Exception e) {
81              throw ExceptionTranslator.translate(e);
82          }
83      }
84  
85      public SQLQuery createSQLQuery(String queryString)
86          throws ORMException {
87  
88          try {
89              queryString = SQLTransformer.transform(queryString);
90  
91              return new SQLQueryImpl(_session.createSQLQuery(queryString));
92          }
93          catch (Exception e) {
94              throw ExceptionTranslator.translate(e);
95          }
96      }
97  
98      public void delete(Object object) throws ORMException {
99          try {
100             _session.delete(object);
101         }
102         catch (Exception e) {
103             throw ExceptionTranslator.translate(e);
104         }
105     }
106 
107     public void evict(Object object) throws ORMException {
108         try {
109             _session.evict(object);
110         }
111         catch (Exception e) {
112             throw ExceptionTranslator.translate(e);
113         }
114     }
115 
116     public void flush() throws ORMException {
117         try {
118             _session.flush();
119         }
120         catch (Exception e) {
121             throw ExceptionTranslator.translate(e);
122         }
123     }
124 
125     public Object get(Class<?> clazz, Serializable id) throws ORMException {
126         try {
127             return _session.get(clazz, id);
128         }
129         catch (Exception e) {
130             throw ExceptionTranslator.translate(e);
131         }
132     }
133 
134     public Object get(Class<?> clazz, Serializable id, LockMode lockMode)
135         throws ORMException {
136 
137         try {
138             return _session.get(
139                 clazz, id, LockModeTranslator.translate(lockMode));
140         }
141         catch (Exception e) {
142             throw ExceptionTranslator.translate(e);
143         }
144     }
145 
146     public Object getWrappedSession() {
147         return _session;
148     }
149 
150     public Object load(Class<?> clazz, Serializable id) throws ORMException {
151         try {
152             return _session.load(clazz, id);
153         }
154         catch (Exception e) {
155             throw ExceptionTranslator.translate(e);
156         }
157     }
158 
159     public Object merge(Object object) throws ORMException {
160         try {
161             return _session.merge(object);
162         }
163         catch (Exception e) {
164             throw ExceptionTranslator.translate(e);
165         }
166     }
167 
168     public Serializable save(Object object) throws ORMException {
169         try {
170             return _session.save(object);
171         }
172         catch (Exception e) {
173             throw ExceptionTranslator.translate(e);
174         }
175     }
176 
177     public void saveOrUpdate(Object object) throws ORMException {
178         try {
179             _session.saveOrUpdate(object);
180         }
181         catch (Exception e) {
182             throw ExceptionTranslator.translate(e);
183         }
184     }
185 
186     private org.hibernate.Session _session;
187 
188 }