Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge branch '1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sarmbruster committed Mar 16, 2013
2 parents 48ec401 + 4863255 commit 2291c81
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
Expand Up @@ -100,6 +100,27 @@ class Neo4jGormInstanceApi<D> extends GormInstanceApi<D> {
traverse(instance, order, stopEvaluator as StopEvaluator, returnableEvaluator as ReturnableEvaluator, args)
}

/**
* 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.
*
Expand Down
Expand Up @@ -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')
Expand Down
Expand Up @@ -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)!
Expand All @@ -20,6 +20,7 @@ class Person implements Serializable {
}
{code}

h3. using map semantics
{code}
when:
def person = new Person(lastName:'person1').save()
Expand All @@ -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
Expand Down

0 comments on commit 2291c81

Please sign in to comment.