public static SubGraph from( GraphDatabaseService gdb ) { return new DatabaseSubGraph( gdb ); }
private String doExportGraph( GraphDatabaseService db ) { SubGraph graph = DatabaseSubGraph.from( db ); return doExportGraph( graph ); }
@Procedure @Description("apoc.exportJson.json.all(file,config) - exports whole database as json to the provided file") public Stream<ProgressInfo> all(@Name("file") String fileName, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws Exception { String source = String.format("database: nodes(%d), rels(%d)", Util.nodeCount(db), Util.relCount(db)); return exportJson(fileName, source, new DatabaseSubGraph(db), config); }
@Test public void testFromSimpleGraph() { final Node n0 = gdb.createNode(); final Node n1 = gdb.createNode(); n1.setProperty( "name", "Node1" ); final Relationship relationship = n0.createRelationshipTo( n1, RelationshipType.withName( "REL" ) ); relationship.setProperty( "related", true ); final SubGraph graph = DatabaseSubGraph.from( gdb ); assertEquals( "create (_" + n0.getId() + ")" + lineSeparator() + "create (_" + n1.getId() + " {`name`:\"Node1\"})" + lineSeparator() + "create (_" + n0.getId() + ")-[:`REL` {`related`:true}]->(_" + n1.getId() + ")" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); } }
@Procedure @Description("apoc.export.csv.all(file,config) - exports whole database as csv to the provided file") public Stream<ProgressInfo> all(@Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception { String source = String.format("database: nodes(%d), rels(%d)", Util.nodeCount(db), Util.relCount(db)); return exportCsv(fileName, source, new DatabaseSubGraph(db), config); }
@Override public Continuation execute( AppCommandParser parser, Session session, Output out ) throws Exception { if ( parser.arguments().isEmpty() ) // Dump the whole graph { try ( Transaction tx = getServer().getDb().beginTransaction( implicit, AUTH_DISABLED ) ) { getServer().registerTopLevelTransactionInProgress( session.getId() ); final SubGraph graph = DatabaseSubGraph.from( getServer().getDb() ); export( graph, out ); tx.success(); return Continuation.INPUT_COMPLETE; } } else { AppCommandParser newParser = newParser( parser ); return super.execute( newParser, session, out ); } }
@Procedure @Description("apoc.export.graphml.all(file,config) - exports whole database as graphml to the provided file") public Stream<ProgressInfo> all(@Name("file") String fileName, @Name("config") Map<String, Object> config) throws Exception { String source = String.format("database: nodes(%d), rels(%d)", Util.nodeCount(db), Util.relCount(db)); return exportGraphML(fileName, source, new DatabaseSubGraph(db), new ExportConfig(config)); }
@Procedure @Description("apoc.export.cypher.schema(file,config) - exports all schema indexes and constraints to cypher") public Stream<DataProgressInfo> schema(@Name(value = "file",defaultValue = "") String fileName, @Name(value = "config",defaultValue = "{}") Map<String, Object> config) throws IOException { if (Util.isNullOrEmpty(fileName)) fileName=null; String source = String.format("database: nodes(%d), rels(%d)", Util.nodeCount(db), Util.relCount(db)); return exportCypher(fileName, source, new DatabaseSubGraph(db), new ExportConfig(config), true); }
@Procedure @Description("apoc.export.cypher.all(file,config) - exports whole database incl. indexes as cypher statements to the provided file") public Stream<DataProgressInfo> all(@Name(value = "file",defaultValue = "") String fileName, @Name(value = "config",defaultValue = "{}") Map<String, Object> config) throws IOException { if (Util.isNullOrEmpty(fileName)) fileName=null; String source = String.format("database: nodes(%d), rels(%d)", Util.nodeCount(db), Util.relCount(db)); return exportCypher(fileName, source, new DatabaseSubGraph(db), new ExportConfig(config), false); }
public static SubGraph from( GraphDatabaseService gdb ) { return new DatabaseSubGraph( gdb ); }
@Override public Continuation execute(AppCommandParser parser, Session session, Output out) throws Exception { Config config = Config.fromOptions(parser); String fileName = parser.option("o", null); String format = parser.option("f", "kryo"); ProgressReporter reporter = new ProgressReporter(null, out); GraphDatabaseService db = getServer().getDb(); SubGraph graph = new DatabaseSubGraph(db); if (fileName == null) { throw new RuntimeException("Output file option is required"); } switch (format) { case KRYO: writeOutputType(KRYO, fileName); writeKryo(fileName, db, graph, reporter, config); break; case CBOR: throw new RuntimeException(String.format("%s is not supported yet", CBOR)); case PACKSTREAM: throw new RuntimeException(String.format("%s is not supported yet", PACKSTREAM)); } reporter.progress("Wrote to binary file " + fileName); return Continuation.INPUT_COMPLETE; }
@Override public Continuation execute(AppCommandParser parser, Session session, Output out) throws Exception { Config config = Config.fromOptions(parser); String fileName = parser.option("o", null); boolean relsBetween = parser.options().containsKey("r"); Writer writer = FileUtils.getPrintWriter(fileName,out); ProgressReporter reporter = new ProgressReporter(null, out); GraphDatabaseService db = getServer().getDb(); Format exportFormat = new XmlGraphMLFormat(db); String query = Config.extractQuery(parser); SubGraph graph = query.isEmpty() ? new DatabaseSubGraph(db) : cypherResultSubGraph(query,relsBetween); exportFormat.dump(graph, writer, reporter, config); writer.close(); reporter.progress("Wrote to GraphML-file " + fileName); return Continuation.INPUT_COMPLETE; } }
@Override public Continuation execute(AppCommandParser parser, Session session, Output out) throws Exception { Config config = Config.fromOptions(parser); boolean relsBetween = parser.options().containsKey("r"); ProgressReporter reporter = new ProgressReporter(null, out); GraphDatabaseService db = getServer().getDb(); String query = Config.extractQuery(parser); SubGraph graph = query.isEmpty() ? new DatabaseSubGraph(db) : cypherResultSubGraph(query,relsBetween); String fileName = parser.option("o", null); try (Transaction tx = db.beginTx();PrintWriter printWriter = getPrintWriter(fileName, out)) { MultiStatementCypherSubGraphExporter exporter = new MultiStatementCypherSubGraphExporter(graph); exporter.export(printWriter, config.getBatchSize(), reporter); tx.success(); } reporter.progress("Wrote to Cypher-file " + fileName); return Continuation.INPUT_COMPLETE; } }