Skip to content

Commit 9caa1e2

Browse files
committed
move management of fetch profiles to the SqlTranslationEngine
1 parent 3491101 commit 9caa1e2

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor, BindingCon
201201

202202
private final transient Map<String, FilterDefinition> filters;
203203
private final transient java.util.Collection<FilterDefinition> autoEnabledFilters = new HashSet<>();
204-
private final transient Map<String, FetchProfile> fetchProfiles;
205204
private final transient JavaType<Object> tenantIdentifierJavaType;
206205

207206
private final transient EventListenerGroups eventListenerGroups;
@@ -305,7 +304,6 @@ public SessionFactoryImpl(
305304
// and SqmFunctionRegistry, instantiating just the
306305
// registry here, and doing the engine later
307306
queryEngine = new QueryEngineImpl( bootMetamodel, options, this, serviceRegistry, settings, name );
308-
sqlTranslationEngine = new SqlTranslationEngineImpl( this, typeConfiguration );
309307

310308
// create runtime metamodels (mapping and JPA)
311309
final RuntimeMetamodelsImpl runtimeMetamodelsImpl = new RuntimeMetamodelsImpl();
@@ -318,7 +316,8 @@ public SessionFactoryImpl(
318316

319317
// this needs to happen after the mapping metamodel is
320318
// completely built, since we need to use the persisters
321-
fetchProfiles = getFetchProfiles( bootMetamodel, runtimeMetamodelsImpl );
319+
Map<String, FetchProfile> fetchProfiles = getFetchProfiles( bootMetamodel, runtimeMetamodelsImpl );
320+
sqlTranslationEngine = new SqlTranslationEngineImpl( this, typeConfiguration, fetchProfiles );
322321

323322
defaultSessionOpenOptions = createDefaultSessionOpenOptionsIfPossible();
324323
temporarySessionOpenOptions = defaultSessionOpenOptions == null ? null : buildTemporarySessionOpenOptions();
@@ -1035,18 +1034,23 @@ public java.util.Collection<FilterDefinition> getAutoEnabledFilters() {
10351034
}
10361035

10371036
@Override
1038-
public boolean containsFetchProfileDefinition(String name) {
1039-
return fetchProfiles.containsKey( name );
1037+
public Set<String> getDefinedFilterNames() {
1038+
return unmodifiableSet( filters.keySet() );
10401039
}
10411040

10421041
@Override
1043-
public Set<String> getDefinedFilterNames() {
1044-
return unmodifiableSet( filters.keySet() );
1042+
public FetchProfile getFetchProfile(String name) {
1043+
return sqlTranslationEngine.getFetchProfile( name );
1044+
}
1045+
1046+
@Override
1047+
public boolean containsFetchProfileDefinition(String name) {
1048+
return sqlTranslationEngine.containsFetchProfileDefinition( name );
10451049
}
10461050

10471051
@Override
10481052
public Set<String> getDefinedFetchProfileNames() {
1049-
return unmodifiableSet( fetchProfiles.keySet() );
1053+
return sqlTranslationEngine.getDefinedFetchProfileNames();
10501054
}
10511055

10521056
@Override @Deprecated
@@ -1126,11 +1130,6 @@ public EntityNotFoundDelegate getEntityNotFoundDelegate() {
11261130
return sessionFactoryOptions.getEntityNotFoundDelegate();
11271131
}
11281132

1129-
@Override
1130-
public FetchProfile getFetchProfile(String name) {
1131-
return fetchProfiles.get( name );
1132-
}
1133-
11341133
/**
11351134
* @deprecated use {@link #configuredInterceptor(Interceptor, boolean, SessionFactoryOptions)}
11361135
*/

hibernate-core/src/main/java/org/hibernate/query/sql/internal/SqlTranslationEngineImpl.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,31 @@
1111
import org.hibernate.query.sql.spi.SqlTranslationEngine;
1212
import org.hibernate.type.spi.TypeConfiguration;
1313

14+
import java.util.Map;
15+
import java.util.Set;
16+
17+
import static java.util.Collections.unmodifiableSet;
18+
1419
public class SqlTranslationEngineImpl implements SqlTranslationEngine {
1520

1621
//TODO: consider unifying with SqlStringGenerationContextImpl
1722

1823
private final SessionFactoryImplementor factory;
1924
private final TypeConfiguration typeConfiguration;
25+
private final Map<String, FetchProfile> fetchProfiles;
2026

21-
public SqlTranslationEngineImpl(SessionFactoryImplementor factory, TypeConfiguration typeConfiguration) {
27+
public SqlTranslationEngineImpl(
28+
SessionFactoryImplementor factory,
29+
TypeConfiguration typeConfiguration,
30+
Map<String, FetchProfile> fetchProfiles) {
2231
this.factory = factory;
2332
this.typeConfiguration = typeConfiguration;
33+
this.fetchProfiles = fetchProfiles;
34+
}
35+
36+
@Override
37+
public TypeConfiguration getTypeConfiguration() {
38+
return typeConfiguration;
2439
}
2540

2641
@Override
@@ -50,11 +65,16 @@ public JpaMetamodel getJpaMetamodel() {
5065

5166
@Override
5267
public FetchProfile getFetchProfile(String name) {
53-
return factory.getFetchProfile( name );
68+
return fetchProfiles.get( name );
5469
}
5570

5671
@Override
57-
public TypeConfiguration getTypeConfiguration() {
58-
return typeConfiguration;
72+
public boolean containsFetchProfileDefinition(String name) {
73+
return fetchProfiles.containsKey( name );
74+
}
75+
76+
@Override
77+
public Set<String> getDefinedFetchProfileNames() {
78+
return unmodifiableSet( fetchProfiles.keySet() );
5979
}
6080
}

hibernate-core/src/main/java/org/hibernate/query/sql/spi/SqlTranslationEngine.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.hibernate.Incubating;
88
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
99

10+
import java.util.Set;
11+
1012
/**
1113
* Introduced as an analog of {@link org.hibernate.query.spi.QueryEngine}
1214
* and/or {@link org.hibernate.query.sqm.NodeBuilder} for the SQL
@@ -19,4 +21,8 @@
1921
@Incubating
2022
public interface SqlTranslationEngine extends SqlAstCreationContext {
2123
// TODO: consider implementing SqlStringGenerationContext
24+
25+
boolean containsFetchProfileDefinition(String name);
26+
27+
Set<String> getDefinedFetchProfileNames();
2228
}

hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlAstCreationContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,24 @@ public interface SqlAstCreationContext extends BindingContext {
5656
*/
5757
FetchProfile getFetchProfile(String name);
5858

59+
/**
60+
* Obtain the {@link SqmFunctionRegistry}.
61+
*/
5962
default SqmFunctionRegistry getSqmFunctionRegistry() {
6063
return getSessionFactory().getQueryEngine().getSqmFunctionRegistry();
6164
}
6265

66+
/**
67+
* Obtain the {@link Dialect}.
68+
*/
6369
default Dialect getDialect() {
6470
return getSessionFactory().getQueryEngine().getDialect();
6571
}
6672

73+
/**
74+
* Obtain the "incomplete" {@link WrapperOptions} that would be
75+
* returned by {@link SessionFactoryImplementor#getWrapperOptions()}.
76+
*/
6777
default WrapperOptions getWrapperOptions() {
6878
return getSessionFactory().getWrapperOptions();
6979
}

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public Class<?> classForName(String className) {
239239

240240
nodeBuilder = new SqmCriteriaNodeBuilder("", "", this, this, this);
241241

242-
sqlTranslationEngine = new SqlTranslationEngineImpl(this, typeConfiguration);
242+
sqlTranslationEngine = new SqlTranslationEngineImpl(this, typeConfiguration, emptyMap() );
243243
}
244244

245245
@Override

0 commit comments

Comments
 (0)