10
10
import org .hibernate .boot .model .FunctionContributor ;
11
11
import org .hibernate .boot .registry .classloading .spi .ClassLoaderService ;
12
12
import org .hibernate .boot .spi .MetadataImplementor ;
13
- import org .hibernate .boot .spi .SessionFactoryOptions ;
14
13
import org .hibernate .cfg .AvailableSettings ;
15
14
import org .hibernate .dialect .Dialect ;
15
+ import org .hibernate .engine .jdbc .spi .JdbcServices ;
16
16
import org .hibernate .engine .query .spi .NativeQueryInterpreter ;
17
- import org .hibernate .engine .spi .SessionFactoryImplementor ;
18
17
import org .hibernate .internal .CoreLogging ;
19
18
import org .hibernate .internal .util .config .ConfigurationHelper ;
19
+ import org .hibernate .query .BindingContext ;
20
20
import org .hibernate .query .hql .HqlTranslator ;
21
21
import org .hibernate .query .hql .internal .StandardHqlTranslator ;
22
22
import org .hibernate .query .hql .spi .SqmCreationOptions ;
32
32
import org .hibernate .query .sqm .sql .SqmTranslatorFactory ;
33
33
import org .hibernate .query .sqm .sql .StandardSqmTranslatorFactory ;
34
34
import org .hibernate .service .ServiceRegistry ;
35
- import org .hibernate .stat .spi .StatisticsImplementor ;
35
+ import org .hibernate .service .spi .ServiceRegistryImplementor ;
36
36
import org .hibernate .type .spi .TypeConfiguration ;
37
37
import org .jboss .logging .Logger ;
38
38
39
39
import java .util .ArrayList ;
40
40
import java .util .Collection ;
41
41
import java .util .List ;
42
42
import java .util .Map ;
43
- import java .util .function .Supplier ;
44
43
45
44
import static java .util .Comparator .comparingInt ;
46
45
@@ -54,23 +53,31 @@ public class QueryEngineImpl implements QueryEngine {
54
53
55
54
private static final Logger LOG_HQL_FUNCTIONS = CoreLogging .logger ("org.hibernate.HQL_FUNCTIONS" );
56
55
57
- public static QueryEngine from (SessionFactoryImplementor sessionFactory , MetadataImplementor metadata ) {
58
- final QueryEngineOptions options = sessionFactory .getSessionFactoryOptions ();
59
- final Dialect dialect = sessionFactory .getJdbcServices ().getDialect ();
56
+ public static QueryEngineImpl from (
57
+ MetadataImplementor metadata ,
58
+ QueryEngineOptions options ,
59
+ SqmCreationContext sqmCreationContext ,
60
+ ServiceRegistryImplementor serviceRegistry ,
61
+ Map <String ,Object > properties ,
62
+ String name ) {
63
+ final Dialect dialect = serviceRegistry .requireService ( JdbcServices .class ).getDialect ();
60
64
return new QueryEngineImpl (
61
- sessionFactory ,
62
65
metadata .getTypeConfiguration (),
63
- resolveHqlTranslator ( options , dialect , sessionFactory , new SqmCreationOptionsStandard ( options ) ),
66
+ resolveHqlTranslator ( options , dialect , sqmCreationContext , new SqmCreationOptionsStandard ( options ) ),
64
67
resolveSqmTranslatorFactory ( options , dialect ),
65
- createFunctionRegistry ( sessionFactory , metadata , options , dialect ),
66
- metadata .buildNamedQueryRepository ( sessionFactory ),
67
- buildInterpretationCache ( sessionFactory ::getStatistics , sessionFactory .getProperties () ),
68
- sessionFactory .getServiceRegistry ().getService (NativeQueryInterpreter .class )
68
+ createFunctionRegistry ( serviceRegistry , metadata , options , dialect ),
69
+ metadata .buildNamedQueryRepository (),
70
+ buildInterpretationCache ( serviceRegistry , properties ),
71
+ serviceRegistry .getService (NativeQueryInterpreter .class ),
72
+ sqmCreationContext ,
73
+ options ,
74
+ options .getUuid (),
75
+ name
69
76
);
70
77
}
71
78
72
79
private static SqmFunctionRegistry createFunctionRegistry (
73
- SessionFactoryImplementor sessionFactory ,
80
+ ServiceRegistry serviceRegistry ,
74
81
MetadataImplementor metadata ,
75
82
QueryEngineOptions queryEngineOptions ,
76
83
Dialect dialect ) {
@@ -84,21 +91,17 @@ private static SqmFunctionRegistry createFunctionRegistry(
84
91
}
85
92
86
93
//TODO: probably better to turn this back into an anonymous class
87
- final FunctionContributions functionContributions = new QueryEngineImpl .FunctionContributionsImpl (
88
- sessionFactory .getServiceRegistry (),
89
- metadata .getTypeConfiguration (),
90
- sqmFunctionRegistry
91
- );
92
- for ( FunctionContributor contributor : sortedFunctionContributors ( sessionFactory .getServiceRegistry () ) ) {
94
+ final FunctionContributions functionContributions =
95
+ new FunctionContributionsImpl ( serviceRegistry , metadata .getTypeConfiguration (), sqmFunctionRegistry );
96
+ for ( FunctionContributor contributor : sortedFunctionContributors ( serviceRegistry ) ) {
93
97
contributor .contributeFunctions ( functionContributions );
94
98
}
95
99
96
100
dialect .initializeFunctionRegistry ( functionContributions );
97
101
98
102
if ( LOG_HQL_FUNCTIONS .isDebugEnabled () ) {
99
- sqmFunctionRegistry .getFunctionsByName ().forEach (
100
- entry -> LOG_HQL_FUNCTIONS .debug ( entry .getValue ().getSignature ( entry .getKey () ) )
101
- );
103
+ sqmFunctionRegistry .getFunctionsByName ()
104
+ .forEach ( entry -> LOG_HQL_FUNCTIONS .debug ( entry .getValue ().getSignature ( entry .getKey () ) ) );
102
105
}
103
106
104
107
return sqmFunctionRegistry ;
@@ -114,30 +117,30 @@ private static SqmFunctionRegistry createFunctionRegistry(
114
117
private final SqmFunctionRegistry sqmFunctionRegistry ;
115
118
116
119
private QueryEngineImpl (
117
- SessionFactoryImplementor sessionFactory ,
118
120
TypeConfiguration typeConfiguration ,
119
121
HqlTranslator hqlTranslator ,
120
122
SqmTranslatorFactory sqmTranslatorFactory ,
121
123
SqmFunctionRegistry functionRegistry ,
122
124
NamedObjectRepository namedObjectRepository ,
123
125
QueryInterpretationCache interpretationCache ,
124
- NativeQueryInterpreter nativeQueryInterpreter ) {
126
+ NativeQueryInterpreter nativeQueryInterpreter ,
127
+ BindingContext context ,
128
+ QueryEngineOptions options ,
129
+ String uuid , String name ) {
125
130
this .typeConfiguration = typeConfiguration ;
126
131
this .sqmFunctionRegistry = functionRegistry ;
127
132
this .sqmTranslatorFactory = sqmTranslatorFactory ;
128
133
this .hqlTranslator = hqlTranslator ;
129
134
this .namedObjectRepository = namedObjectRepository ;
130
135
this .interpretationCache = interpretationCache ;
131
136
this .nativeQueryInterpreter = nativeQueryInterpreter ;
132
- final SessionFactoryOptions sessionFactoryOptions = sessionFactory .getSessionFactoryOptions ();
133
- this .criteriaBuilder = new SqmCriteriaNodeBuilder (
134
- sessionFactory .getUuid (),
135
- sessionFactory .getName (),
136
- this ,
137
- sessionFactoryOptions .getJpaCompliance ().isJpaQueryComplianceEnabled (),
138
- sessionFactoryOptions .getCriteriaValueHandlingMode (),
139
- () -> sessionFactory
140
- );
137
+ this .criteriaBuilder = createCriteriaBuilder ( context , options , uuid , name );
138
+ }
139
+
140
+ private SqmCriteriaNodeBuilder createCriteriaBuilder (
141
+ BindingContext context , QueryEngineOptions options ,
142
+ String uuid , String name ) {
143
+ return new SqmCriteriaNodeBuilder ( uuid , name , this , options , context );
141
144
}
142
145
143
146
private static HqlTranslator resolveHqlTranslator (
@@ -171,10 +174,10 @@ else if ( dialect.getSqmTranslatorFactory() != null ) {
171
174
}
172
175
173
176
private static List <FunctionContributor > sortedFunctionContributors (ServiceRegistry serviceRegistry ) {
174
- Collection <FunctionContributor > functionContributors =
177
+ final Collection <FunctionContributor > functionContributors =
175
178
serviceRegistry .requireService (ClassLoaderService .class )
176
179
.loadJavaServices (FunctionContributor .class );
177
- List <FunctionContributor > contributors = new ArrayList <>( functionContributors );
180
+ final List <FunctionContributor > contributors = new ArrayList <>( functionContributors );
178
181
contributors .sort (
179
182
comparingInt ( FunctionContributor ::ordinal )
180
183
.thenComparing ( a -> a .getClass ().getCanonicalName () )
@@ -183,8 +186,7 @@ private static List<FunctionContributor> sortedFunctionContributors(ServiceRegis
183
186
}
184
187
185
188
private static QueryInterpretationCache buildInterpretationCache (
186
- Supplier <StatisticsImplementor > statisticsSupplier ,
187
- Map <String , Object > properties ) {
189
+ ServiceRegistry serviceRegistry , Map <String , Object > properties ) {
188
190
final boolean explicitUseCache = ConfigurationHelper .getBoolean (
189
191
AvailableSettings .QUERY_PLAN_CACHE_ENABLED ,
190
192
properties ,
@@ -202,11 +204,11 @@ private static QueryInterpretationCache buildInterpretationCache(
202
204
? explicitMaxPlanSize
203
205
: QueryEngine .DEFAULT_QUERY_PLAN_MAX_COUNT ;
204
206
205
- return new QueryInterpretationCacheStandardImpl ( size , statisticsSupplier );
207
+ return new QueryInterpretationCacheStandardImpl ( size , serviceRegistry );
206
208
}
207
209
else {
208
210
// disabled
209
- return new QueryInterpretationCacheDisabledImpl ( statisticsSupplier );
211
+ return new QueryInterpretationCacheDisabledImpl ( serviceRegistry );
210
212
}
211
213
}
212
214
@@ -299,5 +301,4 @@ public ServiceRegistry getServiceRegistry() {
299
301
return serviceRegistry ;
300
302
}
301
303
}
302
-
303
304
}
0 commit comments