modernize code in GraphSemantic and ExecuteUpdateResultCheckStyle
This commit is contained in:
parent
3d3561ff7e
commit
0ba7aec32d
|
@ -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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,38 +63,29 @@ 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:
|
String.format(
|
||||||
case HINT_JAVAEE_LOAD_GRAPH:
|
Locale.ROOT,
|
||||||
return LOAD;
|
"Unknown EntityGraph hint name - `%s`. "
|
||||||
default:
|
+ "Expecting `%s` or `%s` (or `%s` and `%s`).",
|
||||||
throw new IllegalArgumentException(
|
hintName,
|
||||||
String.format(
|
HINT_SPEC_FETCH_GRAPH,
|
||||||
Locale.ROOT,
|
HINT_SPEC_LOAD_GRAPH,
|
||||||
"Unknown EntityGraph hint name - `%s`. " +
|
HINT_JAVAEE_FETCH_GRAPH,
|
||||||
"Expecting `%s` or `%s` (or `%s` and `%s`).",
|
HINT_JAVAEE_LOAD_GRAPH
|
||||||
hintName,
|
)
|
||||||
HINT_SPEC_FETCH_GRAPH,
|
);
|
||||||
HINT_SPEC_LOAD_GRAPH,
|
};
|
||||||
HINT_JAVAEE_FETCH_GRAPH,
|
|
||||||
HINT_JAVAEE_LOAD_GRAPH
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue