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    package org.nanocontainer.persistence.hibernate.classic;
011    
012    import java.io.Serializable;
013    import java.sql.Connection;
014    import java.util.Map;
015    import javax.naming.NamingException;
016    import javax.naming.Reference;
017    import net.sf.hibernate.cfg.Configuration;
018    import net.sf.hibernate.exception.SQLExceptionConverter;
019    import net.sf.hibernate.Databinder;
020    import net.sf.hibernate.HibernateException;
021    import net.sf.hibernate.Interceptor;
022    import net.sf.hibernate.metadata.ClassMetadata;
023    import net.sf.hibernate.metadata.CollectionMetadata;
024    import net.sf.hibernate.Session;
025    import net.sf.hibernate.SessionFactory;
026    import org.picocontainer.PicoInitializationException;
027    /** 
028     * delegates everything to session factory obtained from confiuration.
029     * this class is necessary because component adapters are really ugly when 
030     * it comes to scripting 
031     * 
032     * 
033     * @author Konstantin Pribluda
034     * @version $Revision: 2043 $ 
035     */
036    
037    public class SessionFactoryDelegator implements SessionFactory {
038        
039        private SessionFactory delegate;
040        
041        public SessionFactoryDelegator(Configuration configuration) {
042            try {
043                delegate = configuration.buildSessionFactory();
044            } catch(HibernateException ex) {
045                throw new PicoInitializationException(ex);
046            }
047        }
048        
049        public Session openSession(Connection connection) {
050            return delegate.openSession(connection);
051        }
052        
053        public Session openSession(Interceptor interceptor) throws HibernateException {
054            return  delegate.openSession(interceptor);
055        }
056        
057        
058        public Session openSession(Connection connection, Interceptor interceptor) {
059            return  delegate.openSession( connection,interceptor);
060        }
061        
062        public Session openSession() throws HibernateException {
063             return  delegate.openSession();
064        }
065        
066        public Databinder openDatabinder() throws HibernateException {
067            return delegate.openDatabinder();
068        }
069        
070        public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {
071            return delegate.getClassMetadata(persistentClass);
072        }
073        
074        public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {
075            return delegate.getCollectionMetadata(roleName);
076        }
077        
078        public Map getAllClassMetadata() throws HibernateException {
079            return delegate.getAllClassMetadata();
080        }
081        
082        public Map getAllCollectionMetadata() throws HibernateException {
083            return delegate.getAllCollectionMetadata();
084        }
085        
086        public void close() throws HibernateException {
087            try {
088                delegate.close();
089            } finally {
090                delegate = null;
091            }
092        }
093        
094        public void evict(Class persistentClass) throws HibernateException {
095            delegate.evict(persistentClass);
096        }
097        
098        public void evict(Class persistentClass, Serializable id) throws HibernateException {
099             delegate.evict(persistentClass,id);
100        }
101        
102        
103        public void evictCollection(String roleName) throws HibernateException {
104            delegate.evictCollection(roleName);
105        }
106        
107        public void evictCollection(String roleName, Serializable id) throws HibernateException {
108            delegate.evictCollection(roleName,id);
109        }
110        
111        
112        public void evictQueries() throws HibernateException {
113            delegate.evictQueries();
114        }
115        
116        public void evictQueries(String cacheRegion) throws HibernateException {
117            delegate.evictQueries(cacheRegion);
118        }
119        
120        public Reference getReference() throws NamingException {
121            return delegate.getReference();
122        }
123    
124            public SQLExceptionConverter getSQLExceptionConverter() {
125                    return delegate.getSQLExceptionConverter();
126            }
127    }