org.neo4j.kernel.api.exceptions.KernelException Java Examples

The following examples show how to use org.neo4j.kernel.api.exceptions.KernelException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Neo4jDriver.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void read(final String modelPath)
	throws XMLStreamException, IOException, KernelException {
	switch (graphFormat) {
		case CSV:
			readCsv(modelPath);
			break;
		case GRAPHML:
			readGraphMl(modelPath);
			break;
		case CYPHER:
			readCypher(modelPath);
			break;
		default:
			throw new UnsupportedOperationException("Format " + graphFormat + " not supported");
	}
}
 
Example #2
Source File: Neo4jGraphSerializer.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void persistModel() throws IOException, XMLStreamException, KernelException {
	try {
		switch (gc.getGraphFormat()) {
		case CSV:
			saveToCsv();
			break;
		case GRAPHML:
			saveToGraphMl();
			break;
		default:
			throw new UnsupportedOperationException("Graph format " + gc.getGraphFormat() + " not supported.");
		}
	} finally {
		graphDb.shutdown();

		// cleanup: delete the database directory
		cleanupDatabaseDirectory();
	}
}
 
Example #3
Source File: TestUtil.java    From atlas with GNU General Public License v3.0 5 votes vote down vote up
public static void registerProcedure(GraphDatabaseService db, Class<?>...procedures) throws KernelException {
    Procedures proceduresService = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(Procedures.class);
    for (Class<?> procedure : procedures) {
        proceduresService.registerProcedure(procedure,true);
        proceduresService.registerFunction(procedure, true);
        proceduresService.registerAggregationFunction(procedure, true);
    }
}
 
Example #4
Source File: Neo4jDriver.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
private void readGraphMl(String modelPath) throws FileNotFoundException, XMLStreamException, KernelException {
	startDb();

	ApocHelper.registerProcedure(graphDb, ExportGraphML.class, Graphs.class);
	try (final Transaction t = graphDb.beginTx()) {
		graphDb.execute(String.format( //
			"CALL apoc.import.graphml('%s', {batchSize: 10000, readLabels: true})", //
			modelPath //
		));
		t.success();
	}
}
 
Example #5
Source File: Neo4jApiTransformationRepairSwitchSet.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<Neo4jSwitchSetMatch> matches) throws KernelException {
	for (final Neo4jSwitchSetMatch match : matches) {
		final Node sw = match.getSw();
		final String position = match.getPosition();
		sw.setProperty(CURRENTPOSITION, position);
	}
}
 
Example #6
Source File: ApocHelper.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
public static void registerProcedure(GraphDatabaseService db, Class<?>...procedures) throws KernelException {
	Procedures proceduresService = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(Procedures.class);
	for (Class<?> procedure : procedures) {
		proceduresService.registerProcedure(procedure);
		proceduresService.registerFunction(procedure);
	}
}
 
Example #7
Source File: Neo4jGraphSerializer.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
private void saveToCsv() throws RemoteException, KernelException {
	ApocHelper.registerProcedure(graphDb, ExportCSV.class, Graphs.class);

	final Map<String, String> exportCommands = ImmutableMap.<String, String>builder()
			// nodes
			.put(ModelConstants.REGION,         "MATCH (n:Region)              RETURN n.id AS `id:ID`") //
			.put(ModelConstants.ROUTE,          "MATCH (n:Route)               RETURN n.id AS `id:ID`, n.active AS `active:BOOLEAN`") //
			.put(ModelConstants.SEGMENT,        "MATCH (n:Segment)             RETURN n.id AS `id:ID`, n.length AS `length:INT`") //
			.put(ModelConstants.SEMAPHORE,      "MATCH (n:Semaphore)           RETURN n.id AS `id:ID`, n.signal AS signal") //
			.put(ModelConstants.SENSOR,         "MATCH (n:Sensor)              RETURN n.id AS `id:ID`") //
			.put(ModelConstants.SWITCH,         "MATCH (n:Switch)              RETURN n.id AS `id:ID`, n.currentPosition AS currentPosition") //
			.put(ModelConstants.SWITCHPOSITION, "MATCH (n:SwitchPosition)      RETURN n.id AS `id:ID`, n.position AS position") //
			// relationships
			.put(ModelConstants.CONNECTS_TO,    "MATCH (n)-[:connectsTo]->(m)  RETURN n.id AS `id:START_ID`, m.id AS `id:END_ID`") //
			.put(ModelConstants.ENTRY,          "MATCH (n)-[:entry]->(m)       RETURN n.id AS `id:START_ID`, m.id AS `id:END_ID`") //
			.put(ModelConstants.EXIT,           "MATCH (n)-[:exit]->(m)        RETURN n.id AS `id:START_ID`, m.id AS `id:END_ID`") //
			.put(ModelConstants.FOLLOWS,        "MATCH (n)-[:follows]->(m)     RETURN n.id AS `id:START_ID`, m.id AS `id:END_ID`") //
			.put(ModelConstants.MONITORED_BY,   "MATCH (n)-[:monitoredBy]->(m) RETURN n.id AS `id:START_ID`, m.id AS `id:END_ID`") //
			.put(ModelConstants.REQUIRES,       "MATCH (n)-[:requires]->(m)    RETURN n.id AS `id:START_ID`, m.id AS `id:END_ID`") //
			.put(ModelConstants.TARGET,         "MATCH (n)-[:target]->(m)      RETURN n.id AS `id:START_ID`, m.id AS `id:END_ID`") //
			.build();

	for (Entry<String, String> entry : exportCommands.entrySet()) {
		final String type = entry.getKey();
		final String query = entry.getValue();

		final String fileName = gc.getConfigBase().getModelPathWithoutExtension() + "-" + type + "."
				+ Neo4jConstants.CSV_EXTENSION;

		try (final Transaction t = graphDb.beginTx()) {
			graphDb.execute(String.format( //
				"CALL apoc.export.csv.query('%s', '%s', null)", //
				query,
				fileName //
			));
		}
	}
}
 
Example #8
Source File: Neo4jGraphSerializer.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
private void saveToGraphMl() throws KernelException {
	ApocHelper.registerProcedure(graphDb, ExportGraphML.class, Graphs.class);

	final String fileName = gc.getConfigBase().getModelPathWithoutExtension() + Neo4jConstants.GRAPHML_POSTFIX;

	try (final Transaction t = graphDb.beginTx()) {
		graphDb.execute(String.format( //
			"CALL apoc.export.graphml.all('%s', {useTypes: true})", //
			fileName //
		));
	}
}
 
Example #9
Source File: CoderadarTestApplication.java    From coderadar with MIT License 5 votes vote down vote up
@Bean
public GraphDatabaseService graphDatabaseService() throws KernelException {
  GraphDatabaseService db =
      new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().newGraphDatabase();
  registerProcedure(
      db,
      apoc.path.RelationshipSequenceExpander.class,
      apoc.path.PathExplorer.class,
      apoc.cypher.Cypher.class,
      apoc.graph.Graphs.class,
      apoc.path.RelationshipTypeAndDirections.class);
  return db;
}
 
Example #10
Source File: CoderadarTestApplication.java    From coderadar with MIT License 5 votes vote down vote up
@Bean
public SessionFactory sessionFactory() throws KernelException {
  EmbeddedDriver driver = new EmbeddedDriver(graphDatabaseService(), null);
  return new SessionFactory(
      driver,
      "io.reflectoring.coderadar.graph.projectadministration.domain",
      "io.reflectoring.coderadar.graph.analyzer.domain",
      "io.reflectoring.coderadar.graph.query.domain",
      "io.reflectoring.coderadar.graph.useradministration.domain",
      "io.reflectoring.coderadar.graph.contributor.domain");
}
 
Example #11
Source File: CoderadarTestApplication.java    From coderadar with MIT License 5 votes vote down vote up
public static void registerProcedure(GraphDatabaseService db, Class<?>... procedures)
    throws KernelException {
  Procedures proceduresService =
      ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(Procedures.class);
  for (Class<?> procedure : procedures) {
    proceduresService.registerProcedure(procedure, true);
    proceduresService.registerFunction(procedure, true);
  }
}
 
Example #12
Source File: AtlasProceduresTest.java    From atlas with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void prepare() throws KernelException {
    db = new TestGraphDatabaseFactory().newImpermanentDatabase();
    TestUtil.registerProcedure(db, AtlasProcedures.class);
}