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