KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > entity > ExtendedHibernateSession


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.entity;
23
24 import java.io.Serializable JavaDoc;
25 import java.sql.Connection JavaDoc;
26 import javax.persistence.EntityManager;
27 import org.hibernate.CacheMode;
28 import org.hibernate.Criteria;
29 import org.hibernate.EntityMode;
30 import org.hibernate.Filter;
31 import org.hibernate.FlushMode;
32 import org.hibernate.HibernateException;
33 import org.hibernate.LockMode;
34 import org.hibernate.Query;
35 import org.hibernate.ReplicationMode;
36 import org.hibernate.SQLQuery;
37 import org.hibernate.Session;
38 import org.hibernate.SessionFactory;
39 import org.hibernate.Transaction;
40 import org.hibernate.ejb.HibernateEntityManager;
41 import org.hibernate.stat.SessionStatistics;
42 import org.jboss.ejb3.stateful.StatefulBeanContext;
43
44 /**
45  * Hibernate Session with a managed extended persistence context.
46  *
47  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
48  */

49 public class ExtendedHibernateSession implements Session, ExtendedPersistenceContext, Serializable JavaDoc
50 {
51    private String JavaDoc identity;
52
53    public ExtendedHibernateSession(String JavaDoc name)
54    {
55       this.identity = name;
56    }
57
58    public ExtendedHibernateSession()
59    {
60    }
61
62    public ManagedEntityManagerFactory getFactory()
63    {
64       throw new RuntimeException JavaDoc("NOT IMPLEMENTED");
65    }
66
67    public EntityManager getPersistenceContext()
68    {
69       StatefulBeanContext beanContext = StatefulBeanContext.currentBean.get();
70       EntityManager persistenceContext = beanContext.getExtendedPersistenceContext(identity);
71       if (persistenceContext == null)
72          throw new RuntimeException JavaDoc("Unable to determine persistenceContext: " + identity
73                                     + " in injected SFSB: " + beanContext.getContainer().getObjectName());
74       return persistenceContext;
75    }
76
77    public Session getHibernateSession()
78    {
79       EntityManager persistenceContext = getPersistenceContext();
80       if (persistenceContext instanceof HibernateEntityManager)
81       {
82          return ((HibernateEntityManager) persistenceContext).getSession();
83       }
84       throw new RuntimeException JavaDoc("ILLEGAL ACTION: Not a Hibernate persistence provider");
85    }
86
87
88    public EntityMode getEntityMode()
89    {
90       return getHibernateSession().getEntityMode();
91    }
92
93    public Session getSession(EntityMode entityMode)
94    {
95       return getHibernateSession().getSession(entityMode);
96    }
97
98    public void flush()
99    throws HibernateException
100    {
101       getHibernateSession().flush();
102    }
103
104    public void setFlushMode(FlushMode flushMode)
105    {
106       getHibernateSession().setFlushMode(flushMode);
107    }
108
109    public FlushMode getFlushMode()
110    {
111       return getHibernateSession().getFlushMode();
112    }
113
114    public void setCacheMode(CacheMode cacheMode)
115    {
116       getHibernateSession().setCacheMode(cacheMode);
117    }
118
119    public CacheMode getCacheMode()
120    {
121       return getHibernateSession().getCacheMode();
122    }
123
124    public SessionFactory getSessionFactory()
125    {
126       return getHibernateSession().getSessionFactory();
127    }
128
129    public Connection JavaDoc connection()
130    throws HibernateException
131    {
132       return getHibernateSession().connection();
133    }
134
135    public Connection JavaDoc disconnect()
136    throws HibernateException
137    {
138       return getHibernateSession().disconnect();
139    }
140
141    public void reconnect()
142    throws HibernateException
143    {
144       getHibernateSession().reconnect();
145    }
146
147    public void reconnect(Connection JavaDoc connection)
148    throws HibernateException
149    {
150       getHibernateSession().reconnect(connection);
151    }
152
153    public Connection JavaDoc close()
154    throws HibernateException
155    {
156       throw new IllegalStateException JavaDoc("It is illegal to close an injected Hibernate Session");
157    }
158
159    public void cancelQuery()
160    throws HibernateException
161    {
162       getHibernateSession().cancelQuery();
163    }
164
165    public boolean isOpen()
166    {
167       return getHibernateSession().isOpen();
168    }
169
170    public boolean isConnected()
171    {
172       return getHibernateSession().isConnected();
173    }
174
175    public boolean isDirty()
176    throws HibernateException
177    {
178       return getHibernateSession().isDirty();
179    }
180
181    public Serializable JavaDoc getIdentifier(Object JavaDoc object)
182    throws HibernateException
183    {
184       return getHibernateSession().getIdentifier(object);
185    }
186
187    public boolean contains(Object JavaDoc object)
188    {
189       return getHibernateSession().contains(object);
190    }
191
192    public void evict(Object JavaDoc object)
193    throws HibernateException
194    {
195       getHibernateSession().evict(object);
196    }
197
198    public Object JavaDoc load(Class JavaDoc theClass, Serializable JavaDoc id, LockMode lockMode)
199    throws HibernateException
200    {
201       return getHibernateSession().load(theClass, id, lockMode);
202    }
203
204    public Object JavaDoc load(String JavaDoc entityName, Serializable JavaDoc id, LockMode lockMode)
205    throws HibernateException
206    {
207       return getHibernateSession().load(entityName, id, lockMode);
208    }
209
210    public Object JavaDoc load(Class JavaDoc theClass, Serializable JavaDoc id)
211    throws HibernateException
212    {
213       return getHibernateSession().load(theClass, id);
214    }
215
216    public Object JavaDoc load(String JavaDoc entityName, Serializable JavaDoc id)
217    throws HibernateException
218    {
219       return getHibernateSession().load(entityName, id);
220    }
221
222    public void load(Object JavaDoc object, Serializable JavaDoc id)
223    throws HibernateException
224    {
225       getHibernateSession().load(object, id);
226    }
227
228    public void replicate(Object JavaDoc object, ReplicationMode replicationMode)
229    throws HibernateException
230    {
231       getHibernateSession().replicate(object, replicationMode);
232    }
233
234    public void replicate(String JavaDoc entityName, Object JavaDoc object, ReplicationMode replicationMode)
235    throws HibernateException
236    {
237       getHibernateSession().replicate(entityName, object, replicationMode);
238    }
239
240    public Serializable JavaDoc save(Object JavaDoc object)
241    throws HibernateException
242    {
243       return getHibernateSession().save(object);
244    }
245
246    public Serializable JavaDoc save(String JavaDoc entityName, Object JavaDoc object)
247    throws HibernateException
248    {
249       return getHibernateSession().save(entityName, object);
250    }
251
252    public void saveOrUpdate(Object JavaDoc object)
253    throws HibernateException
254    {
255       getHibernateSession().saveOrUpdate(object);
256    }
257
258    public void saveOrUpdate(String JavaDoc entityName, Object JavaDoc object)
259    throws HibernateException
260    {
261       getHibernateSession().saveOrUpdate(entityName, object);
262    }
263
264    public void update(Object JavaDoc object)
265    throws HibernateException
266    {
267       getHibernateSession().update(object);
268    }
269
270    public void update(String JavaDoc entityName, Object JavaDoc object)
271    throws HibernateException
272    {
273       getHibernateSession().update(entityName, object);
274    }
275
276    public Object JavaDoc merge(Object JavaDoc object)
277    throws HibernateException
278    {
279       return getHibernateSession().merge(object);
280    }
281
282    public Object JavaDoc merge(String JavaDoc entityName, Object JavaDoc object)
283    throws HibernateException
284    {
285       return getHibernateSession().merge(entityName, object);
286    }
287
288    public void persist(Object JavaDoc object)
289    throws HibernateException
290    {
291       getHibernateSession().persist(object);
292    }
293
294    public void persist(String JavaDoc entityName, Object JavaDoc object)
295    throws HibernateException
296    {
297       getHibernateSession().persist(entityName, object);
298    }
299
300    public void delete(Object JavaDoc object)
301    throws HibernateException
302    {
303       getHibernateSession().delete(object);
304    }
305
306    public void delete(String JavaDoc entityName, Object JavaDoc object)
307    throws HibernateException
308    {
309       getHibernateSession().delete(entityName, object);
310    }
311
312    public void lock(Object JavaDoc object, LockMode lockMode)
313    throws HibernateException
314    {
315       getHibernateSession().lock(object, lockMode);
316    }
317
318    public void lock(String JavaDoc entityName, Object JavaDoc object, LockMode lockMode)
319    throws HibernateException
320    {
321       getHibernateSession().lock(entityName, object, lockMode);
322    }
323
324    public void refresh(Object JavaDoc object)
325    throws HibernateException
326    {
327       getHibernateSession().refresh(object);
328    }
329
330    public void refresh(Object JavaDoc object, LockMode lockMode)
331    throws HibernateException
332    {
333       getHibernateSession().refresh(object, lockMode);
334    }
335
336    public LockMode getCurrentLockMode(Object JavaDoc object)
337    throws HibernateException
338    {
339       return getHibernateSession().getCurrentLockMode(object);
340    }
341
342    public Transaction beginTransaction()
343    throws HibernateException
344    {
345       return getHibernateSession().beginTransaction();
346    }
347
348    public Criteria createCriteria(Class JavaDoc persistentClass)
349    {
350       return getHibernateSession().createCriteria(persistentClass);
351    }
352
353    public Criteria createCriteria(Class JavaDoc persistentClass, String JavaDoc alias)
354    {
355       return getHibernateSession().createCriteria(persistentClass, alias);
356    }
357
358    public Criteria createCriteria(String JavaDoc entityName)
359    {
360       return getHibernateSession().createCriteria(entityName);
361    }
362
363    public Criteria createCriteria(String JavaDoc entityName, String JavaDoc alias)
364    {
365       return getHibernateSession().createCriteria(entityName, alias);
366    }
367
368    public Query createQuery(String JavaDoc queryString)
369    throws HibernateException
370    {
371       return getHibernateSession().createQuery(queryString);
372    }
373
374    public SQLQuery createSQLQuery(String JavaDoc queryString)
375    throws HibernateException
376    {
377       return getHibernateSession().createSQLQuery(queryString);
378    }
379
380    public Query createFilter(Object JavaDoc collection, String JavaDoc queryString)
381    throws HibernateException
382    {
383       return getHibernateSession().createFilter(collection, queryString);
384    }
385
386    public Query getNamedQuery(String JavaDoc queryName)
387    throws HibernateException
388    {
389       return getHibernateSession().getNamedQuery(queryName);
390    }
391
392    public void clear()
393    {
394       getHibernateSession().clear();
395    }
396
397    public Object JavaDoc get(Class JavaDoc clazz, Serializable JavaDoc id)
398    throws HibernateException
399    {
400       return getHibernateSession().get(clazz, id);
401    }
402
403    public Object JavaDoc get(Class JavaDoc clazz, Serializable JavaDoc id, LockMode lockMode)
404    throws HibernateException
405    {
406       return getHibernateSession().get(clazz, id, lockMode);
407    }
408
409    public Object JavaDoc get(String JavaDoc entityName, Serializable JavaDoc id)
410    throws HibernateException
411    {
412       return getHibernateSession().get(entityName, id);
413    }
414
415    public Object JavaDoc get(String JavaDoc entityName, Serializable JavaDoc id, LockMode lockMode)
416    throws HibernateException
417    {
418       return getHibernateSession().get(entityName, id, lockMode);
419    }
420
421    public String JavaDoc getEntityName(Object JavaDoc object)
422    throws HibernateException
423    {
424       return getHibernateSession().getEntityName(object);
425    }
426
427    public Filter enableFilter(String JavaDoc filterName)
428    {
429       return getHibernateSession().enableFilter(filterName);
430    }
431
432    public Filter getEnabledFilter(String JavaDoc filterName)
433    {
434       return getHibernateSession().getEnabledFilter(filterName);
435    }
436
437    public void disableFilter(String JavaDoc filterName)
438    {
439       getHibernateSession().disableFilter(filterName);
440    }
441
442    public SessionStatistics getStatistics()
443    {
444       return getHibernateSession().getStatistics();
445    }
446
447    public void setReadOnly(Object JavaDoc entity, boolean readOnly)
448    {
449       getHibernateSession().setReadOnly(entity, readOnly);
450    }
451
452    public Transaction getTransaction()
453    {
454       return getHibernateSession().getTransaction();
455    }
456
457 }
458
459
Popular Tags