////
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.
////

By default, the GORM compiler ensures that all GORM entities implement the `GormEntity` trait, which provides them with all the default GORM methods. Nevertheless, if there's a need to extend GORM functionality to incorporate additional methods tailored to a specific datastore, you can achieve this by extending the `GormEntity` trait.

For example Neo4j adds methods for Cypher querying:

[source,groovy]
----
trait Neo4jEntity<D> extends GormEntity<D> {

    static Result cypherStatic(String queryString, Map params ) {
        def session = AbstractDatastore.retrieveSession(Neo4jDatastore)
        def graphDatabaseService = (GraphDatabaseService)session.nativeInterface
        graphDatabaseService.execute(queryString, params)
    }
}
----

With this addition, you need to instruct the GORM compiler to make entities implement this trait. To achieve this, implement a `TraitProvider`:

[source,groovy]
----
package org.grails.datastore.gorm.neo4j

import grails.neo4j.Neo4jEntity
import groovy.transform.CompileStatic
import org.grails.compiler.gorm.GormEntityTraitProvider

@CompileStatic
class Neo4jEntityTraitProvider implements GormEntityTraitProvider {
    final Class entityTrait = Neo4jEntity
}
----

And then add a `src/main/resources/META-INF/services/org.grails.compiler.gorm.GormEntityTraitProvider` file specifying the name of your trait provider:

----
org.grails.datastore.gorm.neo4j.Neo4jEntityTraitProvider
----

GORM will automatically inject the trait into any domain class discovered in `grails-app/domain` or annotated with the `Entity` annotation. However, if Hibernate is present on the classpath, you must inform GORM to map the domain class with Neo4j:

[,groovy]
----
static mapWith = "neo4j"
----


