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 org.hibernate.HibernateException;
014    import org.hibernate.SessionFactory;
015    import org.picocontainer.Startable;
016    
017    /**
018     * Component organising lifecycle for session factory.
019     * 
020     * @author Jose Peleteiro <juzepeleteiro@intelli.biz>
021     * @version $Revision: 2043 $
022     */
023    public class SessionFactoryLifecycle implements Startable {
024    
025        private SessionFactory sessionFactory;
026    
027        public SessionFactoryLifecycle(SessionFactory sessionFactory) {
028            this.sessionFactory = sessionFactory;
029        }
030    
031        public void start() {}
032    
033        public void stop() {
034            try {
035                sessionFactory.close();
036            } catch (HibernateException ex) {
037                // swallow it? not sure what to do with it...
038            }
039        }
040    }