Skip to content

Commit 7f9f8e1

Browse files
committed
clean up FlushMode
1 parent 3fb6c1c commit 7f9f8e1

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

hibernate-core/src/main/java/org/hibernate/FlushMode.java

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,80 +14,73 @@
1414
* and executing SQL statements.
1515
*
1616
* @see Session#setHibernateFlushMode
17-
* @see org.hibernate.query.Query#setHibernateFlushMode
17+
* @see org.hibernate.query.CommonQueryContract#setHibernateFlushMode
1818
*
1919
* @author Gavin King
2020
*/
2121
public enum FlushMode {
2222
/**
23-
* The {@link Session} is only ever flushed when {@link Session#flush}
24-
* is explicitly called by the application. This mode is very
25-
* efficient for read only transactions.
23+
* The {@link Session} is only flushed when {@link Session#flush}
24+
* is called explicitly. This mode is very efficient for read-only
25+
* transactions.
2626
*/
27-
MANUAL( 0 ),
27+
MANUAL,
2828

2929
/**
3030
* The {@link Session} is flushed when {@link Transaction#commit}
3131
* is called.
3232
*/
33-
COMMIT(5 ),
33+
COMMIT,
3434

3535
/**
3636
* The {@link Session} is sometimes flushed before query execution
3737
* in order to ensure that queries never return stale state. This
3838
* is the default flush mode.
3939
*/
40-
AUTO(10 ),
40+
AUTO,
4141

4242
/**
43-
* The {@link Session} is flushed before every query. This is
44-
* almost always unnecessary and inefficient.
43+
* The {@link Session} is flushed before every query. This is almost
44+
* always unnecessary and inefficient.
4545
*/
46-
ALWAYS(20 );
47-
48-
private final int level;
49-
50-
private FlushMode(int level) {
51-
this.level = level;
52-
}
46+
ALWAYS;
5347

5448
/**
55-
* Checks to see if {@code this} flush mode is less than the given flush mode.
56-
*
57-
* @param other THe flush mode value to be checked against {@code this}
49+
* Compare this flush mode to the given flush mode.
5850
*
59-
* @return {@code true} indicates {@code other} is less than {@code this}; {@code false} otherwise
51+
* @return {@code true} if this flush mode flushes less often than
52+
* the given flush mode
6053
*/
6154
public boolean lessThan(FlushMode other) {
62-
return this.level < other.level;
55+
return this.level() < other.level();
6356
}
6457

6558
/**
66-
* Checks to see if the given mode is the same as {@link #MANUAL}.
59+
* Interprets an external representation of a flush mode.
6760
*
68-
* @param mode The mode to check
61+
* @param externalName the name of a {@code FlushMode}, or of a
62+
* {@link jakarta.persistence.FlushModeType}
6963
*
70-
* @return true/false
64+
* @return a {@code FlushMode}, or null if the argument was null
7165
*
72-
* @deprecated Just use equality check against {@link #MANUAL}. Legacy from before this was an enum
73-
*/
74-
@Deprecated
75-
public static boolean isManualFlushMode(FlushMode mode) {
76-
return MANUAL.level == mode.level;
77-
}
78-
79-
/**
80-
* Interprets an external representation of the flush mode. {@code null} is returned as {@code null}, otherwise
81-
* {@link FlushMode#valueOf(String)} is used with the upper-case version of the incoming value. An unknown,
82-
* non-null value results in a MappingException being thrown.
83-
*
84-
* @param externalName The external representation
85-
*
86-
* @return The interpreted FlushMode value.
87-
*
88-
* @throws MappingException Indicates an unrecognized external representation
66+
* @throws MappingException for an unrecognized external representation
8967
*/
9068
public static FlushMode interpretExternalSetting(String externalName) {
9169
return FlushModeTypeHelper.interpretExternalSetting( externalName );
9270
}
71+
72+
private int level() {
73+
switch (this) {
74+
case ALWAYS:
75+
return 20;
76+
case AUTO:
77+
return 10;
78+
case COMMIT:
79+
return 5;
80+
case MANUAL:
81+
return 0;
82+
default:
83+
throw new AssertionFailure("Impossible FlushMode");
84+
}
85+
}
9386
}

0 commit comments

Comments
 (0)