|
| 1 | += ORM Bootstrap Direction |
| 2 | + |
| 3 | +This note captures the proposed direction for using this PoC to replace and simplify large parts of ORM bootstrap, |
| 4 | +especially the JPA path through `EntityManagerFactoryBuilderImpl`. |
| 5 | + |
| 6 | +== Current ORM Shape |
| 7 | + |
| 8 | +From the JPA side, `EntityManagerFactoryBuilderImpl` currently handles several phases inline: |
| 9 | + |
| 10 | +* Merge persistence-unit, integration, `hibernate.properties`, and cfg.xml settings into `MergedSettings` |
| 11 | +* Build the `BootstrapServiceRegistry` |
| 12 | +* Build the `StandardServiceRegistry` |
| 13 | +* Create `MetadataSources` |
| 14 | +* Push persistence-unit classes, packages, and XML into `MetadataSources` |
| 15 | +* Apply scanning results |
| 16 | +* Apply metadata-builder contributors and type/converter settings |
| 17 | +* Build `ManagedResources` |
| 18 | +* Later call `MetadataBuildingProcess.complete(...)` |
| 19 | + |
| 20 | +`MetadataBuildingProcess.processManagedResources(...)` then unpacks `ManagedResources` into: |
| 21 | + |
| 22 | +* XML preprocessing results |
| 23 | +* known class names |
| 24 | +* `ModelsContext` |
| 25 | +* global registrations |
| 26 | +* root entity, mapped-superclass, and embeddable categorization |
| 27 | + |
| 28 | +This means `ManagedResources` acts as the historical source bundle, while this PoC's `AvailableResources` |
| 29 | +is the cleaner replacement candidate. |
| 30 | + |
| 31 | +== Proposed Pipeline |
| 32 | + |
| 33 | +Replace the current implicit sequence with explicit intermediate products: |
| 34 | + |
| 35 | +[source] |
| 36 | +---- |
| 37 | +JpaBootstrapSettings |
| 38 | +BootstrapSourceContributions |
| 39 | +AvailableResources |
| 40 | +CategorizedDomainModel |
| 41 | +BoundMetadata |
| 42 | +---- |
| 43 | + |
| 44 | +The intended flow is: |
| 45 | + |
| 46 | +[source] |
| 47 | +---- |
| 48 | +PersistenceUnitDescriptor / HibernatePersistenceConfiguration |
| 49 | + -> JpaBootstrapSourceCollector |
| 50 | + -> AvailableResources |
| 51 | + -> DomainModelCategorizer |
| 52 | + -> BindingCoordinator |
| 53 | +---- |
| 54 | + |
| 55 | +== Settings |
| 56 | + |
| 57 | +Extract settings merge into a focused component, e.g. `JpaSettingsResolver` or `BootstrapSettingsResolver`. |
| 58 | + |
| 59 | +Inputs: |
| 60 | + |
| 61 | +* `PersistenceUnitDescriptor` |
| 62 | +* integration settings |
| 63 | +* cfg.xml |
| 64 | +* `HibernatePersistenceConfiguration` |
| 65 | + |
| 66 | +Outputs: |
| 67 | + |
| 68 | +* resolved settings map |
| 69 | +* cache region definitions |
| 70 | +* bootstrap flags such as XML enabled, scanner settings, and enhancement settings |
| 71 | + |
| 72 | +Settings should remain separate from source resources. |
| 73 | + |
| 74 | +== Source Discovery |
| 75 | + |
| 76 | +Extract JPA source discovery from `EntityManagerFactoryBuilderImpl` and avoid routing through `MetadataSources` |
| 77 | +as the primary abstraction. |
| 78 | + |
| 79 | +Inputs: |
| 80 | + |
| 81 | +* persistence-unit class names |
| 82 | +* mapping file names |
| 83 | +* standard `META-INF/orm.xml` |
| 84 | +* explicit `HBM_XML_FILES` |
| 85 | +* scanner results |
| 86 | +* loaded classes |
| 87 | +* packages |
| 88 | + |
| 89 | +Output: |
| 90 | + |
| 91 | +* raw source contributions, not yet categorized |
| 92 | + |
| 93 | +== AvailableResources |
| 94 | + |
| 95 | +`AvailableResources` should be the normalized source model produced by source discovery. |
| 96 | + |
| 97 | +It should contain: |
| 98 | + |
| 99 | +* resolved `ClassDetails` for managed classes |
| 100 | +* resolved package-info `ClassDetails` |
| 101 | +* XML bindings |
| 102 | +* dynamic model names/classes if needed |
| 103 | +* possibly extra query imports, either directly or as a sibling object |
| 104 | + |
| 105 | +It should not contain merged settings. |
| 106 | + |
| 107 | +It should not simply clone `ManagedResources`. `ManagedResources` is raw-ish and historical, exposing class |
| 108 | +references, class names, package names, XML bindings, converter descriptors, and query imports. `AvailableResources` |
| 109 | +should be source-model oriented and normalized for categorization. |
| 110 | + |
| 111 | +== XML Preprocessing |
| 112 | + |
| 113 | +Move XML preprocessing behind `AvailableResources`. |
| 114 | + |
| 115 | +The short-term adapter is acceptable: |
| 116 | + |
| 117 | +[source] |
| 118 | +---- |
| 119 | +AvailableResources -> ManagedResources adapter -> XmlPreProcessor |
| 120 | +---- |
| 121 | + |
| 122 | +The intended direction is direct consumption: |
| 123 | + |
| 124 | +[source] |
| 125 | +---- |
| 126 | +AvailableResources -> XmlPreProcessingResult |
| 127 | +---- |
| 128 | + |
| 129 | +== Categorization |
| 130 | + |
| 131 | +Categorization should consume normalized resources: |
| 132 | + |
| 133 | +[source] |
| 134 | +---- |
| 135 | +AvailableResources + BootstrapContext -> CategorizedDomainModel |
| 136 | +---- |
| 137 | + |
| 138 | +This replaces the current ad hoc categorization work in `MetadataBuildingProcess.processManagedResources(...)`. |
| 139 | + |
| 140 | +== Binding |
| 141 | + |
| 142 | +Binding should consume categorized metadata and resolved bootstrap context: |
| 143 | + |
| 144 | +[source] |
| 145 | +---- |
| 146 | +CategorizedDomainModel + settings/defaults/global registrations -> ORM mapping model |
| 147 | +---- |
| 148 | + |
| 149 | +Binding should not need raw `MetadataSources` or raw `ManagedResources`. |
| 150 | + |
| 151 | +== Next PoC Slice |
| 152 | + |
| 153 | +Prototype this chain: |
| 154 | + |
| 155 | +[source] |
| 156 | +---- |
| 157 | +PersistenceUnitDescriptor / HibernatePersistenceConfiguration |
| 158 | + -> JpaBootstrapSourceCollector |
| 159 | + -> AvailableResources |
| 160 | + -> DomainModelCategorizer |
| 161 | +---- |
| 162 | + |
| 163 | +Do not wire binding yet. |
| 164 | + |
| 165 | +The test target should be: |
| 166 | + |
| 167 | +* Given JPA bootstrap inputs, the PoC derives the same available classes, packages, XML, and global registrations |
| 168 | + that ORM currently derives through `EntityManagerFactoryBuilderImpl` and `ManagedResources` |
| 169 | + |
| 170 | +This establishes a clean replacement boundary before touching binder and persister integration. |
| 171 | + |
0 commit comments