clean up GraphSemantic

This commit is contained in:
Gavin 2023-04-13 12:09:49 +02:00 committed by Gavin King
parent 0b54c1d083
commit 577b6b1403
2 changed files with 42 additions and 34 deletions

View File

@ -8,8 +8,11 @@ package org.hibernate.graph;
import java.util.Locale; import java.util.Locale;
import org.hibernate.AssertionFailure;
import org.hibernate.jpa.LegacySpecHints; import org.hibernate.jpa.LegacySpecHints;
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; import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH; import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
@ -29,7 +32,7 @@ public enum GraphSemantic {
* are not fetched. * are not fetched.
* </ul> * </ul>
*/ */
FETCH( HINT_SPEC_FETCH_GRAPH, LegacySpecHints.HINT_JAVAEE_FETCH_GRAPH ), FETCH,
/** /**
* Indicates that an {@link jakarta.persistence.EntityGraph} should be interpreted as a JPA "load graph". * Indicates that an {@link jakarta.persistence.EntityGraph} should be interpreted as a JPA "load graph".
@ -40,15 +43,7 @@ public enum GraphSemantic {
* depending on the mapping of the attribute, instead of forcing {@code FetchType.LAZY}. * depending on the mapping of the attribute, instead of forcing {@code FetchType.LAZY}.
* </ul> * </ul>
*/ */
LOAD( HINT_SPEC_LOAD_GRAPH, LegacySpecHints.HINT_JAVAEE_LOAD_GRAPH ); LOAD;
private final String jakartaHintName;
private final String javaeeHintName;
GraphSemantic(String jakartaHintName, String javaeeHintName) {
this.jakartaHintName = jakartaHintName;
this.javaeeHintName = javaeeHintName;
}
/** /**
* The corresponding Jakarta Persistence hint name. * The corresponding Jakarta Persistence hint name.
@ -57,7 +52,14 @@ 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() {
return jakartaHintName; switch ( this ) {
case FETCH:
return HINT_SPEC_FETCH_GRAPH;
case LOAD:
return HINT_SPEC_LOAD_GRAPH;
default:
throw new AssertionFailure( "unknown GraphSemantic" );
}
} }
/** /**
@ -70,32 +72,38 @@ public enum GraphSemantic {
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public String getJpaHintName() { public String getJpaHintName() {
return javaeeHintName; switch ( this ) {
case FETCH:
return HINT_JAVAEE_FETCH_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) {
assert hintName != null; switch ( hintName ) {
case HINT_SPEC_FETCH_GRAPH:
if ( FETCH.getJakartaHintName().equals( hintName ) || FETCH.getJpaHintName().equals( hintName ) ) { case HINT_JAVAEE_FETCH_GRAPH:
return FETCH; return FETCH;
} case HINT_SPEC_LOAD_GRAPH:
case HINT_JAVAEE_LOAD_GRAPH:
if ( LOAD.getJakartaHintName().equalsIgnoreCase( hintName ) || LOAD.getJpaHintName().equalsIgnoreCase( hintName ) ) { return LOAD;
return LOAD; default:
} throw new IllegalArgumentException(
String.format(
throw new IllegalArgumentException( Locale.ROOT,
String.format( "Unknown EntityGraph hint name - `%s`. " +
Locale.ROOT, "Expecting `%s` or `%s` (or `%s` and `%s`).",
"Unknown EntityGraph hint name - `%s`. " +
"Expecting `%s` or `%s` (or `%s` and `%s`).",
hintName, hintName,
FETCH.jakartaHintName, HINT_SPEC_FETCH_GRAPH,
LOAD.jakartaHintName, HINT_SPEC_LOAD_GRAPH,
FETCH.javaeeHintName, HINT_JAVAEE_FETCH_GRAPH,
LOAD.javaeeHintName HINT_JAVAEE_LOAD_GRAPH
) )
); );
}
} }
/** /**

View File

@ -195,7 +195,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
} }
private EntityPersister getEntityPersister(String entityName) { private EntityPersister getEntityPersister(String entityName) {
return getFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor( entityName ); return getFactory().getMappingMetamodel().getEntityDescriptor( entityName );
} }
@Override @Override