001    /*******************************************************************************
002     * Copyright (c) PicoContainer Organization. All rights reserved.
003     * ---------------------------------------------------------------------------
004     * The software in this package is published under the terms of the BSD style
005     * license a copy of which has been included with this distribution in the
006     * license.html file.
007     ******************************************************************************/
008    
009    package org.picocontainer.persistence.hibernate;
010    
011    import org.hibernate.Session;
012    import org.picocontainer.Startable;
013    
014    /**
015     * Adds lifecycle method to the delegate session.
016     * 
017     * @author Jose Peleteiro
018     */
019    public final class SessionLifecycle implements Startable {
020    
021        private final Session session;
022    
023        public SessionLifecycle(Session session) {
024            this.session = session;
025        }
026    
027        public void start() {
028        }
029    
030        public void stop() {
031            if (session != null) {
032                session.flush();
033                session.close();
034            }
035        }
036    
037    }