Re: Issue with enhancement of annotations

2017-07-21 Thread Craig Russell
Hi Andy,

> On Jul 21, 2017, at 8:05 AM, Andy Jefferson  wrote:
> 
>> I updated the pom.xml to 5.1.1-SNAPSHOT and the enhancer step worked but
>> many tck tests fail. [1]
> 
> I'd suggest that is down to whatever is different in your TCK from the SVN 
> trunk TCK ...

Clearly this is the case. The class/interface/annotation that is being 
complained about is the new composite annotation.

The failure is in a subclass of a class that has the new annotation. 
FCDSMedicalInsurance extends FCDSInsurance.

I've prepared a patch that shows the error. Can you please try it and let me 
know what you think the problem is.

https://issues.apache.org/jira/browse/JDO-764

Thanks,

Craig

[1]
Insert of object 
"org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSMedicalInsurance@5553d0f5" using 
statement "INSERT INTO DATASTOREIDENTITY0.FCDSINSURANCE 
(CARRIER,EMPLOYEE,INSID,PLANTYPE,DISCRIMINATOR) VALUES (?,?,?,?,?)" failed : 
Table/View 'DATASTOREIDENTITY0.FCDSINSURANCE' does not exist.
org.datanucleus.exceptions.NucleusDataStoreException: Insert of object 
"org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSMedicalInsurance@5553d0f5" using 
statement "INSERT INTO DATASTOREIDENTITY0.FCDSINSURANCE 
(CARRIER,EMPLOYEE,INSID,PLANTYPE,DISCRIMINATOR) VALUES (?,?,?,?,?)" failed : 
Table/View 'DATASTOREIDENTITY0.FCDSINSURANCE' does not exist.


> because SVN trunk works fine with current DN code, and the only 
> change in my fix is ignoring classes that are annotations, hence no 
> persistable classes will be ignored due to this check.
> 
> 
> Regards
> -- 
> Andy
> DataNucleus (Web: http://www.datanucleus.org   Twitter: @datanucleus)

Craig L Russell
c...@apache.org



[jira] [Updated] (JDO-764) Allow JDO annotations to be used in meta-annotations

2017-07-21 Thread Craig L Russell (JIRA)

 [ 
https://issues.apache.org/jira/browse/JDO-764?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Craig L Russell updated JDO-764:

Attachment: jdo-764.patch

With this patch, and DataNucleus 5.1.1-SNAPSHOT of 21-July-2017, enhancement 
works but there are failures running tck tests:

Insert of object 
"org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSMedicalInsurance@5553d0f5" using 
statement "INSERT INTO DATASTOREIDENTITY0.FCDSINSURANCE 
(CARRIER,EMPLOYEE,INSID,PLANTYPE,DISCRIMINATOR) VALUES (?,?,?,?,?)" failed : 
Table/View 'DATASTOREIDENTITY0.FCDSINSURANCE' does not exist.
org.datanucleus.exceptions.NucleusDataStoreException: Insert of object 
"org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSMedicalInsurance@5553d0f5" using 
statement "INSERT INTO DATASTOREIDENTITY0.FCDSINSURANCE 
(CARRIER,EMPLOYEE,INSID,PLANTYPE,DISCRIMINATOR) VALUES (?,?,?,?,?)" failed : 
Table/View 'DATASTOREIDENTITY0.FCDSINSURANCE' does not exist.


> Allow JDO annotations to be used in meta-annotations
> 
>
> Key: JDO-764
> URL: https://issues.apache.org/jira/browse/JDO-764
> Project: JDO
>  Issue Type: Improvement
>  Components: api, specification
>Affects Versions: JDO 3.1
>Reporter: Andy Jefferson
> Fix For: JDO 3.2
>
> Attachments: jdo-764.patch
>
>
> By default annotations are used directly in a persistable class. Java 
> additionally allows annotations to be formed of other annotations. This is 
> particularly useful where a user has a particular combination of annotations 
> to set on a class/field/method and wants to simply annotate with an 
> abbreviated form. For example, specifying attributes of an annotation
> @PersistenceCapable(detachable="true", identityType="datastore", 
> embeddedOnly="true")
> or formed of multiple annotations
> @PersistenceCapable(detachable="true")
> @Extension(vendorName="datanucleus", key="multitenancy-column-name", 
> value="TENANT")
> These can be represented as meta-annotations like this
> @Target(TYPE)
> @Retention(RUNTIME)
> @PersistenceCapable(detachable="true", identityType="datastore", 
> embeddedOnly="true")
> public @interface DatastoreIdPersistable
> {
> }
> @Target(TYPE)
> @Retention(RUNTIME)
> @PersistenceCapable(detachable="true")
> @Extension(vendorName="datanucleus", key="multitenancy-column-name", 
> value="TENANT")
> public @interface MultitenantPersistable
> {
> }
> and the user can subsequently just annotate their persistable class as
> @DatastoreIdPersistable
> public class MyClass1 {...}
> @MultitenantPersistable
> public class MyClass2 {...}
> The work required to support this in the JDO spec is simply to update the 
> following annotations to add @Target({ElementType.ANNOTATION_TYPE})
> The annotations requiring this are
> @Element, @EmbeddedId, @Key, @NotPersistent, @Order, @Persistent, 
> @Serialized, @Transactional, and @Value  (all other annotations already have 
> @Target({ElementType.TYPE}) which already permits their usage in 
> meta-annotations.
> The same is proposed for JPA 2.2, see 
> https://github.com/javaee/jpa-spec/issues/43



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Updated] (JDO-764) Allow JDO annotations to be used in meta-annotations

2017-07-21 Thread Craig L Russell (JIRA)

 [ 
https://issues.apache.org/jira/browse/JDO-764?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Craig L Russell updated JDO-764:

Attachment: (was: jdo-764.patch)

> Allow JDO annotations to be used in meta-annotations
> 
>
> Key: JDO-764
> URL: https://issues.apache.org/jira/browse/JDO-764
> Project: JDO
>  Issue Type: Improvement
>  Components: api, specification
>Affects Versions: JDO 3.1
>Reporter: Andy Jefferson
> Fix For: JDO 3.2
>
>
> By default annotations are used directly in a persistable class. Java 
> additionally allows annotations to be formed of other annotations. This is 
> particularly useful where a user has a particular combination of annotations 
> to set on a class/field/method and wants to simply annotate with an 
> abbreviated form. For example, specifying attributes of an annotation
> @PersistenceCapable(detachable="true", identityType="datastore", 
> embeddedOnly="true")
> or formed of multiple annotations
> @PersistenceCapable(detachable="true")
> @Extension(vendorName="datanucleus", key="multitenancy-column-name", 
> value="TENANT")
> These can be represented as meta-annotations like this
> @Target(TYPE)
> @Retention(RUNTIME)
> @PersistenceCapable(detachable="true", identityType="datastore", 
> embeddedOnly="true")
> public @interface DatastoreIdPersistable
> {
> }
> @Target(TYPE)
> @Retention(RUNTIME)
> @PersistenceCapable(detachable="true")
> @Extension(vendorName="datanucleus", key="multitenancy-column-name", 
> value="TENANT")
> public @interface MultitenantPersistable
> {
> }
> and the user can subsequently just annotate their persistable class as
> @DatastoreIdPersistable
> public class MyClass1 {...}
> @MultitenantPersistable
> public class MyClass2 {...}
> The work required to support this in the JDO spec is simply to update the 
> following annotations to add @Target({ElementType.ANNOTATION_TYPE})
> The annotations requiring this are
> @Element, @EmbeddedId, @Key, @NotPersistent, @Order, @Persistent, 
> @Serialized, @Transactional, and @Value  (all other annotations already have 
> @Target({ElementType.TYPE}) which already permits their usage in 
> meta-annotations.
> The same is proposed for JPA 2.2, see 
> https://github.com/javaee/jpa-spec/issues/43



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


Re: Issue with enhancement of annotations

2017-07-21 Thread Andy Jefferson
> I updated the pom.xml to 5.1.1-SNAPSHOT and the enhancer step worked but
> many tck tests fail. [1]

I'd suggest that is down to whatever is different in your TCK from the SVN 
trunk TCK ... because SVN trunk works fine with current DN code, and the only 
change in my fix is ignoring classes that are annotations, hence no 
persistable classes will be ignored due to this check.


Regards
-- 
Andy
DataNucleus (Web: http://www.datanucleus.org   Twitter: @datanucleus)


Re: Issue with enhancement of annotations

2017-07-21 Thread Craig Russell
Hi Andy,

> On Jul 20, 2017, at 11:40 PM, Andy Jefferson  wrote:
> 
> Hi Craig,
> 
>> It looks like the DN enhancer recognizes the annotation as a
>> persistence-capable class because it is annotated with PersistenceCapable
>> but doesn't recognize it as an annotation that should not be enhanced.
> 
> Quite probably. I've only been enhancing through a persistence.xml file 
> recently, which explicitly specifies the classes to be enhanced so never hit 
> that one.
> 
>> I looked at the code and think that perhaps a patch like this would fix it.
>> org.datanucleus.enhancer.ClassEnhancerImpl around line 298 after the cls
>> object is obtained:
>> 
>>if (cls.isAnnotation())
>>{
>>return false;
>>}
>> 
>> Other possible solutions: move the composite annotations out of the package
>> into a sibling package. This probably works but is awkward.
> 
> No, let's just fix the code rather than imposing the user has to do something.

I agree. That didn't work anyway (see subsequent message for details).
> 
> Instead of doing your proposed fix, I put a couple of checks in further 
> upstream, where it reads annotations for a class to check if it is has 
> metadata. 
> 
> See https://github.com/datanucleus/datanucleus-core/commit/
> f048a37494066b46545a1849d536104dc149950d
> 
> A simple test with that fix, explicitly adding the meta-annotation class to 
> persistence.xml results in a log message that the class has no metadata and 
> is 
> ignored.
> 
> That should be in current DN nightly builds, so give it a try and see if it 
> catches your situation. 

I updated the pom.xml to 5.1.1-SNAPSHOT and the enhancer step worked but many 
tck tests fail. [1]

Thanks,

Craig

09:58:35,295 (main) INFO  [DataNucleus.JDO] - Exception thrown
Class 
"org.apache.jdo.tck.pc.companyAnnotatedFC.DatastoreIdDiscriminatorClassNameInheritanceSuperclass"
 has been specified with an inheritance strategy of "superclass-table", yet no 
superclass exists or none exists with its own table!
org.datanucleus.metadata.InvalidClassMetaDataException: Class 
"org.apache.jdo.tck.pc.companyAnnotatedFC.DatastoreIdDiscriminatorClassNameInheritanceSuperclass"
 has been specified with an inheritance strategy of "superclass-table", yet no 
superclass exists or none exists with its own table!
at 
org.datanucleus.metadata.AbstractClassMetaData.validateUserInputForInheritanceMetaData(AbstractClassMetaData.java:874)
at 
org.datanucleus.metadata.InterfaceMetaData.populate(InterfaceMetaData.java:120)
at 
org.datanucleus.metadata.MetaDataManagerImpl$1.run(MetaDataManagerImpl.java:2926)
at java.security.AccessController.doPrivileged(Native Method)
at 
org.datanucleus.metadata.MetaDataManagerImpl.populateAbstractClassMetaData(MetaDataManagerImpl.java:2920)
at 
org.datanucleus.metadata.MetaDataManagerImpl.populateFileMetaData(MetaDataManagerImpl.java:2724)
at 
org.datanucleus.metadata.MetaDataManagerImpl.initialiseFileMetaDataForUse(MetaDataManagerImpl.java:1365)
at 
org.datanucleus.metadata.MetaDataManagerImpl.loadClasses(MetaDataManagerImpl.java:645)
at 
org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:672)
at 
org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:500)
at org.datanucleus.api.jdo.JDOEnhancer.enhance(JDOEnhancer.java:125)
at org.apache.jdo.exectck.Enhance.execute(Enhance.java:288)
at 
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at 
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at 
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at 
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at 
org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 

Re: Issue with enhancement of annotations

2017-07-21 Thread Andy Jefferson
Hi Craig,

> It looks like the DN enhancer recognizes the annotation as a
> persistence-capable class because it is annotated with PersistenceCapable
> but doesn't recognize it as an annotation that should not be enhanced.

Quite probably. I've only been enhancing through a persistence.xml file 
recently, which explicitly specifies the classes to be enhanced so never hit 
that one.

> I looked at the code and think that perhaps a patch like this would fix it.
> org.datanucleus.enhancer.ClassEnhancerImpl around line 298 after the cls
> object is obtained:
> 
> if (cls.isAnnotation())
> {
> return false;
> }
> 
> Other possible solutions: move the composite annotations out of the package
> into a sibling package. This probably works but is awkward.

No, let's just fix the code rather than imposing the user has to do something.

Instead of doing your proposed fix, I put a couple of checks in further 
upstream, where it reads annotations for a class to check if it is has 
metadata. 

See https://github.com/datanucleus/datanucleus-core/commit/
f048a37494066b46545a1849d536104dc149950d

A simple test with that fix, explicitly adding the meta-annotation class to 
persistence.xml results in a log message that the class has no metadata and is 
ignored.

That should be in current DN nightly builds, so give it a try and see if it 
catches your situation. 




Regards
-- 
Andy
DataNucleus (Web: http://www.datanucleus.org   Twitter: @datanucleus)