|
72 | 72 | import org.hibernate.jpa.internal.ExceptionMapperLegacyJpaImpl;
|
73 | 73 | import org.hibernate.jpa.internal.PersistenceUnitUtilImpl;
|
74 | 74 | import org.hibernate.mapping.Collection;
|
| 75 | +import org.hibernate.mapping.GeneratorSettings; |
75 | 76 | import org.hibernate.mapping.PersistentClass;
|
76 | 77 | import org.hibernate.mapping.RootClass;
|
77 | 78 | import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl;
|
@@ -277,16 +278,16 @@ public SessionFactoryImpl(
|
277 | 278 | // create runtime metamodels (mapping and JPA)
|
278 | 279 | final RuntimeMetamodelsImpl runtimeMetamodelsImpl = new RuntimeMetamodelsImpl();
|
279 | 280 | runtimeMetamodels = runtimeMetamodelsImpl;
|
280 |
| - final MappingMetamodelImpl mappingMetamodelImpl = |
281 |
| - new MappingMetamodelImpl( typeConfiguration, serviceRegistry ); |
| 281 | + final MappingMetamodelImpl mappingMetamodelImpl = new MappingMetamodelImpl( typeConfiguration, serviceRegistry ); |
282 | 282 | runtimeMetamodelsImpl.setMappingMetamodel( mappingMetamodelImpl );
|
283 | 283 | fastSessionServices = new FastSessionServices( this );
|
284 |
| - initializeMappingModel( mappingMetamodelImpl, bootstrapContext, bootMetamodel, options ); |
| 284 | + mappingMetamodelImpl.finishInitialization( |
| 285 | + new ModelCreationContext( bootstrapContext, bootMetamodel, mappingMetamodelImpl, typeConfiguration ) ); |
285 | 286 | runtimeMetamodelsImpl.setJpaMetamodel( mappingMetamodelImpl.getJpaMetamodel() );
|
286 | 287 |
|
287 | 288 | // this needs to happen after the mapping metamodel is
|
288 | 289 | // completely built, since we need to use the persisters
|
289 |
| - fetchProfiles = getFetchProfiles( bootMetamodel, runtimeMetamodels ); |
| 290 | + fetchProfiles = getFetchProfiles( bootMetamodel, runtimeMetamodelsImpl); |
290 | 291 |
|
291 | 292 | defaultSessionOpenOptions = createDefaultSessionOpenOptionsIfPossible();
|
292 | 293 | temporarySessionOpenOptions = defaultSessionOpenOptions == null ? null : buildTemporarySessionOpenOptions();
|
@@ -320,102 +321,6 @@ public SessionFactoryImpl(
|
320 | 321 | LOG.debug( "Instantiated SessionFactory" );
|
321 | 322 | }
|
322 | 323 |
|
323 |
| - private void initializeMappingModel( |
324 |
| - MappingMetamodelImpl mappingMetamodelImpl, |
325 |
| - BootstrapContext bootstrapContext, |
326 |
| - MetadataImplementor bootMetamodel, |
327 |
| - SessionFactoryOptions options) { |
328 |
| - mappingMetamodelImpl.finishInitialization( runtimeModelCreationContext( |
329 |
| - bootstrapContext, |
330 |
| - bootMetamodel, |
331 |
| - mappingMetamodelImpl, |
332 |
| - mappingMetamodelImpl.getTypeConfiguration(), |
333 |
| - options |
334 |
| - ) ); |
335 |
| - } |
336 |
| - |
337 |
| - private RuntimeModelCreationContext runtimeModelCreationContext( |
338 |
| - BootstrapContext bootstrapContext, |
339 |
| - MetadataImplementor bootMetamodel, |
340 |
| - MappingMetamodelImplementor mappingMetamodel, |
341 |
| - TypeConfiguration typeConfiguration, |
342 |
| - SessionFactoryOptions options) { |
343 |
| - return new RuntimeModelCreationContext() { |
344 |
| - final Map<String,Generator> generators = new HashMap<>(); |
345 |
| - |
346 |
| - @Override |
347 |
| - public BootstrapContext getBootstrapContext() { |
348 |
| - return bootstrapContext; |
349 |
| - } |
350 |
| - |
351 |
| - @Override |
352 |
| - public SessionFactoryImplementor getSessionFactory() { |
353 |
| - // this is bad, we're not yet fully-initialized |
354 |
| - return SessionFactoryImpl.this; |
355 |
| - } |
356 |
| - |
357 |
| - @Override |
358 |
| - public MetadataImplementor getBootModel() { |
359 |
| - return bootMetamodel; |
360 |
| - } |
361 |
| - |
362 |
| - @Override |
363 |
| - public MappingMetamodelImplementor getDomainModel() { |
364 |
| - return mappingMetamodel; |
365 |
| - } |
366 |
| - |
367 |
| - @Override |
368 |
| - public CacheImplementor getCache() { |
369 |
| - return cacheAccess; |
370 |
| - } |
371 |
| - |
372 |
| - @Override |
373 |
| - public Map<String, Object> getSettings() { |
374 |
| - return settings; |
375 |
| - } |
376 |
| - |
377 |
| - @Override |
378 |
| - public Dialect getDialect() { |
379 |
| - return jdbcServices.getDialect(); |
380 |
| - } |
381 |
| - |
382 |
| - @Override |
383 |
| - public SqmFunctionRegistry getFunctionRegistry() { |
384 |
| - return queryEngine.getSqmFunctionRegistry(); |
385 |
| - } |
386 |
| - |
387 |
| - @Override |
388 |
| - public TypeConfiguration getTypeConfiguration() { |
389 |
| - return typeConfiguration; |
390 |
| - } |
391 |
| - |
392 |
| - @Override |
393 |
| - public SessionFactoryOptions getSessionFactoryOptions() { |
394 |
| - return options; |
395 |
| - } |
396 |
| - |
397 |
| - @Override |
398 |
| - public JdbcServices getJdbcServices() { |
399 |
| - return jdbcServices; |
400 |
| - } |
401 |
| - |
402 |
| - @Override |
403 |
| - public SqlStringGenerationContext getSqlStringGenerationContext() { |
404 |
| - return sqlStringGenerationContext; |
405 |
| - } |
406 |
| - |
407 |
| - @Override |
408 |
| - public ServiceRegistry getServiceRegistry() { |
409 |
| - return serviceRegistry; |
410 |
| - } |
411 |
| - |
412 |
| - @Override |
413 |
| - public Map<String, Generator> getGenerators() { |
414 |
| - return generators; |
415 |
| - } |
416 |
| - }; |
417 |
| - } |
418 |
| - |
419 | 324 | private static SqlStringGenerationContext createSqlStringGenerationContext(
|
420 | 325 | MetadataImplementor bootMetamodel,
|
421 | 326 | SessionFactoryOptions options,
|
@@ -1687,4 +1592,110 @@ private enum Status {
|
1687 | 1592 | CLOSING,
|
1688 | 1593 | CLOSED
|
1689 | 1594 | }
|
| 1595 | + |
| 1596 | + private class ModelCreationContext implements RuntimeModelCreationContext, GeneratorSettings { |
| 1597 | + final Map<String, Generator> generators; |
| 1598 | + private final BootstrapContext bootstrapContext; |
| 1599 | + private final MetadataImplementor bootMetamodel; |
| 1600 | + private final MappingMetamodelImplementor mappingMetamodel; |
| 1601 | + private final TypeConfiguration typeConfiguration; |
| 1602 | + |
| 1603 | + private ModelCreationContext( |
| 1604 | + BootstrapContext bootstrapContext, |
| 1605 | + MetadataImplementor bootMetamodel, |
| 1606 | + MappingMetamodelImplementor mappingMetamodel, |
| 1607 | + TypeConfiguration typeConfiguration) { |
| 1608 | + this.bootstrapContext = bootstrapContext; |
| 1609 | + this.bootMetamodel = bootMetamodel; |
| 1610 | + this.mappingMetamodel = mappingMetamodel; |
| 1611 | + this.typeConfiguration = typeConfiguration; |
| 1612 | + generators = new HashMap<>(); |
| 1613 | + } |
| 1614 | + |
| 1615 | + @Override |
| 1616 | + public BootstrapContext getBootstrapContext() { |
| 1617 | + return bootstrapContext; |
| 1618 | + } |
| 1619 | + |
| 1620 | + @Override |
| 1621 | + public SessionFactoryImplementor getSessionFactory() { |
| 1622 | + // this is bad, we're not yet fully-initialized |
| 1623 | + return SessionFactoryImpl.this; |
| 1624 | + } |
| 1625 | + |
| 1626 | + @Override |
| 1627 | + public MetadataImplementor getBootModel() { |
| 1628 | + return bootMetamodel; |
| 1629 | + } |
| 1630 | + |
| 1631 | + @Override |
| 1632 | + public MappingMetamodelImplementor getDomainModel() { |
| 1633 | + return mappingMetamodel; |
| 1634 | + } |
| 1635 | + |
| 1636 | + @Override |
| 1637 | + public CacheImplementor getCache() { |
| 1638 | + return cacheAccess; |
| 1639 | + } |
| 1640 | + |
| 1641 | + @Override |
| 1642 | + public Map<String, Object> getSettings() { |
| 1643 | + return settings; |
| 1644 | + } |
| 1645 | + |
| 1646 | + @Override |
| 1647 | + public Dialect getDialect() { |
| 1648 | + return jdbcServices.getDialect(); |
| 1649 | + } |
| 1650 | + |
| 1651 | + @Override |
| 1652 | + public SqmFunctionRegistry getFunctionRegistry() { |
| 1653 | + return queryEngine.getSqmFunctionRegistry(); |
| 1654 | + } |
| 1655 | + |
| 1656 | + @Override |
| 1657 | + public TypeConfiguration getTypeConfiguration() { |
| 1658 | + return typeConfiguration; |
| 1659 | + } |
| 1660 | + |
| 1661 | + @Override |
| 1662 | + public SessionFactoryOptions getSessionFactoryOptions() { |
| 1663 | + return sessionFactoryOptions; |
| 1664 | + } |
| 1665 | + |
| 1666 | + @Override |
| 1667 | + public JdbcServices getJdbcServices() { |
| 1668 | + return jdbcServices; |
| 1669 | + } |
| 1670 | + |
| 1671 | + @Override |
| 1672 | + public ServiceRegistry getServiceRegistry() { |
| 1673 | + return serviceRegistry; |
| 1674 | + } |
| 1675 | + |
| 1676 | + @Override |
| 1677 | + public Map<String, Generator> getGenerators() { |
| 1678 | + return generators; |
| 1679 | + } |
| 1680 | + |
| 1681 | + @Override |
| 1682 | + public GeneratorSettings getGeneratorSettings() { |
| 1683 | + return this; |
| 1684 | + } |
| 1685 | + |
| 1686 | + @Override |
| 1687 | + public String getDefaultCatalog() { |
| 1688 | + return sessionFactoryOptions.getDefaultCatalog(); |
| 1689 | + } |
| 1690 | + |
| 1691 | + @Override |
| 1692 | + public String getDefaultSchema() { |
| 1693 | + return sessionFactoryOptions.getDefaultSchema(); |
| 1694 | + } |
| 1695 | + |
| 1696 | + @Override |
| 1697 | + public SqlStringGenerationContext getSqlStringGenerationContext() { |
| 1698 | + return sqlStringGenerationContext; |
| 1699 | + } |
| 1700 | + } |
1690 | 1701 | }
|
0 commit comments