modernize code in GraphSemantic and ExecuteUpdateResultCheckStyle
This commit is contained in:
parent
3d3561ff7e
commit
0ba7aec32d
|
@ -52,29 +52,19 @@ public enum ExecuteUpdateResultCheckStyle {
|
|||
PARAM;
|
||||
|
||||
public String externalName() {
|
||||
switch (this) {
|
||||
case NONE:
|
||||
return "none";
|
||||
case COUNT:
|
||||
return "rowcount";
|
||||
case PARAM:
|
||||
return "param";
|
||||
default:
|
||||
throw new AssertionFailure("Unrecognized ExecuteUpdateResultCheckStyle");
|
||||
}
|
||||
return switch ( this ) {
|
||||
case NONE -> "none";
|
||||
case COUNT -> "rowcount";
|
||||
case PARAM -> "param";
|
||||
};
|
||||
}
|
||||
|
||||
public static @Nullable ExecuteUpdateResultCheckStyle fromResultCheckStyle(ResultCheckStyle style) {
|
||||
switch (style) {
|
||||
case NONE:
|
||||
return NONE;
|
||||
case COUNT:
|
||||
return COUNT;
|
||||
case PARAM:
|
||||
return PARAM;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
public static ExecuteUpdateResultCheckStyle fromResultCheckStyle(ResultCheckStyle style) {
|
||||
return switch ( style ) {
|
||||
case NONE -> NONE;
|
||||
case COUNT -> COUNT;
|
||||
case PARAM -> PARAM;
|
||||
};
|
||||
}
|
||||
|
||||
public static @Nullable ExecuteUpdateResultCheckStyle fromExternalName(String name) {
|
||||
|
@ -92,28 +82,18 @@ public enum ExecuteUpdateResultCheckStyle {
|
|||
}
|
||||
|
||||
public Supplier<? extends Expectation> expectationConstructor() {
|
||||
switch (this) {
|
||||
case NONE:
|
||||
return Expectation.None::new;
|
||||
case COUNT:
|
||||
return Expectation.RowCount::new;
|
||||
case PARAM:
|
||||
return Expectation.OutParameter::new;
|
||||
default:
|
||||
throw new AssertionFailure( "Unrecognized ExecuteUpdateResultCheckStyle");
|
||||
}
|
||||
return switch ( this ) {
|
||||
case NONE -> Expectation.None::new;
|
||||
case COUNT -> Expectation.RowCount::new;
|
||||
case PARAM -> Expectation.OutParameter::new;
|
||||
};
|
||||
}
|
||||
|
||||
public Class<? extends Expectation> expectationClass() {
|
||||
switch (this) {
|
||||
case NONE:
|
||||
return Expectation.None.class;
|
||||
case COUNT:
|
||||
return Expectation.RowCount.class;
|
||||
case PARAM:
|
||||
return Expectation.OutParameter.class;
|
||||
default:
|
||||
throw new AssertionFailure( "Unrecognized ExecuteUpdateResultCheckStyle");
|
||||
}
|
||||
return switch ( this ) {
|
||||
case NONE -> Expectation.None.class;
|
||||
case COUNT -> Expectation.RowCount.class;
|
||||
case PARAM -> Expectation.OutParameter.class;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ package org.hibernate.graph;
|
|||
|
||||
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_LOAD_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
|
||||
*/
|
||||
public String getJakartaHintName() {
|
||||
switch ( this ) {
|
||||
case FETCH:
|
||||
return HINT_SPEC_FETCH_GRAPH;
|
||||
case LOAD:
|
||||
return HINT_SPEC_LOAD_GRAPH;
|
||||
default:
|
||||
throw new AssertionFailure( "unknown GraphSemantic" );
|
||||
}
|
||||
return switch ( this ) {
|
||||
case FETCH -> HINT_SPEC_FETCH_GRAPH;
|
||||
case LOAD -> HINT_SPEC_LOAD_GRAPH;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,30 +63,21 @@ public enum GraphSemantic {
|
|||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
public String getJpaHintName() {
|
||||
switch ( this ) {
|
||||
case FETCH:
|
||||
return HINT_JAVAEE_FETCH_GRAPH;
|
||||
case LOAD:
|
||||
return HINT_JAVAEE_LOAD_GRAPH;
|
||||
default:
|
||||
throw new AssertionFailure( "unknown GraphSemantic" );
|
||||
}
|
||||
return switch ( this ) {
|
||||
case FETCH -> HINT_JAVAEE_FETCH_GRAPH;
|
||||
case LOAD -> HINT_JAVAEE_LOAD_GRAPH;
|
||||
};
|
||||
}
|
||||
|
||||
public static GraphSemantic fromHintName(String hintName) {
|
||||
switch ( hintName ) {
|
||||
case HINT_SPEC_FETCH_GRAPH:
|
||||
case HINT_JAVAEE_FETCH_GRAPH:
|
||||
return FETCH;
|
||||
case HINT_SPEC_LOAD_GRAPH:
|
||||
case HINT_JAVAEE_LOAD_GRAPH:
|
||||
return LOAD;
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
return switch ( hintName ) {
|
||||
case HINT_SPEC_FETCH_GRAPH, HINT_JAVAEE_FETCH_GRAPH -> FETCH;
|
||||
case HINT_SPEC_LOAD_GRAPH, HINT_JAVAEE_LOAD_GRAPH -> LOAD;
|
||||
default -> throw new IllegalArgumentException(
|
||||
String.format(
|
||||
Locale.ROOT,
|
||||
"Unknown EntityGraph hint name - `%s`. " +
|
||||
"Expecting `%s` or `%s` (or `%s` and `%s`).",
|
||||
"Unknown EntityGraph hint name - `%s`. "
|
||||
+ "Expecting `%s` or `%s` (or `%s` and `%s`).",
|
||||
hintName,
|
||||
HINT_SPEC_FETCH_GRAPH,
|
||||
HINT_SPEC_LOAD_GRAPH,
|
||||
|
@ -100,7 +85,7 @@ public enum GraphSemantic {
|
|||
HINT_JAVAEE_LOAD_GRAPH
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue