001/*
002 * Copyright 2012 Atteo.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.atteo.moonshine.jpa;
017
018import java.util.Map;
019
020import javax.persistence.EntityManager;
021import javax.persistence.EntityManagerFactory;
022import javax.persistence.EntityTransaction;
023import javax.persistence.FlushModeType;
024import javax.persistence.LockModeType;
025import javax.persistence.Query;
026import javax.persistence.TypedQuery;
027import javax.persistence.criteria.CriteriaBuilder;
028import javax.persistence.criteria.CriteriaQuery;
029import javax.persistence.metamodel.Metamodel;
030
031public abstract class DelegatingEntityManager implements EntityManager {
032    protected abstract EntityManager getEntityManager();
033
034    @Override
035    public void persist(Object entity) {
036        getEntityManager().persist(entity);
037    }
038
039    @Override
040    public <T> T merge(T entity) {
041        return getEntityManager().merge(entity);
042    }
043
044    @Override
045    public void remove(Object entity) {
046        getEntityManager().remove(entity);
047    }
048
049    @Override
050    public <T> T find(Class<T> entityClass, Object primaryKey) {
051        return getEntityManager().find(entityClass, primaryKey);
052    }
053
054    @Override
055    public <T> T find(Class<T> entityClass, Object primaryKey, Map<String, Object> properties) {
056        return getEntityManager().find(entityClass, primaryKey, properties);
057    }
058
059    @Override
060    public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode) {
061        return getEntityManager().find(entityClass, primaryKey, lockMode);
062    }
063
064    @Override
065    public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode, Map<String, Object> properties) {
066        return getEntityManager().find(entityClass, primaryKey, lockMode, properties);
067    }
068
069    @Override
070    public <T> T getReference(Class<T> entityClass, Object primaryKey) {
071        return getEntityManager().getReference(entityClass, primaryKey);
072    }
073
074    @Override
075    public void flush() {
076        getEntityManager().flush();
077    }
078
079    @Override
080    public void setFlushMode(FlushModeType flushMode) {
081        getEntityManager().setFlushMode(flushMode);
082    }
083
084    @Override
085    public FlushModeType getFlushMode() {
086        return getEntityManager().getFlushMode();
087    }
088
089    @Override
090    public void lock(Object entity, LockModeType lockMode) {
091        getEntityManager().lock(entity, lockMode);
092    }
093
094    @Override
095    public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties) {
096        getEntityManager().lock(entity, lockMode, properties);
097    }
098
099    @Override
100    public void refresh(Object entity) {
101        getEntityManager().refresh(entity);
102    }
103
104    @Override
105    public void refresh(Object entity, Map<String, Object> properties) {
106        getEntityManager().refresh(entity, properties);
107    }
108
109    @Override
110    public void refresh(Object entity, LockModeType lockMode) {
111        getEntityManager().refresh(entity, lockMode);
112    }
113
114    @Override
115    public void refresh(Object entity, LockModeType lockMode, Map<String, Object> properties) {
116        getEntityManager().refresh(entity, lockMode, properties);
117    }
118
119    @Override
120    public void clear() {
121        getEntityManager().clear();
122    }
123
124    @Override
125    public void detach(Object entity) {
126        getEntityManager().detach(entity);
127    }
128
129    @Override
130    public boolean contains(Object entity) {
131        return getEntityManager().contains(entity);
132    }
133
134    @Override
135    public LockModeType getLockMode(Object entity) {
136        return getEntityManager().getLockMode(entity);
137    }
138
139    @Override
140    public void setProperty(String propertyName, Object value) {
141        getEntityManager().setProperty(propertyName, value);
142    }
143
144    @Override
145    public Map<String, Object> getProperties() {
146        return getEntityManager().getProperties();
147    }
148
149    @Override
150    public Query createQuery(String qlString) {
151        return getEntityManager().createQuery(qlString);
152    }
153
154    @Override
155    public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) {
156        return getEntityManager().createQuery(criteriaQuery);
157    }
158
159    @Override
160    public <T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass) {
161        return getEntityManager().createQuery(qlString, resultClass);
162    }
163
164    @Override
165    public Query createNamedQuery(String name) {
166        return getEntityManager().createNamedQuery(name);
167    }
168
169    @Override
170    public <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass) {
171        return getEntityManager().createNamedQuery(name, resultClass);
172    }
173
174    @Override
175    public Query createNativeQuery(String sqlString) {
176        return getEntityManager().createNativeQuery(sqlString);
177    }
178
179    @SuppressWarnings("rawtypes")
180    @Override
181    public Query createNativeQuery(String sqlString, Class resultClass) {
182        return getEntityManager().createNativeQuery(sqlString, resultClass);
183    }
184
185    @Override
186    public Query createNativeQuery(String sqlString, String resultSetMapping) {
187        return getEntityManager().createNativeQuery(sqlString, resultSetMapping);
188    }
189
190    @Override
191    public void joinTransaction() {
192        getEntityManager().joinTransaction();
193    }
194
195    @Override
196    public <T> T unwrap(Class<T> cls) {
197        return getEntityManager().unwrap(cls);
198    }
199
200    @Override
201    public Object getDelegate() {
202        return getEntityManager().getDelegate();
203    }
204
205    @Override
206    public void close() {
207        getEntityManager().close();
208    }
209
210    @Override
211    public boolean isOpen() {
212        return getEntityManager().isOpen();
213    }
214
215    @Override
216    public EntityTransaction getTransaction() {
217        return getEntityManager().getTransaction();
218    }
219
220    @Override
221    public EntityManagerFactory getEntityManagerFactory() {
222        return getEntityManager().getEntityManagerFactory();
223    }
224
225    @Override
226    public CriteriaBuilder getCriteriaBuilder() {
227        return getEntityManager().getCriteriaBuilder();
228    }
229
230    @Override
231    public Metamodel getMetamodel() {
232        return getEntityManager().getMetamodel();
233    }
234}