////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

If you wish to use GORM for Neo4j outside of a Grails application you should declare the necessary dependencies, for example in Gradle:

[source,groovy,subs="attributes"]
----
compile "org.grails:grails-datastore-gorm-neo4j:{version}"
----

Then annotate your entities with the `grails.gorm.annotation.Entity` annotation and implement the link:../api/grails/neo4j/Node.html[Node] trait:

[source,groovy]
----
import grails.neo4j.*
import grails.gorm.annotation.*

@Entity
class Person implements Node<Person>{
    String name
}
----

Then you need to place the bootstrap logic somewhere in your application which uses link:../api/org/grails/datastore/gorm/neo4j/Neo4jDatastore.html[Neo4jDatastore]:

[source,groovy]
----
def datastore = new Neo4jDatastore(Person)

println Person.count()
----

For configuration you can either pass a map or an instance of the `org.springframework.core.env.PropertyResolver` interface:

[source,groovy]
----
def datastore = new Neo4jDatastore(['grails.neo4j.url':'bolt://...'], Person)

println Person.count()
----

If you are using Spring with an existing `ApplicationContext` you can instead call use link:../api/grails/neo4j/bootstrap/Neo4jDataStoreSpringInitializer.html[Neo4jDataStoreSpringInitializer] and call `configureForBeanDefinitionRegistry` prior to refreshing the context. You can pass the Spring `Environment` object to the constructor for configuration:

[source,groovy]
----
ApplicationContext myApplicationContext = ...
def initializer = new Neo4jDataStoreSpringInitializer(myApplicationContext.getEnvironment(), Person)
initializer.configureForBeanDefinitionRegistry(myApplicationContext)

println Person.count()
----
