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