001 /*****************************************************************************
002 * Copyright (c) PicoContainer Organization. All rights reserved. *
003 * ------------------------------------------------------------------------- *
004 * The software in this package is published under the terms of the BSD *
005 * style license a copy of which has been included with this distribution in *
006 * the license.html file. *
007 * *
008 * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant *
009 *****************************************************************************/
010
011 package org.nanocontainer.persistence.hibernate;
012
013 import java.io.Serializable;
014 import java.sql.Connection;
015 import java.util.Map;
016
017 import javax.naming.NamingException;
018 import javax.naming.Reference;
019
020 import org.hibernate.HibernateException;
021 import org.hibernate.Interceptor;
022 import org.hibernate.SessionFactory;
023 import org.hibernate.cfg.Configuration;
024 import org.hibernate.classic.Session;
025 import org.hibernate.metadata.ClassMetadata;
026 import org.hibernate.metadata.CollectionMetadata;
027 import org.hibernate.stat.Statistics;
028 import org.picocontainer.PicoInitializationException;
029
030 /**
031 * Delegates everything to session factory obtained from confiuration. this class is necessary
032 * because component adapters are really ugly when it comes to scripting.
033 *
034 * @version $Id: SessionFactoryDelegator.java 2158 2005-07-08 02:13:36Z juze $
035 */
036 public class SessionFactoryDelegator implements SessionFactory {
037
038 private SessionFactory sessionFactory;
039
040 public SessionFactoryDelegator(Configuration configuration) {
041 try {
042 this.sessionFactory = configuration.buildSessionFactory();
043 } catch (HibernateException ex) {
044 throw new PicoInitializationException(ex);
045 }
046 }
047
048 public SessionFactory getDelegatedSessionFactory() {
049 return this.sessionFactory;
050 }
051
052 public void close() throws HibernateException {
053 this.getDelegatedSessionFactory().close();
054 }
055
056 public void evict(Class persistentClass) throws HibernateException {
057 this.getDelegatedSessionFactory().evict(persistentClass);
058 }
059
060 public void evict(Class persistentClass, Serializable id) throws HibernateException {
061 this.getDelegatedSessionFactory().evict(persistentClass, id);
062 }
063
064 public void evictCollection(String roleName) throws HibernateException {
065 this.getDelegatedSessionFactory().evictCollection(roleName);
066 }
067
068 public void evictCollection(String roleName, Serializable id) throws HibernateException {
069 this.getDelegatedSessionFactory().evictCollection(roleName, id);
070 }
071
072 public void evictEntity(String entityName) throws HibernateException {
073 this.getDelegatedSessionFactory().evictEntity(entityName);
074 }
075
076 public void evictEntity(String entityName, Serializable id) throws HibernateException {
077 this.getDelegatedSessionFactory().evictEntity(entityName, id);
078 }
079
080 public void evictQueries() throws HibernateException {
081 this.getDelegatedSessionFactory().evictQueries();
082 }
083
084 public void evictQueries(String cacheRegion) throws HibernateException {
085 this.getDelegatedSessionFactory().evictQueries(cacheRegion);
086 }
087
088 public Map getAllClassMetadata() throws HibernateException {
089 return this.getDelegatedSessionFactory().getAllClassMetadata();
090 }
091
092 public Map getAllCollectionMetadata() throws HibernateException {
093 return this.getDelegatedSessionFactory().getAllCollectionMetadata();
094 }
095
096 public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {
097 return this.getDelegatedSessionFactory().getClassMetadata(persistentClass);
098 }
099
100 public ClassMetadata getClassMetadata(String entityName) throws HibernateException {
101 return this.getDelegatedSessionFactory().getClassMetadata(entityName);
102 }
103
104 public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {
105 return this.getDelegatedSessionFactory().getCollectionMetadata(roleName);
106 }
107
108 public Session getCurrentSession() throws HibernateException {
109 return this.getDelegatedSessionFactory().getCurrentSession();
110 }
111
112 public Reference getReference() throws NamingException {
113 return this.getDelegatedSessionFactory().getReference();
114 }
115
116 public Statistics getStatistics() {
117 return this.getDelegatedSessionFactory().getStatistics();
118 }
119
120 public boolean isClosed() {
121 return this.getDelegatedSessionFactory().isClosed();
122 }
123
124 public Session openSession() throws HibernateException {
125 return this.getDelegatedSessionFactory().openSession();
126 }
127
128 public Session openSession(Connection connection) {
129 return this.getDelegatedSessionFactory().openSession(connection);
130 }
131
132 public Session openSession(Connection connection, Interceptor interceptor) {
133 return this.getDelegatedSessionFactory().openSession(connection, interceptor);
134 }
135
136 public Session openSession(Interceptor interceptor) throws HibernateException {
137 return this.getDelegatedSessionFactory().openSession(interceptor);
138 }
139
140 }