Permalink
Browse files

Merge branch '1.x'

  • Loading branch information...
2 parents 48ec401 + 4863255 commit 2291c81df1ca93559deb72eb98fceffe144a78be @sarmbruster sarmbruster committed Mar 16, 2013
@@ -101,6 +101,27 @@ class Neo4jGormInstanceApi<D> extends GormInstanceApi<D> {
}
/**
+ * Allows accessing to dynamic properties with the dot operator
+ *
+ * @param instance The instance
+ * @param name The property name
+ * @return The property value
+ */
+ def propertyMissing(D instance, String name) {
+ getAt(instance, name)
+ }
+
+ /**
+ * Allows setting a dynamic property via the dot operator
+ * @param instance The instance
+ * @param name The property name
+ * @param val The value
+ */
+ def propertyMissing(D instance, String name, val) {
+ putAt(instance, name, val)
+ }
+
+ /**
* Allows subscript access to schemaless attributes.
*
* @param instance The instance
@@ -160,6 +160,30 @@ class ApiExtensionsSpec extends GormDatastoreSpec {
person['someDoubleArray'] == [0.9, 1.0, 1.1]
}
+ def "test handling of non-declared properties using dot notation"() {
+ when:
+ def person = new Person(lastName:'person1').save(flush:true)
+ session.clear()
+ person = Person.load(person.id)
+ person.notDeclaredProperty = 'someValue' // n.b. the 'dot' notation is not valid for undeclared properties
+ person.emptyArray = []
+ person.someIntArray = [1,2,3]
+ person.someStringArray = ['a', 'b', 'c']
+ person.someDoubleArray= [0.9, 1.0, 1.1]
+ session.flush()
+ session.clear()
+ person = Person.get(person.id)
+
+ then:
+ person.notDeclaredProperty == 'someValue'
+ person.lastName == 'person1' // declared properties are also available via map semantics
+ person.someIntArray == [1,2,3]
+ person.someStringArray == ['a', 'b', 'c']
+ person.emptyArray == []
+ person.someDoubleArray == [0.9, 1.0, 1.1]
+ }
+
+
def "test handling of non-declared properties on transient instance"() {
when:
def person = new Person(lastName:'person1')
@@ -2,8 +2,8 @@ h1. schemaless attributes
h2. Purpose
-For domain classes mapped by Neo4j you can put and get arbitrary attributes on a instances by using map semantics on the
-domain instance.
+For domain classes mapped by Neo4j you can put and get arbitrary attributes on a instances by using the dot operator or
+map semantics on the domain instance.
{note}
Setting arbitrary attribute in only allowed when the domain instance is persisted (aka @save@ has been called)!
@@ -20,6 +20,7 @@ class Person implements Serializable {
}
{code}
+h3. using map semantics
{code}
when:
def person = new Person(lastName:'person1').save()
@@ -40,6 +41,30 @@ person['someStringArray'] == ['a', 'b', 'c']
person['someDoubleArray'] == [0.9, 1.0, 1.1]
{code}
+h3. using dot operator
+{code}
+when:
+def person = new Person(lastName:'person1').save(flush:true)
+session.clear()
+person = Person.load(person.id)
+person.notDeclaredProperty = 'someValue' // n.b. the 'dot' notation is not valid for undeclared properties
+person.emptyArray = []
+person.someIntArray = [1,2,3]
+person.someStringArray = ['a', 'b', 'c']
+person.someDoubleArray= [0.9, 1.0, 1.1]
+session.flush()
+session.clear()
+person = Person.get(person.id)
+
+then:
+person.notDeclaredProperty == 'someValue'
+person.lastName == 'person1' // declared properties are also available via map semantics
+person.someIntArray == [1,2,3]
+person.someStringArray == ['a', 'b', 'c']
+person.emptyArray == []
+person.someDoubleArray == [0.9, 1.0, 1.1]
+{code}
+
h2. Description
The non declared attribtes are stored a regular properties on the domain instance's node. The values of the schemaless

0 comments on commit 2291c81

Please sign in to comment.