solomax commented on code in PR #186:
URL: https://github.com/apache/openjpa/pull/186#discussion_r4011838166
##########
openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java:
##########
@@ -650,17 +655,40 @@ public static PersistenceUnitInfoImpl
convert(PersistenceConfiguration config) {
pinfo.setTransactionType(config.transactionType() ==
jakarta.persistence.PersistenceUnitTransactionType.JTA ?
PersistenceUnitTransactionType.JTA :
PersistenceUnitTransactionType.RESOURCE_LOCAL);
pinfo.setValidationMode(config.validationMode());
- List<Class<?>> managedClasses = config.managedClasses();
- if (managedClasses != null && !managedClasses.isEmpty()) {
- String managedClassesList =
managedClasses.stream().map(Class::getName).collect(Collectors.joining(";"));
- String old =
config.properties().containsKey("openjpa.MetaDataFactory")
- ? "," +
config.properties().get("openjpa.MetaDataFactory").toString()
- : "";
- config.property("openjpa.MetaDataFactory", "jpa(Types="
+ managedClassesList + old + ")");
+ for (Class<?> managedClass : config.managedClasses()) {
+ pinfo.addManagedClassName(managedClass.getName());
+ }
+ for (String mappingFile : config.mappingFiles()) {
+ pinfo.addMappingFileName(mappingFile);
}
- config.property("openjpa.noPersistenceXMLResource", true);
- pinfo.setPersistenceUnitName(config.name());
return pinfo;
}
+
+ /**
+ * Returns a copy of the properties of the given configuration,
completed with
+ * the OpenJPA specific properties derived from it. The given
configuration is
+ * left untouched.
+ */
+ public static Map<String, Object> toProperties(PersistenceConfiguration
config) {
+ Map<String, Object> props = new HashMap<>(config.properties());
+ Properties metaFactoryProps = new Properties();
+ if (!config.managedClasses().isEmpty()) {
+ metaFactoryProps.put("Types",
config.managedClasses().stream().map(Class::getName)
+ .collect(Collectors.joining(";")));
+ }
+ if (!config.mappingFiles().isEmpty()) {
+ metaFactoryProps.put("Resources", String.join(";",
config.mappingFiles()));
+ }
+ if (!metaFactoryProps.isEmpty()) {
+ // the user properties take precedence over the ones
derived from the unit info,
+ // so merge the locations into any user provided
metadata factory
+ String key =
ProductDerivations.getConfigurationKey("MetaDataFactory", props);
+ Object old = props.get(key);
+ props.put(key, Configurations.combinePlugins(old ==
null ? null : old.toString(),
+
Configurations.serializeProperties(metaFactoryProps)));
+ }
+ props.put("openjpa.noPersistenceXMLResource", true);
Review Comment:
this one is dropped in next PR ....
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]