db-jdo
db-jdo copied to clipboard
[JDO-709] Enable Element.TYPE for @Convert
This reverts commit bddffaba0384d1393b9091461ad9eaba0d9848b8 to be consistent with its javadoc.
With this capability, we can avoid as much configuration file as possible, it's very convenient to mark default attribute converter for a type with Java annotation.
Reference: https://issues.apache.org/jira/browse/JDO-709?focusedCommentId=17619585&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17619585
Notify some authors touched this file, please have a look, thanks! @clr-apache @mboapache @tobous
The original goal for having Element.Type apply to @Convert was to allow a PersistenceCapable class to have all of the field convert annotations in one place at the definition of the class instead of needing the annotation on each field/property. But this requires new properties on @Convert to identify the field plus the converter for each field. We decided that this use case was not really needed.
But a different use, case recently identified by @Dieken is to annotate the field type for a user-defined class that will by default always use the converter regardless of which PersistenceCapable class the field is defined in. This use case requires the Element.Type to be supported by @Convert.
Note that the JPA annotation supports this use case and therefore there should be minimal changes needed to DataNucleus to support JDO in addition to JPA which is already supported. Perhaps @andyjefferson can comment on whether this can be done easily or if it already should work with JDO if the annotation is enabled.
To properly support this use case we should have TCK tests for it. There are already test cases for AttributeConverters which should have a new test added.
One test case should annotate a new user-defined type with @Convert and verify that the converter is used for date between memory and the datastore. Another test case should override the default case and verify that the override conversion is used instead of the conversion defined in the annotation for the class.