Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

List of ParameterizedType as property fix

  • Loading branch information...
commit e50fa726471905481599afd05e854b53044f1cd2 1 parent 4c6a4f6
@jkuehn authored
View
2  MongodbMorphiaGrailsPlugin.groovy
@@ -20,7 +20,7 @@ class MongodbMorphiaGrailsPlugin {
def scm = [ url: "https://github.com/jkuehn/gorm-mongodb" ]
// the plugin version
- def version = "0.7.6"
+ def version = "0.7.7"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.4 > *"
// the other plugins this plugin depends on
View
2  README.textile
@@ -4,7 +4,7 @@ h2. MongoDB GORM plugin for Grails
You will find a list of all domain class methods and other information in the "User Guide":http://jkuehn.github.com/gorm-mongodb/
-Built with "IntelliJ IDEA":http://www.jetbrains.com/idea/
+Built with "IntelliJ IDEA":http://www.jetbrains.com/idea/ and kindly supported with "JProfiler":http://www.ej-technologies.com/products/jprofiler/overview.html
Special thanks to the contributors:
* Hubert Chang
View
10 application.properties
@@ -1,9 +1,9 @@
#Grails Metadata file
-#Thu Dec 01 14:28:19 CET 2011
-app.grails.version=2.0.0.RC2
+#Sun Dec 18 19:25:18 CET 2011
+app.grails.version=2.0.0
app.name=mongodb-morphia
-app.version=0.7.6
-plugins.hibernate=2.0.0.RC2
+app.version=0.7.7
+plugins.hibernate=2.0.0
plugins.release=1.0.0.RC3
plugins.svn=1.0.0.M1
-plugins.tomcat=2.0.0.RC2
+plugins.tomcat=2.0.0
View
17 plugin.xml
@@ -1,4 +1,4 @@
-<plugin name='mongodb-morphia' version='0.7.5' grailsVersion='1.3.4 &gt; *'>
+<plugin name='mongodb-morphia' version='0.7.6' grailsVersion='1.3.4 &gt; *'>
<author>Juri Kuehn</author>
<authorEmail>juri.kuehn at gmail.com</authorEmail>
<title>Alternative MongoDB GORM based on the Morphia library</title>
@@ -12,8 +12,21 @@
<resource>org.acme.inheritance.User</resource>
<resource>org.acme.Contact</resource>
</resources>
+ <repositories>
+ <repository name='grailsCentral' url='http://plugins.grails.org' />
+ <repository name='http://repo.grails.org/grails/plugins' url='http://repo.grails.org/grails/plugins/' />
+ <repository name='http://repo.grails.org/grails/core' url='http://repo.grails.org/grails/core/' />
+ <repository name='grailsCore' url='http://svn.codehaus.org/grails/trunk/grails-plugins' />
+ <repository name='mavenCentral' url='http://repo1.maven.org/maven2/' />
+ </repositories>
<dependencies>
- <plugin name='core' version='1.3.4 &gt; *' />
+ <runtime>
+ <dependency group='org.mongodb' name='mongo-java-driver' version='2.6' />
+ </runtime>
</dependencies>
+ <plugins />
+ <runtimePluginRequirements>
+ <plugin name='core' version='1.3.4 &gt; *' />
+ </runtimePluginRequirements>
<behavior />
</plugin>
View
428 src/java/grails/plugins/mongodb/MongoDomainClassProperty.java
@@ -20,241 +20,245 @@
* Date: 02.06.2010
*/
public class MongoDomainClassProperty implements GrailsDomainClassProperty {
- private Class ownerClass;
- private Field field;
- private String name;
- private Class type;
- private MongoDomainClass domainClass;
- private Method getter;
- private boolean persistent = true;
- private boolean identity = false;
-
- public MongoDomainClassProperty(MongoDomainClass domain, Field field, PropertyDescriptor descriptor) {
- this.ownerClass = domain.getClazz();
- this.domainClass = domain;
- this.field = field;
- this.name = descriptor.getName();
- this.type = descriptor.getPropertyType();
- this.getter = descriptor.getReadMethod();
- this.persistent = checkPersistence(descriptor, field);
-
- checkIfTransient();
- }
-
- private boolean checkPersistence(PropertyDescriptor descriptor, Field field) {
- // no transients
- if ((field.getModifiers() & Modifier.TRANSIENT) > 0 || field.getAnnotation(Transient.class) != null) {
- return false;
- }
-
- // check if type is supported
- if (!MappedClass.isSupportedType(field.getType())
- && field.getAnnotation(Embedded.class) == null
- && field.getAnnotation(Reference.class) == null) {
- return false;
- }
- // check if groovy/java property
- if (descriptor.getName().equals("class")
- || descriptor.getName().equals("metaClass")) {
- return false;
- }
-
- return true;
- }
-
- // Checks whether this property is transient... copied from DefaultGrailsDomainClassProperty.
- private void checkIfTransient() {
- if (isAnnotatedWith(Transient.class)) {
- this.persistent = false;
-
- } else {
- List transientProps = getTransients(domainClass);
- if (transientProps != null) {
- for (Object currentObj : transientProps) {
- // make sure its a string otherwise ignore. Note: Again maybe a warning?
- if (currentObj instanceof String) {
- String propertyName = (String) currentObj;
-
- // if the property name is on the not persistant list
- // then set persistant to false
- if (propertyName.equals(this.name)) {
- this.persistent = false;
- if (!isAnnotatedWith(Transient.class))
- domainClass.log(ownerClass.getName() + "." + this.name + " should be annotated with morphias Transient!");
- break;
+ private Class ownerClass;
+ private Field field;
+ private String name;
+ private Class type;
+ private MongoDomainClass domainClass;
+ private Method getter;
+ private boolean persistent = true;
+ private boolean identity = false;
+
+ public MongoDomainClassProperty(MongoDomainClass domain, Field field, PropertyDescriptor descriptor) {
+ this.ownerClass = domain.getClazz();
+ this.domainClass = domain;
+ this.field = field;
+ this.name = descriptor.getName();
+ this.type = descriptor.getPropertyType();
+ this.getter = descriptor.getReadMethod();
+ this.persistent = checkPersistence(descriptor, field);
+
+ checkIfTransient();
+ }
+
+ private boolean checkPersistence(PropertyDescriptor descriptor, Field field) {
+ // no transients
+ if ((field.getModifiers() & Modifier.TRANSIENT) > 0 || field.getAnnotation(Transient.class) != null) {
+ return false;
+ }
+
+ // check if type is supported
+ if (!MappedClass.isSupportedType(field.getType())
+ && field.getAnnotation(Embedded.class) == null
+ && field.getAnnotation(Reference.class) == null) {
+ return false;
+ }
+ // check if groovy/java property
+ if (descriptor.getName().equals("class")
+ || descriptor.getName().equals("metaClass")) {
+ return false;
+ }
+
+ return true;
+ }
+
+ // Checks whether this property is transient... copied from DefaultGrailsDomainClassProperty.
+ private void checkIfTransient() {
+ if (isAnnotatedWith(Transient.class)) {
+ this.persistent = false;
+
+ } else {
+ List transientProps = getTransients(domainClass);
+ if (transientProps != null) {
+ for (Object currentObj : transientProps) {
+ // make sure its a string otherwise ignore. Note: Again maybe a warning?
+ if (currentObj instanceof String) {
+ String propertyName = (String) currentObj;
+
+ // if the property name is on the not persistant list
+ // then set persistant to false
+ if (propertyName.equals(this.name)) {
+ this.persistent = false;
+ if (!isAnnotatedWith(Transient.class))
+ domainClass.log(ownerClass.getName() + "." + this.name + " should be annotated with morphias Transient!");
+ break;
+ }
+ }
+ }
}
- }
}
- }
- }
- }
-
- // Retrieves the transient properties... copied from DefaultGrailsDomainClassProperty.
- private List getTransients(GrailsDomainClass domainClass) {
- List transientProps;
- transientProps = domainClass.getPropertyValue(TRANSIENT, List.class);
-
- // Undocumented feature alert! Steve insisted on this :-)
- List evanescent = domainClass.getPropertyValue(EVANESCENT, List.class);
- if (evanescent != null) {
- if (transientProps == null) {
- transientProps = new ArrayList();
- }
-
- transientProps.addAll(evanescent);
- }
- return transientProps;
- }
-
- public int getFetchMode() {
- return FETCH_EAGER;
- }
-
- public String getName() {
- return this.name;
- }
-
- public Class getType() {
- return this.type;
- }
-
- public Class getReferencedPropertyType() {
- if (Collection.class.isAssignableFrom(getType())) {
- final Type genericType = field.getGenericType();
- if (genericType instanceof ParameterizedType) {
- final Type[] arguments = ((ParameterizedType) genericType).getActualTypeArguments();
- if (arguments.length > 0) {
- return (Class) arguments[0];
+ }
+
+ // Retrieves the transient properties... copied from DefaultGrailsDomainClassProperty.
+ private List getTransients(GrailsDomainClass domainClass) {
+ List transientProps;
+ transientProps = domainClass.getPropertyValue(TRANSIENT, List.class);
+
+ // Undocumented feature alert! Steve insisted on this :-)
+ List evanescent = domainClass.getPropertyValue(EVANESCENT, List.class);
+ if (evanescent != null) {
+ if (transientProps == null) {
+ transientProps = new ArrayList();
+ }
+
+ transientProps.addAll(evanescent);
}
- }
+ return transientProps;
}
- return getType();
- }
- public GrailsDomainClassProperty getOtherSide() {
- return null;
- }
+ public int getFetchMode() {
+ return FETCH_EAGER;
+ }
- public String getTypePropertyName() {
- return GrailsNameUtils.getPropertyName(getType());
- }
+ public String getName() {
+ return this.name;
+ }
- public GrailsDomainClass getDomainClass() {
- return domainClass;
- }
+ public Class getType() {
+ return this.type;
+ }
- public boolean isPersistent() {
- return persistent;
- }
+ public Class getReferencedPropertyType() {
+ if (Collection.class.isAssignableFrom(getType())) {
+ final Type genericType = field.getGenericType();
+ if (genericType instanceof ParameterizedType) {
+ final Type[] arguments = ((ParameterizedType) genericType).getActualTypeArguments();
+ if (arguments.length > 0) {
+ if (arguments[0] instanceof ParameterizedType) { // in case it is also parameterized, e.g. List<Key<DomainClass>>
+ return (Class)((ParameterizedType)arguments[0]).getRawType();
+ } else if (arguments[0] instanceof Class) {
+ return (Class)arguments[0];
+ }
+ }
+ }
+ }
+ return getType();
+ }
+
+ public GrailsDomainClassProperty getOtherSide() {
+ return null;
+ }
+
+ public String getTypePropertyName() {
+ return GrailsNameUtils.getPropertyName(getType());
+ }
+
+ public GrailsDomainClass getDomainClass() {
+ return domainClass;
+ }
+
+ public boolean isPersistent() {
+ return persistent;
+ }
- public boolean isOptional() {
- ConstrainedProperty constrainedProperty = (ConstrainedProperty) domainClass.getConstrainedProperties().get(name);
- return (constrainedProperty != null) && constrainedProperty.isNullable();
- }
+ public boolean isOptional() {
+ ConstrainedProperty constrainedProperty = (ConstrainedProperty) domainClass.getConstrainedProperties().get(name);
+ return (constrainedProperty != null) && constrainedProperty.isNullable();
+ }
- public boolean isIdentity() {
- return identity;
- }
+ public boolean isIdentity() {
+ return identity;
+ }
- public void setIdentity(boolean identity) {
- this.identity = identity;
- }
+ public void setIdentity(boolean identity) {
+ this.identity = identity;
+ }
- public boolean isOneToMany() {
- return false;
- }
+ public boolean isOneToMany() {
+ return false;
+ }
- public boolean isManyToOne() {
- return false;
- }
+ public boolean isManyToOne() {
+ return false;
+ }
- public boolean isManyToMany() {
- return false;
- }
+ public boolean isManyToMany() {
+ return false;
+ }
- public boolean isBidirectional() {
- return false;
- }
+ public boolean isBidirectional() {
+ return false;
+ }
- public String getFieldName() {
- return getName().toUpperCase();
- }
+ public String getFieldName() {
+ return getName().toUpperCase();
+ }
- public boolean isOneToOne() {
- return false;
- }
+ public boolean isOneToOne() {
+ return false;
+ }
- public GrailsDomainClass getReferencedDomainClass() {
- return null;
- }
+ public GrailsDomainClass getReferencedDomainClass() {
+ return null;
+ }
- public boolean isAssociation() {
- return false;
- }
+ public boolean isAssociation() {
+ return false;
+ }
- public boolean isEnum() {
- return false;
- }
+ public boolean isEnum() {
+ return false;
+ }
- public String getNaturalName() {
- return GrailsNameUtils.getNaturalName(name);
- }
+ public String getNaturalName() {
+ return GrailsNameUtils.getNaturalName(name);
+ }
- public void setReferencedDomainClass(GrailsDomainClass referencedGrailsDomainClass) {
+ public void setReferencedDomainClass(GrailsDomainClass referencedGrailsDomainClass) {
- }
+ }
- public void setOtherSide(GrailsDomainClassProperty referencedProperty) {
+ public void setOtherSide(GrailsDomainClassProperty referencedProperty) {
- }
+ }
- public boolean isInherited() {
- return false;
- }
+ public boolean isInherited() {
+ return false;
+ }
- public boolean isOwningSide() {
- return false;
- }
+ public boolean isOwningSide() {
+ return false;
+ }
- public boolean isCircular() {
- return getType().equals(ownerClass);
- }
+ public boolean isCircular() {
+ return getType().equals(ownerClass);
+ }
- public String getReferencedPropertyName() {
- return null;
- }
+ public String getReferencedPropertyName() {
+ return null;
+ }
- public boolean isEmbedded() {
- return false;
- }
+ public boolean isEmbedded() {
+ return false;
+ }
- public GrailsDomainClass getComponent() {
- return null;
- }
+ public GrailsDomainClass getComponent() {
+ return null;
+ }
- public void setOwningSide(boolean b) {
+ public void setOwningSide(boolean b) {
- }
+ }
- public boolean isBasicCollectionType() {
- // @todo cache result?
- Class c = this.type;
- boolean found = (c == Collection.class);
- while (c != null && !found) {
- found = (ArrayUtils.contains(c.getInterfaces(), Collection.class));
- c = c.getSuperclass();
+ public boolean isBasicCollectionType() {
+ // @todo cache result?
+ Class c = this.type;
+ boolean found = (c == Collection.class);
+ while (c != null && !found) {
+ found = (ArrayUtils.contains(c.getInterfaces(), Collection.class));
+ c = c.getSuperclass();
+ }
+ return found;
}
- return found;
- }
- public boolean isAnnotatedWith(Class annotation) {
- return (field != null && field.getAnnotation(annotation) != null) || (getter != null && getter.getAnnotation(annotation) != null);
- }
+ public boolean isAnnotatedWith(Class annotation) {
+ return (field != null && field.getAnnotation(annotation) != null) || (getter != null && getter.getAnnotation(annotation) != null);
+ }
- // grails 1.2 GrailsDomainClass
- public boolean isHasOne() {
- return false;
- }
+ // grails 1.2 GrailsDomainClass
+ public boolean isHasOne() {
+ return false;
+ }
public void setDerived(boolean derived) {
// no action
@@ -265,18 +269,18 @@ public boolean isDerived() {
}
public String toString() {
- String assType = null;
- if (isManyToMany()) {
- assType = "many-to-many";
- } else if (isOneToMany()) {
- assType = "one-to-many";
- } else if (isOneToOne()) {
- assType = "one-to-one";
- } else if (isManyToOne()) {
- assType = "many-to-one";
- } else if (isEmbedded()) {
- assType = "embedded";
- }
- return new ToStringBuilder(this).append("name", this.name).append("type", this.type).append("persistent", isPersistent()).append("optional", isOptional()).append("association", isAssociation()).append("bidirectional", isBidirectional()).append("association-type", assType).toString();
- }
+ String assType = null;
+ if (isManyToMany()) {
+ assType = "many-to-many";
+ } else if (isOneToMany()) {
+ assType = "one-to-many";
+ } else if (isOneToOne()) {
+ assType = "one-to-one";
+ } else if (isManyToOne()) {
+ assType = "many-to-one";
+ } else if (isEmbedded()) {
+ assType = "embedded";
+ }
+ return new ToStringBuilder(this).append("name", this.name).append("type", this.type).append("persistent", isPersistent()).append("optional", isOptional()).append("association", isAssociation()).append("bidirectional", isBidirectional()).append("association-type", assType).toString();
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.