Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
33 | PointedEar | 1 | /* |
2 | * Hibernate, Relational Persistence for Idiomatic Java |
||
3 | * |
||
4 | * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as |
||
5 | * indicated by the @author tags or express copyright attribution |
||
6 | * statements applied by the authors. All third-party contributions are |
||
7 | * distributed under license by Red Hat Middleware LLC. |
||
8 | * |
||
9 | * This copyrighted material is made available to anyone wishing to use, modify, |
||
10 | * copy, or redistribute it subject to the terms and conditions of the GNU |
||
11 | * Lesser General Public License, as published by the Free Software Foundation. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
||
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
||
16 | * for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Lesser General Public License |
||
19 | * along with this distribution; if not, write to: |
||
20 | * Free Software Foundation, Inc. |
||
21 | * 51 Franklin Street, Fifth Floor |
||
22 | * Boston, MA 02110-1301 USA |
||
23 | * |
||
24 | */ |
||
25 | package org.hibernate; |
||
26 | |||
27 | import java.io.Serializable; |
||
28 | |||
29 | /** |
||
30 | * Defines the various policies by which Hibernate might release its underlying |
||
31 | * JDBC connection. |
||
32 | * |
||
33 | * @author Steve Ebersole |
||
34 | */ |
||
35 | public class ConnectionReleaseMode implements Serializable { |
||
36 | |||
37 | /** |
||
38 | * Indicates that JDBC connection should be aggressively released after each |
||
39 | * SQL statement is executed. In this mode, the application <em>must</em> |
||
40 | * explicitly close all iterators and scrollable results. This mode may |
||
41 | * only be used with a JTA datasource. |
||
42 | */ |
||
43 | public static final ConnectionReleaseMode AFTER_STATEMENT = new ConnectionReleaseMode( "after_statement" ); |
||
44 | |||
45 | /** |
||
46 | * Indicates that JDBC connections should be released after each transaction |
||
47 | * ends (works with both JTA-registered synch and HibernateTransaction API). |
||
48 | * This mode may not be used with an application server JTA datasource. |
||
49 | * <p/> |
||
50 | * This is the default mode starting in 3.1; was previously {@link #ON_CLOSE}. |
||
51 | */ |
||
52 | public static final ConnectionReleaseMode AFTER_TRANSACTION = new ConnectionReleaseMode( "after_transaction" ); |
||
53 | |||
54 | /** |
||
55 | * Indicates that connections should only be released when the Session is explicitly closed |
||
56 | * or disconnected; this is the legacy (Hibernate2 and pre-3.1) behavior. |
||
57 | */ |
||
58 | public static final ConnectionReleaseMode ON_CLOSE = new ConnectionReleaseMode( "on_close" ); |
||
59 | |||
60 | |||
61 | private String name; |
||
62 | |||
63 | private ConnectionReleaseMode(String name) { |
||
64 | this.name = name; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Override of Object.toString(). Returns the release mode name. |
||
69 | * |
||
70 | * @return The release mode name. |
||
71 | */ |
||
72 | public String toString() { |
||
73 | return name; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Determine the correct ConnectionReleaseMode instance based on the given |
||
78 | * name. |
||
79 | * |
||
80 | * @param modeName The release mode name. |
||
81 | * @return The appropriate ConnectionReleaseMode instance |
||
82 | * @throws HibernateException Indicates the modeName param did not match any known modes. |
||
83 | */ |
||
84 | public static ConnectionReleaseMode parse(String modeName) throws HibernateException { |
||
85 | if ( AFTER_STATEMENT.name.equals( modeName ) ) { |
||
86 | return AFTER_STATEMENT; |
||
87 | } |
||
88 | else if ( AFTER_TRANSACTION.name.equals( modeName ) ) { |
||
89 | return AFTER_TRANSACTION; |
||
90 | } |
||
91 | else if ( ON_CLOSE.name.equals( modeName ) ) { |
||
92 | return ON_CLOSE; |
||
93 | } |
||
94 | throw new HibernateException( "could not determine appropriate connection release mode [" + modeName + "]" ); |
||
95 | } |
||
96 | |||
97 | private Object readResolve() { |
||
98 | return parse( name ); |
||
99 | } |
||
100 | } |