View Javadoc

1   package org.controlhaus.hibernate;
2   
3   import net.sf.hibernate.HibernateException;
4   import net.sf.hibernate.Session;
5   import net.sf.hibernate.SessionFactory;
6   import net.sf.hibernate.Transaction;
7   
8   import org.apache.beehive.controls.api.bean.ControlInterface;
9   import org.apache.beehive.controls.api.properties.PropertySet;
10  
11  import java.lang.annotation.Retention;
12  import java.lang.annotation.RetentionPolicy;
13  import java.lang.annotation.Target;
14  import java.lang.annotation.ElementType;
15  
16  /***
17   * The HibernateControl allows easy session and transaction management
18   * between Beehive Controls and Hibernate.
19   * 
20   * Use the <code>ManagedTransactions</code> property on the HibernateControl 
21   * and transactions will be managed for you autmatically.  The transaction 
22   * will start at the first access to the session.
23   * 
24   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
25   * @since Oct 29, 2004
26   */
27  @ControlInterface
28  public interface HibernateControl
29  {
30      /***
31       * Get the Hibernate <code>SessionFactory</code>.
32       * @return
33       */
34      SessionFactory getSessionFactory();
35      
36      /***
37       * @return The session that is currently associated with this Thread.
38       * If there is no session yet, one will be created.
39       * @throws HibernateException
40       */
41      Session getSession() throws HibernateException;
42      
43      /***
44       * @return The transaction for the current session. If there is no 
45       * session or the control is not managing the transactions, it will
46       * return <code>null</code>.
47       */
48      Transaction getTransaction();
49      
50      /***
51       * Close the session for the current Thread. If there is no session
52       * it will fail gracefully and no exception is thrown.
53       * 
54       * @throws HibernateException
55       */
56      void closeSession() throws HibernateException;
57  
58      @PropertySet(prefix="ManagedTransactions")
59      @Target( {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD} )
60      @Retention(RetentionPolicy.RUNTIME)
61      public @interface ManagedTransactions
62      {
63          boolean value() default false;
64      }
65  }