001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.dao.orm.hibernate;
016    
017    import com.liferay.portal.dao.orm.common.SQLTransformer;
018    import com.liferay.portal.kernel.dao.orm.LockMode;
019    import com.liferay.portal.kernel.dao.orm.ORMException;
020    import com.liferay.portal.kernel.dao.orm.Query;
021    import com.liferay.portal.kernel.dao.orm.SQLQuery;
022    import com.liferay.portal.kernel.dao.orm.Session;
023    
024    import java.io.Serializable;
025    
026    import java.sql.Connection;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class SessionImpl implements Session {
032    
033            public SessionImpl(org.hibernate.Session session) {
034                    _session = session;
035            }
036    
037            public void clear() throws ORMException {
038                    try {
039                            _session.clear();
040                    }
041                    catch (Exception e) {
042                            throw ExceptionTranslator.translate(e);
043                    }
044            }
045    
046            public Connection close() throws ORMException {
047                    try {
048                            return _session.close();
049                    }
050                    catch (Exception e) {
051                            throw ExceptionTranslator.translate(e);
052                    }
053            }
054    
055            public boolean contains(Object object) throws ORMException {
056                    try {
057                            return _session.contains(object);
058                    }
059                    catch (Exception e) {
060                            throw ExceptionTranslator.translate(e);
061                    }
062            }
063    
064            public Query createQuery(String queryString) throws ORMException {
065                    try {
066                            queryString = SQLTransformer.transform(queryString);
067    
068                            return new QueryImpl(_session.createQuery(queryString));
069                    }
070                    catch (Exception e) {
071                            throw ExceptionTranslator.translate(e);
072                    }
073            }
074    
075            public SQLQuery createSQLQuery(String queryString)
076                    throws ORMException {
077    
078                    try {
079                            queryString = SQLTransformer.transform(queryString);
080    
081                            return new SQLQueryImpl(_session.createSQLQuery(queryString));
082                    }
083                    catch (Exception e) {
084                            throw ExceptionTranslator.translate(e);
085                    }
086            }
087    
088            public void delete(Object object) throws ORMException {
089                    try {
090                            _session.delete(object);
091                    }
092                    catch (Exception e) {
093                            throw ExceptionTranslator.translate(e);
094                    }
095            }
096    
097            public void evict(Object object) throws ORMException {
098                    try {
099                            _session.evict(object);
100                    }
101                    catch (Exception e) {
102                            throw ExceptionTranslator.translate(e);
103                    }
104            }
105    
106            public void flush() throws ORMException {
107                    try {
108                            _session.flush();
109                    }
110                    catch (Exception e) {
111                            throw ExceptionTranslator.translate(e);
112                    }
113            }
114    
115            public Object get(Class<?> clazz, Serializable id) throws ORMException {
116                    try {
117                            return _session.get(clazz, id);
118                    }
119                    catch (Exception e) {
120                            throw ExceptionTranslator.translate(e);
121                    }
122            }
123    
124            /**
125             * @deprecated
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 Object 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    }