1 22 package org.jboss.ejb3.entity; 23 24 import java.io.Serializable ; 25 import java.sql.Connection ; 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 49 public class ExtendedHibernateSession implements Session, ExtendedPersistenceContext, Serializable 50 { 51 private String identity; 52 53 public ExtendedHibernateSession(String name) 54 { 55 this.identity = name; 56 } 57 58 public ExtendedHibernateSession() 59 { 60 } 61 62 public ManagedEntityManagerFactory getFactory() 63 { 64 throw new RuntimeException ("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 ("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 ("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 connection() 130 throws HibernateException 131 { 132 return getHibernateSession().connection(); 133 } 134 135 public Connection 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 connection) 148 throws HibernateException 149 { 150 getHibernateSession().reconnect(connection); 151 } 152 153 public Connection close() 154 throws HibernateException 155 { 156 throw new IllegalStateException ("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 getIdentifier(Object object) 182 throws HibernateException 183 { 184 return getHibernateSession().getIdentifier(object); 185 } 186 187 public boolean contains(Object object) 188 { 189 return getHibernateSession().contains(object); 190 } 191 192 public void evict(Object object) 193 throws HibernateException 194 { 195 getHibernateSession().evict(object); 196 } 197 198 public Object load(Class theClass, Serializable id, LockMode lockMode) 199 throws HibernateException 200 { 201 return getHibernateSession().load(theClass, id, lockMode); 202 } 203 204 public Object load(String entityName, Serializable id, LockMode lockMode) 205 throws HibernateException 206 { 207 return getHibernateSession().load(entityName, id, lockMode); 208 } 209 210 public Object load(Class theClass, Serializable id) 211 throws HibernateException 212 { 213 return getHibernateSession().load(theClass, id); 214 } 215 216 public Object load(String entityName, Serializable id) 217 throws HibernateException 218 { 219 return getHibernateSession().load(entityName, id); 220 } 221 222 public void load(Object object, Serializable id) 223 throws HibernateException 224 { 225 getHibernateSession().load(object, id); 226 } 227 228 public void replicate(Object object, ReplicationMode replicationMode) 229 throws HibernateException 230 { 231 getHibernateSession().replicate(object, replicationMode); 232 } 233 234 public void replicate(String entityName, Object object, ReplicationMode replicationMode) 235 throws HibernateException 236 { 237 getHibernateSession().replicate(entityName, object, replicationMode); 238 } 239 240 public Serializable save(Object object) 241 throws HibernateException 242 { 243 return getHibernateSession().save(object); 244 } 245 246 public Serializable save(String entityName, Object object) 247 throws HibernateException 248 { 249 return getHibernateSession().save(entityName, object); 250 } 251 252 public void saveOrUpdate(Object object) 253 throws HibernateException 254 { 255 getHibernateSession().saveOrUpdate(object); 256 } 257 258 public void saveOrUpdate(String entityName, Object object) 259 throws HibernateException 260 { 261 getHibernateSession().saveOrUpdate(entityName, object); 262 } 263 264 public void update(Object object) 265 throws HibernateException 266 { 267 getHibernateSession().update(object); 268 } 269 270 public void update(String entityName, Object object) 271 throws HibernateException 272 { 273 getHibernateSession().update(entityName, object); 274 } 275 276 public Object merge(Object object) 277 throws HibernateException 278 { 279 return getHibernateSession().merge(object); 280 } 281 282 public Object merge(String entityName, Object object) 283 throws HibernateException 284 { 285 return getHibernateSession().merge(entityName, object); 286 } 287 288 public void persist(Object object) 289 throws HibernateException 290 { 291 getHibernateSession().persist(object); 292 } 293 294 public void persist(String entityName, Object object) 295 throws HibernateException 296 { 297 getHibernateSession().persist(entityName, object); 298 } 299 300 public void delete(Object object) 301 throws HibernateException 302 { 303 getHibernateSession().delete(object); 304 } 305 306 public void delete(String entityName, Object object) 307 throws HibernateException 308 { 309 getHibernateSession().delete(entityName, object); 310 } 311 312 public void lock(Object object, LockMode lockMode) 313 throws HibernateException 314 { 315 getHibernateSession().lock(object, lockMode); 316 } 317 318 public void lock(String entityName, Object object, LockMode lockMode) 319 throws HibernateException 320 { 321 getHibernateSession().lock(entityName, object, lockMode); 322 } 323 324 public void refresh(Object object) 325 throws HibernateException 326 { 327 getHibernateSession().refresh(object); 328 } 329 330 public void refresh(Object object, LockMode lockMode) 331 throws HibernateException 332 { 333 getHibernateSession().refresh(object, lockMode); 334 } 335 336 public LockMode getCurrentLockMode(Object 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 persistentClass) 349 { 350 return getHibernateSession().createCriteria(persistentClass); 351 } 352 353 public Criteria createCriteria(Class persistentClass, String alias) 354 { 355 return getHibernateSession().createCriteria(persistentClass, alias); 356 } 357 358 public Criteria createCriteria(String entityName) 359 { 360 return getHibernateSession().createCriteria(entityName); 361 } 362 363 public Criteria createCriteria(String entityName, String alias) 364 { 365 return getHibernateSession().createCriteria(entityName, alias); 366 } 367 368 public Query createQuery(String queryString) 369 throws HibernateException 370 { 371 return getHibernateSession().createQuery(queryString); 372 } 373 374 public SQLQuery createSQLQuery(String queryString) 375 throws HibernateException 376 { 377 return getHibernateSession().createSQLQuery(queryString); 378 } 379 380 public Query createFilter(Object collection, String queryString) 381 throws HibernateException 382 { 383 return getHibernateSession().createFilter(collection, queryString); 384 } 385 386 public Query getNamedQuery(String 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 get(Class clazz, Serializable id) 398 throws HibernateException 399 { 400 return getHibernateSession().get(clazz, id); 401 } 402 403 public Object get(Class clazz, Serializable id, LockMode lockMode) 404 throws HibernateException 405 { 406 return getHibernateSession().get(clazz, id, lockMode); 407 } 408 409 public Object get(String entityName, Serializable id) 410 throws HibernateException 411 { 412 return getHibernateSession().get(entityName, id); 413 } 414 415 public Object get(String entityName, Serializable id, LockMode lockMode) 416 throws HibernateException 417 { 418 return getHibernateSession().get(entityName, id, lockMode); 419 } 420 421 public String getEntityName(Object object) 422 throws HibernateException 423 { 424 return getHibernateSession().getEntityName(object); 425 } 426 427 public Filter enableFilter(String filterName) 428 { 429 return getHibernateSession().enableFilter(filterName); 430 } 431 432 public Filter getEnabledFilter(String filterName) 433 { 434 return getHibernateSession().getEnabledFilter(filterName); 435 } 436 437 public void disableFilter(String filterName) 438 { 439 getHibernateSession().disableFilter(filterName); 440 } 441 442 public SessionStatistics getStatistics() 443 { 444 return getHibernateSession().getStatistics(); 445 } 446 447 public void setReadOnly(Object 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 |