Skip to content

Commit

Permalink
allow easy programmatic registration of procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
bachmanm committed Sep 21, 2016
1 parent 784e1a7 commit ff30180
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

package com.graphaware.module.timetree.proc;

import com.graphaware.module.timetree.SingleTimeTree;
import com.graphaware.module.timetree.TimeTreeBackedEvents;
import com.graphaware.module.timetree.TimedEvents;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.exceptions.KernelException;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.neo4j.kernel.api.exceptions.KernelException;

@Component
public class TimeTreeProcedures {
Expand All @@ -35,6 +35,19 @@ public class TimeTreeProcedures {
private final Procedures procedures;
private final TimedEvents timedEvents;

public static void register(GraphDatabaseService database) {
try {
new TimeTreeProcedures(database).init();
} catch (KernelException e) {
throw new RuntimeException(e);
}
}

private TimeTreeProcedures(GraphDatabaseService database) {
this.database = database;
this.procedures = ((GraphDatabaseAPI) database).getDependencyResolver().resolveDependency(Procedures.class);
this.timedEvents = new TimeTreeBackedEvents(new SingleTimeTree(database));
}

@Autowired
public TimeTreeProcedures(GraphDatabaseService database, TimedEvents timedEvents, Procedures procedures) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2013-2016 GraphAware
*
* This file is part of the GraphAware Framework.
*
* GraphAware Framework is free software: you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of
* the GNU General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/

package com.graphaware.module.timetree.proc;

import com.graphaware.module.timetree.module.TimeTreeConfiguration;
import com.graphaware.module.timetree.module.TimeTreeModule;
import com.graphaware.runtime.GraphAwareRuntime;
import com.graphaware.runtime.GraphAwareRuntimeFactory;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.test.TestGraphDatabaseFactory;

public class ProgrammaticProcedureRegistrationTest {

@Test
public void canRegisterProceduresProgrammatically() {
GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();

GraphAwareRuntime runtime = GraphAwareRuntimeFactory.createRuntime(database);
runtime.registerModule(new TimeTreeModule("timetree", TimeTreeConfiguration.defaultConfiguration(), database));
runtime.start();

TimeTreeProcedures.register(database);

database.execute("CALL ga.timetree.now({})");
}
}

0 comments on commit ff30180

Please sign in to comment.