2
* Hibernate, Relational Persistence for Idiomatic Java
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.
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.
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
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
25
package org.hibernate;
27
import java.io.Serializable;
28
import java.util.HashMap;
32
* Represents a flushing strategy. The flush process synchronizes
33
* database state with session state by detecting state changes
34
* and executing SQL statements.
36
* @see Session#setFlushMode(FlushMode)
37
* @see Query#setFlushMode(FlushMode)
38
* @see Criteria#setFlushMode(FlushMode)
42
public final class FlushMode implements Serializable {
43
private static final Map INSTANCES = new HashMap();
45
private final int level;
46
private final String name;
48
private FlushMode(int level, String name) {
53
public String toString() {
58
* The {@link Session} is never flushed unless {@link Session#flush}
59
* is explicitly called by the application. This mode is very
60
* efficient for read only transactions.
62
* @deprecated use {@link #MANUAL} instead.
64
public static final FlushMode NEVER = new FlushMode( 0, "NEVER" );
67
* The {@link Session} is only ever flushed when {@link Session#flush}
68
* is explicitly called by the application. This mode is very
69
* efficient for read only transactions.
71
public static final FlushMode MANUAL = new FlushMode( 0, "MANUAL" );
74
* The {@link Session} is flushed when {@link Transaction#commit}
77
public static final FlushMode COMMIT = new FlushMode(5, "COMMIT");
80
* The {@link Session} is sometimes flushed before query execution
81
* in order to ensure that queries never return stale state. This
82
* is the default flush mode.
84
public static final FlushMode AUTO = new FlushMode(10, "AUTO");
87
* The {@link Session} is flushed before every query. This is
88
* almost always unnecessary and inefficient.
90
public static final FlushMode ALWAYS = new FlushMode(20, "ALWAYS");
92
public boolean lessThan(FlushMode other) {
93
return this.level<other.level;
97
INSTANCES.put( NEVER.name, NEVER );
98
INSTANCES.put( MANUAL.name, MANUAL );
99
INSTANCES.put( AUTO.name, AUTO );
100
INSTANCES.put( ALWAYS.name, ALWAYS );
101
INSTANCES.put( COMMIT.name, COMMIT );
104
public static boolean isManualFlushMode(FlushMode mode) {
105
return MANUAL.level == mode.level;
108
private Object readResolve() {
109
return INSTANCES.get( name );
112
public static FlushMode parse(String name) {
113
return ( FlushMode ) INSTANCES.get( name );