How do I instantiate a GraphRepository interface by hand (without using Spring?)

51 views
Skip to first unread message

Josef Karthauser

unread,
Jun 3, 2015, 7:26:44 PM6/3/15
to ne...@googlegroups.com
Hi folks,

Can someone familiar with Spring-Data-Neo4j please tell me how to instantiate a GraphRepository instance without using Spring?

I know I can neo4jTemplate.repositoryFor(DomainClass) to get one, but how do I instantiate an instance of an interface?

i.e.:

    interface MyFooGraph implements GraphRepository(Foo) {
           @Query("SOME CYPHER QUERY WHERE a.property={0} RETURN count(a) <> 0")
           boolean exists(Long id)
    }

How do I, in code, get an instance of a MyFooGraph?

I don't have the luxury of Spring in the current project, but I do want SDN magic.

Many thanks,
Joe

Dan Barron

unread,
Jun 4, 2015, 2:41:07 AM6/4/15
to ne...@googlegroups.com
This is how we instantiate a new instance of an embedded graphdb.

final GraphDatabaseService graphDB = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder("/your/path/to/database/files")
.loadPropertiesFromFile("/your/path/to/database/files/neo4j.properties" )
.newGraphDatabase();

Michael Hunger

unread,
Jun 4, 2015, 3:35:01 AM6/4/15
to ne...@googlegroups.com
You can't without spring except if you are using our upcoming Java-OGM which is used to build SDN4 (but not tied to it).

With spring you just let spring inject you an instance of the repository 

Michael

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dr Josef Karthauser

unread,
Jun 4, 2015, 4:38:02 AM6/4/15
to ne...@googlegroups.com
Thanks Michael.

I’m trying to work out with parts of SDN I can use without a spring container, and which I can’t.

If I take the approach:

    static class Config extends Neo4jConfiguration {
        GraphDatabaseService graphDatabaseService
        Config(GraphDatabaseService service) throws ClassNotFoundException {
            setBasePackage("com.truespeed.truedb");
            this.graphDatabaseService = service
        }

    public GraphDatabaseService graphDatabaseService() {
        return graphDatabaseService;
    }
   }

   def setup() {
        def testGraphDatabaseFactory = new TestGraphDatabaseFactory()
        def graphDatabaseService = testGraphDatabaseFactory.newImpermanentDatabase()
        def ee = new ExecutionEngine(graphDatabaseService)
        def neo4jTemplate = new Neo4jTemplate(graphDatabaseService)
def repo = neo4jTemplate.repositoryFor(Foo)

Is it possible to use my repo without a spring container, or are will it all fall apart if the internals of SDN aren’t wired by spring? (I’m guessing the later).

Is there a steep learning curve around your Java-OGM, and do you have an references that I could chase?

The background is that we’re building a RESTX application, backed by Neo4J. They’ve got a static wiring configuration for speed of deployment, and I’d rather not introduce a spring context if I don’t have to.  However, we’ve got an SDN (3.2.2) with Neo4j (2.1.6) app that we’re porting and I’m trying to remove all the spring as we go.  I’m beginning to feel that I’m on to a hiding to nothing, and it’s not going to be possible with SDN 3.2.2.

We’re not doing much with SDN - our transactions are managed locally (we’re not using @Transactional), and we’re only really using the mapping capabilities of SDN through domain object annotations and then doing everything else directly through neo4jTemplate, using createEntityFromStoredType to map back into the domain. 

The database is embedded; so another option open to us is to host the Neo4j separately and use REST to communicate with it, but there’s a lot of doubt here as to whether Neo4j 2.0 / SDN4.0 work yet with neo4j-spatial in a way that makes the transition worth going through, as it’s a fairly large transition and I believe  that spatial is in some flux right now WRT 2.0.
 
Joe

You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/KXyuYdhZIok/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages