Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ protected void registerEventListeners(ConfigurableApplicationEventPublisher even
protected GormEnhancer initialize(Neo4jConnectionSourceSettings settings) {
registerEventListeners(this.eventPublisher);

// Must run before the GormEnhancer constructor (below) registers this datastore's entities,
// otherwise GormRegistry falls back to the generic DefaultGormApiFactory for them.
org.grails.datastore.gorm.GormRegistry.getInstance().registerApiFactory(Neo4jDatastore.class, new Neo4jGormApiFactory());

this.mappingContext.addMappingContextListener(new MappingContext.Listener() {
@Override
public void persistentEntityAdded(PersistentEntity entity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.
*/
package org.grails.datastore.gorm.neo4j

import groovy.transform.CompileStatic

import org.grails.datastore.gorm.DatastoreResolver
import org.grails.datastore.gorm.DefaultGormApiFactory
import org.grails.datastore.gorm.GormRegistry
import org.grails.datastore.gorm.finders.FinderMethod
import org.grails.datastore.gorm.neo4j.api.Neo4jGormStaticApi
import org.grails.datastore.mapping.model.MappingContext

/**
* Neo4j-specific {@link org.grails.datastore.gorm.GormApiFactory} that creates a
* {@link Neo4jGormStaticApi} instead of the generic {@code GormStaticApi}. Without it the
* {@link GormRegistry} falls back to the {@link DefaultGormApiFactory}, whose generic
* {@code GormStaticApi} breaks casts like {@code (Neo4jGormStaticApi) GormEnhancer.findStaticApi(...)}
* used by {@code Neo4jEntity}/{@code Node} for {@code cypherStatic}, {@code findRelationship},
* {@code findPath}, etc. The instance and validation APIs reuse the generic GORM implementations
* inherited from {@link DefaultGormApiFactory}, matching {@code Neo4jDatastore}'s existing
* {@code GormEnhancer} overrides.
*/
@CompileStatic
class Neo4jGormApiFactory extends DefaultGormApiFactory {

@Override
<D> Neo4jGormStaticApi<D> createStaticApi(Class<D> persistentClass, MappingContext mappingContext, DatastoreResolver resolver, String qualifier, GormRegistry registry) {
Neo4jDatastore neo4jDatastore = (Neo4jDatastore) resolver.resolve()
List<FinderMethod> finders = createDynamicFinders(resolver, mappingContext)
return new Neo4jGormStaticApi<D>(persistentClass, neo4jDatastore, finders, neo4jDatastore.getTransactionManager())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ package grails.gorm.tests


import org.apache.grails.data.neo4j.core.Neo4jGormDatastoreSpec
import spock.lang.PendingFeature
import org.neo4j.driver.Result

/**
* @author graemerocher
*/
class CypherQueryStringSpec extends Neo4jGormDatastoreSpec {

@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - static cypher/string-query calls resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test execute update method"() {
given:
setupDomain()
Expand All @@ -43,7 +40,6 @@ class CypherQueryStringSpec extends Neo4jGormDatastoreSpec {
club.ground == "Alliance Arena"
}

@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - static cypher/string-query calls resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test find method that accepts cypher"() {
given:
setupDomain()
Expand Down Expand Up @@ -87,7 +83,6 @@ class CypherQueryStringSpec extends Neo4jGormDatastoreSpec {
team.club.name == 'FC Bayern Muenchen'
}

@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - static cypher/string-query calls resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test findAll method that accepts cypher"() {
given:
setupDomain()
Expand Down Expand Up @@ -132,7 +127,6 @@ class CypherQueryStringSpec extends Neo4jGormDatastoreSpec {
result.next().get('n').asMap().get('name') == name
}

@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - static cypher/string-query calls resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "Test convert nodes using asType for a cypher result"() {
given:
setupDomain()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package grails.gorm.tests

import org.apache.grails.data.neo4j.core.Neo4jGormDatastoreSpec
import grails.gorm.annotation.Entity
import spock.lang.PendingFeature

/**
* @author graemerocher
Expand All @@ -45,7 +44,6 @@ class NativeIdentityGeneratorSpec extends Neo4jGormDatastoreSpec {
Competition.get(c2.id).id == 1L
}

@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Competition's static API always resolves to the generic GormStaticApi, whose saveAll() has its own bug (returns flush()'s null instead of the persisted ids). Neo4jGormStaticApi#saveAll already fixes this but is unreachable until PR2 wires up the factory")
void "Test native id generator save multiple"() {
when:"An entity with a native id is persisted"
def c1 = new Competition(name:"FA Cup")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package grails.gorm.tests

import org.apache.grails.data.neo4j.core.Neo4jGormDatastoreSpec
import spock.lang.Issue
import spock.lang.PendingFeature

/**
* @author graemerocher
Expand All @@ -31,7 +30,6 @@ class OneToManyUpdateSpec extends Neo4jGormDatastoreSpec {


@Issue('https://github.com/apache/grails-data-mapping/issues/575')
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Club.cypherStatic(...) resolves to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "Test updates to one to many don't create duplicate relationships"() {
given:" a one to many relationship"
Club club = new Club(name:"Manchester United")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import org.grails.datastore.mapping.multitenancy.AllTenantsResolver
import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException
import org.grails.datastore.mapping.multitenancy.resolvers.SystemPropertyTenantResolver
import spock.lang.AutoCleanup
import spock.lang.PendingFeature
import spock.lang.Shared
import spock.lang.Specification

Expand Down Expand Up @@ -63,7 +62,6 @@ class MultiTenancySpec extends Specification {
System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, "")
}

@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - CompanyC.find(cypher, params) resolves to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "Test persist and retrieve entities with multi tenancy"() {
when:"A tenant id is present"
System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, "test1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import grails.gorm.transactions.Rollback
import grails.neo4j.Path
import org.grails.datastore.gorm.neo4j.Neo4jDatastore
import spock.lang.AutoCleanup
import spock.lang.PendingFeature
import spock.lang.Shared
import spock.lang.Specification

Expand All @@ -36,7 +35,6 @@ class PathSpec extends Specification {
@Shared @AutoCleanup Neo4jDatastore datastore = new Neo4jDatastore(getClass().getPackage())

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findShortestPath/findPath/findPathTo resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test simple shortest path with findShortestPath"() {

given:
Expand Down Expand Up @@ -76,7 +74,6 @@ class PathSpec extends Specification {
}

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findShortestPath/findPath/findPathTo resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test simple shortest path with findShortestPath with proxies"() {
given:
def barney = new Person(name: "Barney")
Expand Down Expand Up @@ -110,7 +107,6 @@ class PathSpec extends Specification {
}

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findShortestPath/findPath/findPathTo resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test simple shortest path"() {
given:
def barney = new Person(name: "Barney")
Expand Down Expand Up @@ -142,7 +138,6 @@ class PathSpec extends Specification {
}

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findShortestPath/findPath/findPathTo resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test simple shortest pathTo"() {
given:
def barney = new Person(name: "Barney")
Expand Down Expand Up @@ -174,7 +169,6 @@ class PathSpec extends Specification {
}

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findShortestPath/findPath/findPathTo resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test shortest path with arguments"() {
given:
def barney = new Person(name: "Barney")
Expand Down Expand Up @@ -206,7 +200,6 @@ class PathSpec extends Specification {
}

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findShortestPath/findPath/findPathTo resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test shortest path with gstring arguments"() {
given:
def barney = new Person(name: "Barney")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import grails.neo4j.Path
import grails.neo4j.Relationship
import org.grails.datastore.gorm.neo4j.Neo4jDatastore
import spock.lang.AutoCleanup
import spock.lang.PendingFeature
import spock.lang.Shared
import spock.lang.Specification

Expand All @@ -36,7 +35,6 @@ class RelationshipSpec extends Specification {
@Shared @AutoCleanup Neo4jDatastore datastore = new Neo4jDatastore(getClass().getPackage())

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findRelationship(s) resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test find relationship"() {
given:
def barney = new Person(name: "Barney")
Expand Down Expand Up @@ -64,7 +62,6 @@ class RelationshipSpec extends Specification {
}

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findRelationship(s) resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test find relationships"() {
given:
def barney = new Person(name: "Barney")
Expand Down Expand Up @@ -93,7 +90,6 @@ class RelationshipSpec extends Specification {
}

@Rollback
@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - Person.findRelationship(s) resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
void "test find relationships for types"() {
given:
def barney = new Person(name: "Barney")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import grails.gorm.tests.Club
import grails.gorm.tests.League
import grails.gorm.tests.Team
import org.apache.grails.data.neo4j.core.Neo4jGormDatastoreSpec
import spock.lang.PendingFeature

/**
* check the traverser extension
Expand All @@ -34,7 +33,6 @@ class ApiExtensionsSpec extends Neo4jGormDatastoreSpec {
manager.registerDomainClasses(Club, Team, League)
}

@PendingFeature(reason = "Neo4jGormApiFactory isn't registered with GormRegistry yet (PR2 scope) - static cypher calls resolve to the generic GormStaticApi instead of Neo4jGormStaticApi")
def "test cypher queries"() {
setup:
new Club(name:'person1').save()
Expand Down
Loading