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   */
42  public class SessionImpl implements Session {
43  
44      public SessionImpl(org.hibernate.Session session) {
45          _session = session;
46      }
47  
48      public void clear() throws ORMException {
49          try {
50              _session.clear();
51          }
52          catch (Exception e) {
53              throw ExceptionTranslator.translate(e);
54          }
55      }
56  
57      public Connection close() throws ORMException {
58          try {
59              return _session.close();
60          }
61          catch (Exception e) {
62              throw ExceptionTranslator.translate(e);
63          }
64      }
65  
66      public boolean contains(Object object) throws ORMException {
67          try {
68              return _session.contains(object);
69          }
70          catch (Exception e) {
71              throw ExceptionTranslator.translate(e);
72          }
73      }
74  
75      public Query createQuery(String queryString) throws ORMException {
76          try {
77              queryString = SQLTransformer.transform(queryString);
78  
79              return new QueryImpl(_session.createQuery(queryString));
80          }
81          catch (Exception e) {
82              throw ExceptionTranslator.translate(e);
83          }
84      }
85  
86      public SQLQuery createSQLQuery(String queryString)
87          throws ORMException {
88  
89          try {
90              queryString = SQLTransformer.transform(queryString);
91  
92              return new SQLQueryImpl(_session.createSQLQuery(queryString));
93          }
94          catch (Exception e) {
95              throw ExceptionTranslator.translate(e);
96          }
97      }
98  
99      public void delete(Object object) throws ORMException {
100         try {
101             _session.delete(object);
102         }
103         catch (Exception e) {
104             throw ExceptionTranslator.translate(e);
105         }
106     }
107 
108     public void evict(Object object) throws ORMException {
109         try {
110             _session.evict(object);
111         }
112         catch (Exception e) {
113             throw ExceptionTranslator.translate(e);
114         }
115     }
116 
117     public void flush() throws ORMException {
118         try {
119             _session.flush();
120         }
121         catch (Exception e) {
122             throw ExceptionTranslator.translate(e);
123         }
124     }
125 
126     public Object get(Class clazz, Serializable id) throws ORMException {
127         try {
128             return _session.get(clazz, id);
129         }
130         catch (Exception e) {
131             throw ExceptionTranslator.translate(e);
132         }
133     }
134 
135     public Object get(Class clazz, Serializable id, LockMode lockMode)
136         throws ORMException {
137 
138         try {
139             return _session.get(
140                 clazz, id, LockModeTranslator.translate(lockMode));
141         }
142         catch (Exception e) {
143             throw ExceptionTranslator.translate(e);
144         }
145     }
146 
147     public org.hibernate.Session getWrappedSession() {
148         return _session;
149     }
150 
151     public Object load(Class clazz, Serializable id) throws ORMException {
152         try {
153             return _session.load(clazz, id);
154         }
155         catch (Exception e) {
156             throw ExceptionTranslator.translate(e);
157         }
158     }
159 
160     public Object merge(Object object) throws ORMException {
161         try {
162             return _session.merge(object);
163         }
164         catch (Exception e) {
165             throw ExceptionTranslator.translate(e);
166         }
167     }
168 
169     public Serializable save(Object object) throws ORMException {
170         try {
171             return _session.save(object);
172         }
173         catch (Exception e) {
174             throw ExceptionTranslator.translate(e);
175         }
176     }
177 
178     public void saveOrUpdate(Object object) throws ORMException {
179         try {
180             _session.saveOrUpdate(object);
181         }
182         catch (Exception e) {
183             throw ExceptionTranslator.translate(e);
184         }
185     }
186 
187     private org.hibernate.Session _session;
188 
189 }