|
14 | 14 | * and executing SQL statements.
|
15 | 15 | *
|
16 | 16 | * @see Session#setHibernateFlushMode
|
17 |
| - * @see org.hibernate.query.Query#setHibernateFlushMode |
| 17 | + * @see org.hibernate.query.CommonQueryContract#setHibernateFlushMode |
18 | 18 | *
|
19 | 19 | * @author Gavin King
|
20 | 20 | */
|
21 | 21 | public enum FlushMode {
|
22 | 22 | /**
|
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. |
26 | 26 | */
|
27 |
| - MANUAL( 0 ), |
| 27 | + MANUAL, |
28 | 28 |
|
29 | 29 | /**
|
30 | 30 | * The {@link Session} is flushed when {@link Transaction#commit}
|
31 | 31 | * is called.
|
32 | 32 | */
|
33 |
| - COMMIT(5 ), |
| 33 | + COMMIT, |
34 | 34 |
|
35 | 35 | /**
|
36 | 36 | * The {@link Session} is sometimes flushed before query execution
|
37 | 37 | * in order to ensure that queries never return stale state. This
|
38 | 38 | * is the default flush mode.
|
39 | 39 | */
|
40 |
| - AUTO(10 ), |
| 40 | + AUTO, |
41 | 41 |
|
42 | 42 | /**
|
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. |
45 | 45 | */
|
46 |
| - ALWAYS(20 ); |
47 |
| - |
48 |
| - private final int level; |
49 |
| - |
50 |
| - private FlushMode(int level) { |
51 |
| - this.level = level; |
52 |
| - } |
| 46 | + ALWAYS; |
53 | 47 |
|
54 | 48 | /**
|
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. |
58 | 50 | *
|
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 |
60 | 53 | */
|
61 | 54 | public boolean lessThan(FlushMode other) {
|
62 |
| - return this.level < other.level; |
| 55 | + return this.level() < other.level(); |
63 | 56 | }
|
64 | 57 |
|
65 | 58 | /**
|
66 |
| - * Checks to see if the given mode is the same as {@link #MANUAL}. |
| 59 | + * Interprets an external representation of a flush mode. |
67 | 60 | *
|
68 |
| - * @param mode The mode to check |
| 61 | + * @param externalName the name of a {@code FlushMode}, or of a |
| 62 | + * {@link jakarta.persistence.FlushModeType} |
69 | 63 | *
|
70 |
| - * @return true/false |
| 64 | + * @return a {@code FlushMode}, or null if the argument was null |
71 | 65 | *
|
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 |
89 | 67 | */
|
90 | 68 | public static FlushMode interpretExternalSetting(String externalName) {
|
91 | 69 | return FlushModeTypeHelper.interpretExternalSetting( externalName );
|
92 | 70 | }
|
| 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 | + } |
93 | 86 | }
|
0 commit comments