KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > ConnectionReleaseMode


1 // $Id: ConnectionReleaseMode.java,v 1.2 2005/05/03 23:44:14 oneovthafew Exp $
2
package org.hibernate;
3
4 import java.io.Serializable JavaDoc;
5
6 /**
7  * Defines the various policies by which Hibernate might release its underlying
8  * JDBC connection.
9  *
10  * @author Steve Ebersole
11  */

12 public class ConnectionReleaseMode implements Serializable JavaDoc {
13
14     /**
15      * Indicates that JDBC connection should be aggressively released after each
16      * SQL statement is executed. In this mode, the application <em>must</em>
17      * explicitly close all iterators and scrollable results. This mode may
18      * only be used with a JTA datasource.
19      */

20     public static final ConnectionReleaseMode AFTER_STATEMENT = new ConnectionReleaseMode( "after_statement" );
21
22     /**
23      * Indicates that JDBC connections should be released after each transaction
24      * ends (works with both JTA-registered synch and HibernateTransaction API).
25      * This mode may not be used with an application server JTA datasource.
26      */

27     public static final ConnectionReleaseMode AFTER_TRANSACTION = new ConnectionReleaseMode( "after_transaction" );
28
29     /**
30      * Indicates that connections should only be released when the Session is explicitly closed
31      * or disconnected; this is the default and legacy behavior.
32      */

33     public static final ConnectionReleaseMode ON_CLOSE = new ConnectionReleaseMode( "on_close" );
34
35
36     private String JavaDoc name;
37
38     private ConnectionReleaseMode(String JavaDoc name) {
39         this.name = name;
40     }
41
42     public String JavaDoc toString() {
43         return name;
44     }
45
46     public static ConnectionReleaseMode parse(String JavaDoc modeName) {
47         if ( AFTER_STATEMENT.name.equals( modeName ) ) {
48             return AFTER_STATEMENT;
49         }
50         else if ( AFTER_TRANSACTION.name.equals( modeName ) ) {
51             return AFTER_TRANSACTION;
52         }
53         // default is to release connections on close of the session (legacy behaviour).
54
return ON_CLOSE;
55     }
56
57     private Object JavaDoc readResolve() {
58         return parse( name );
59     }
60 }
61
Popular Tags