-
-
Save gbadner/943347 to your computer and use it in GitHub Desktop.
Build ServiceRegistry | |
--------------------- | |
Map config = ...; | |
A) ServiceRegistry serviceRegistry = | |
new ServiceRegistryBuilder( config ) | |
... | |
.buildServiceRegistry(); | |
B) ServiceRegistry serviceRegistry = | |
new ServiceRegistryBuilder() | |
.setConfigurationData( config ) | |
.setOption( Environment.SHOW_SQL, true ) | |
.buildServiceRegistry(); | |
Questions: | |
1) Will there need to be a Jpa-specific ServiceRegistry (e.g., configured w/ | |
JPA-specific listeners? | |
2) Emmanuel suggested using something like the following to set the default | |
services for JPA: | |
JPAWasher.wash(builder); | |
GB: JPAWasher would live in a different package, so ServiceRegistryBuilder | |
would have to have public setters (maybe OK for a builder). | |
Build MetadataSources: | |
---------------------- | |
MetadataSources sources = | |
new MetadataSources( serviceRegistry ) | |
.addAnnotatedClass( Order.class ) | |
.addResource( "OrderLine.hbm.xml" ) | |
...; | |
1) Does it make sense that MetadataSources could have some resources using | |
hibernate-mapping-4.0.xsd and others using orm_2_0.xsd? | |
2) Should there need to be a JpaMetadataSources? | |
Build Metadata: | |
--------------- | |
A) Metadata metadata = | |
sources | |
.getMetadataBuilder() | |
.setNamingStrategy( namingStrategy ) | |
... // other config stuff | |
.build(); | |
B) Metadata metadata = | |
new MetadataBuilder() | |
.setNamingStrategy( namingStrategy ) | |
... // other config stuff | |
.build( sources ); | |
(makes it absolutely clear that the namingStrategy is | |
associated with the MetadataBuilder, not w/ MetadataSources) | |
C) Metadata metadata = sources.buildMetadata( new NamingStrategy() ); | |
(this is OK if there's no need for a MetadataBuilder) | |
(also allows metadata to be built from the same source multiple | |
times using different naming strategies) | |
1) Would there be a need for a JpaMetadataBuilder? If there is a | |
JpaMetadataSources or some other way to indicate "jpa" sources, then | |
A) could get the JpaMetadataBuilder. | |
Build SessionFactory: | |
--------------------- | |
SessionFactory sf = metadata.buildSessionFactory(); |
If the naming strategy is really only needed for building the metadata, and calling getMetadataBuilder() is unnecessary, then why not instead do:
Metadata metadata = new MetadataSources(...)
.addResource(...)
.addAnnotatedClass(...)
.buildMetadata( new NamingStrategy() );
Having MetadataSources.buildMetadata( NamingStrategy ) would also allow metadata to be built from the same MetadataSources using different naming strategies.
By putting NamingStrategy in the MetadataSources constructor, MetadataSources would actually have to be recreated in order to build Metadata with different naming strategies.
In the "Build Metadata" section above, I've added:
C) Metadata metadata = sources.buildMetadata( new NamingStrategy() );
(this is OK if there's no need for a MetadataBuilder)
(also allows metadata to be built from the same source multiple
times using different naming strategies)
I like that. Better idea.
Regarding building metadata: After talking with Steve in more detail, I think I agree more with his original design. The call to getMetadataBuilder seems like a useless extra step for the user just to separate the process from the sources involved in the process, and the naming strategy is supposed to be a one-time call. His idea combines the strategy with the sources, which aren't related except via the process to create the metadata, but his main goal was to keep the resulting metadata clean. His original design was this:
Metadata metadata = new MetadataSources(new NamingStrategy() {}).addResource(...).addAnnotatedClass(...).buildMetadata();