modernize code in GraphSemantic and ExecuteUpdateResultCheckStyle

This commit is contained in:
Gavin King 2024-10-18 22:24:43 +02:00
parent 3d3561ff7e
commit 0ba7aec32d
2 changed files with 45 additions and 80 deletions

View File

@ -52,29 +52,19 @@ public enum ExecuteUpdateResultCheckStyle {
PARAM; PARAM;
public String externalName() { public String externalName() {
switch (this) { return switch ( this ) {
case NONE: case NONE -> "none";
return "none"; case COUNT -> "rowcount";
case COUNT: case PARAM -> "param";
return "rowcount"; };
case PARAM:
return "param";
default:
throw new AssertionFailure("Unrecognized ExecuteUpdateResultCheckStyle");
}
} }
public static @Nullable ExecuteUpdateResultCheckStyle fromResultCheckStyle(ResultCheckStyle style) { public static ExecuteUpdateResultCheckStyle fromResultCheckStyle(ResultCheckStyle style) {
switch (style) { return switch ( style ) {
case NONE: case NONE -> NONE;
return NONE; case COUNT -> COUNT;
case COUNT: case PARAM -> PARAM;
return COUNT; };
case PARAM:
return PARAM;
default:
return null;
}
} }
public static @Nullable ExecuteUpdateResultCheckStyle fromExternalName(String name) { public static @Nullable ExecuteUpdateResultCheckStyle fromExternalName(String name) {
@ -92,28 +82,18 @@ public enum ExecuteUpdateResultCheckStyle {
} }
public Supplier<? extends Expectation> expectationConstructor() { public Supplier<? extends Expectation> expectationConstructor() {
switch (this) { return switch ( this ) {
case NONE: case NONE -> Expectation.None::new;
return Expectation.None::new; case COUNT -> Expectation.RowCount::new;
case COUNT: case PARAM -> Expectation.OutParameter::new;
return Expectation.RowCount::new; };
case PARAM:
return Expectation.OutParameter::new;
default:
throw new AssertionFailure( "Unrecognized ExecuteUpdateResultCheckStyle");
}
} }
public Class<? extends Expectation> expectationClass() { public Class<? extends Expectation> expectationClass() {
switch (this) { return switch ( this ) {
case NONE: case NONE -> Expectation.None.class;
return Expectation.None.class; case COUNT -> Expectation.RowCount.class;
case COUNT: case PARAM -> Expectation.OutParameter.class;
return Expectation.RowCount.class; };
case PARAM:
return Expectation.OutParameter.class;
default:
throw new AssertionFailure( "Unrecognized ExecuteUpdateResultCheckStyle");
}
} }
} }

View File

@ -6,8 +6,6 @@ package org.hibernate.graph;
import java.util.Locale; import java.util.Locale;
import org.hibernate.AssertionFailure;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH; import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOAD_GRAPH; import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOAD_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH; import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
@ -49,14 +47,10 @@ public enum GraphSemantic {
* @see org.hibernate.jpa.SpecHints#HINT_SPEC_LOAD_GRAPH * @see org.hibernate.jpa.SpecHints#HINT_SPEC_LOAD_GRAPH
*/ */
public String getJakartaHintName() { public String getJakartaHintName() {
switch ( this ) { return switch ( this ) {
case FETCH: case FETCH -> HINT_SPEC_FETCH_GRAPH;
return HINT_SPEC_FETCH_GRAPH; case LOAD -> HINT_SPEC_LOAD_GRAPH;
case LOAD: };
return HINT_SPEC_LOAD_GRAPH;
default:
throw new AssertionFailure( "unknown GraphSemantic" );
}
} }
/** /**
@ -69,30 +63,21 @@ public enum GraphSemantic {
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public String getJpaHintName() { public String getJpaHintName() {
switch ( this ) { return switch ( this ) {
case FETCH: case FETCH -> HINT_JAVAEE_FETCH_GRAPH;
return HINT_JAVAEE_FETCH_GRAPH; case LOAD -> HINT_JAVAEE_LOAD_GRAPH;
case LOAD: };
return HINT_JAVAEE_LOAD_GRAPH;
default:
throw new AssertionFailure( "unknown GraphSemantic" );
}
} }
public static GraphSemantic fromHintName(String hintName) { public static GraphSemantic fromHintName(String hintName) {
switch ( hintName ) { return switch ( hintName ) {
case HINT_SPEC_FETCH_GRAPH: case HINT_SPEC_FETCH_GRAPH, HINT_JAVAEE_FETCH_GRAPH -> FETCH;
case HINT_JAVAEE_FETCH_GRAPH: case HINT_SPEC_LOAD_GRAPH, HINT_JAVAEE_LOAD_GRAPH -> LOAD;
return FETCH; default -> throw new IllegalArgumentException(
case HINT_SPEC_LOAD_GRAPH:
case HINT_JAVAEE_LOAD_GRAPH:
return LOAD;
default:
throw new IllegalArgumentException(
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Unknown EntityGraph hint name - `%s`. " + "Unknown EntityGraph hint name - `%s`. "
"Expecting `%s` or `%s` (or `%s` and `%s`).", + "Expecting `%s` or `%s` (or `%s` and `%s`).",
hintName, hintName,
HINT_SPEC_FETCH_GRAPH, HINT_SPEC_FETCH_GRAPH,
HINT_SPEC_LOAD_GRAPH, HINT_SPEC_LOAD_GRAPH,
@ -100,7 +85,7 @@ public enum GraphSemantic {
HINT_JAVAEE_LOAD_GRAPH HINT_JAVAEE_LOAD_GRAPH
) )
); );
} };
} }
/** /**