Skip to content

Commit

Permalink
GRAILS-6662 - improving the handling of domain classes that extend Ja…
Browse files Browse the repository at this point in the history
…va classes under src/java. This work is still pending testing, specifically as it relates to GRAILS-6405 and GRAILS-3209.
  • Loading branch information
Jeff Brown committed Sep 9, 2010
1 parent 6c7f77b commit d438a67
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Expand Up @@ -196,19 +196,15 @@ private void injectVersionProperty(ClassNode classNode) {
final boolean hasVersion = GrailsASTUtils.hasOrInheritsProperty(classNode, GrailsDomainClassProperty.VERSION);

if (!hasVersion) {
ClassNode parent = GrailsASTUtils.getFurthestParent(classNode);
parent.addProperty(GrailsDomainClassProperty.VERSION, Modifier.PUBLIC, new ClassNode(Long.class), null, null, null);
classNode.addProperty(GrailsDomainClassProperty.VERSION, Modifier.PUBLIC, new ClassNode(Long.class), null, null, null);
}
}

private void injectIdProperty(ClassNode classNode) {
final boolean hasId = GrailsASTUtils.hasOrInheritsProperty(classNode, GrailsDomainClassProperty.IDENTITY);

if (!hasId) {
// inject into furthest relative
ClassNode parent = GrailsASTUtils.getFurthestParent(classNode);

parent.addProperty(GrailsDomainClassProperty.IDENTITY, Modifier.PUBLIC, new ClassNode(Long.class), null, null, null);
classNode.addProperty(GrailsDomainClassProperty.IDENTITY, Modifier.PUBLIC, new ClassNode(Long.class), null, null, null);
}
}

Expand Down
@@ -0,0 +1,4 @@
package org.codehaus.groovy.grails.orm.hibernate;

public class AbstractJavaClass {
}
@@ -0,0 +1,19 @@
package org.codehaus.groovy.grails.orm.hibernate

class JavaInheritanceTests extends AbstractGrailsHibernateTests{
protected void onSetUp() {
gcl.parseClass '''
import grails.persistence.*
@Entity
class MyDomainClass extends org.codehaus.groovy.grails.orm.hibernate.AbstractJavaClass {
String someProperty
}
'''
}

void testInheritingFromAbstractJavaClass() {
def mdc = ga.getDomainClass("MyDomainClass")
assertNotNull 'MyDomainClass is not considered a domain class', mdc
}
}

0 comments on commit d438a67

Please sign in to comment.