private CypherResult doExecuteQuery(String query, boolean canProfile) { long time = System.currentTimeMillis(); Transaction tx = gdb.beginTx(); javax.transaction.Transaction resumeTx; try { resumeTx = suspendTx(query); ExecutionResult result = canProfile ? executionEngine.profile(query) : executionEngine.execute(query); final Collection<Map<String, Object>> data = IteratorUtil.asCollection(result); time = System.currentTimeMillis() - time; resumeTransaction(resumeTx); CypherResult cypherResult = new CypherResult( result.columns(), data, result.getQueryStatistics(), time, canProfile ? result.executionPlanDescription() : null, prettify(query)); tx.success(); return cypherResult; } finally { tx.close(); } }
public static void createData(String filePath) throws IOException { long time = System.currentTimeMillis(); final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(filePath))); Random r = new Random(-1L); for (int nodes = 0; nodes < COUNT; nodes++) { writer.printf("%07d|%07d|%07d%n", nodes, r.nextInt(COUNT), r.nextInt(COUNT)); } writer.close(); System.out.println( "Creating data took " + (System.currentTimeMillis() - time) / 1000 + " seconds"); }
public void importFromFile(String filePath) throws IOException { Map<String, Long> cache = new HashMap<String, Long>(COUNT); final File storeDir = new File(this.path); org.apache.commons.io.FileUtils.deleteDirectory(storeDir); BatchInserter batchInserter = new BatchInserterImpl(storeDir.getAbsolutePath()); final BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(batchInserter); final BatchInserterIndex index = indexProvider.nodeIndex("nodes", MapUtil.stringMap("type", "exact")); BufferedReader reader = new BufferedReader(new FileReader(filePath)); String line = null; int nodes = 0; long time = System.currentTimeMillis(); long batchTime = time; while ((line = reader.readLine()) != null) { final String[] nodeNames = line.split("\\|"); final String name = nodeNames[0]; final Map<String, Object> props = MapUtil.map("name", name); final long node = batchInserter.createNode(props); index.add(node, props); cache.put(name, node); nodes++; if ((nodes % REPORT_COUNT) == 0) { System.out.printf( "%d nodes created. Took %d %n", nodes, (System.currentTimeMillis() - batchTime)); batchTime = System.currentTimeMillis(); } } System.out.println("Creating nodes took " + (System.currentTimeMillis() - time) / 1000); index.flush(); reader.close(); reader = new BufferedReader(new FileReader(filePath)); int rels = 0; time = System.currentTimeMillis(); batchTime = time; String relationshipType = "KNOWS"; while ((line = reader.readLine()) != null) { final String[] nodeNames = line.split("\\|"); final String name = nodeNames[0]; // final Long from = index.get("name", name).getSingle(); Long from = cache.get(name); for (int j = 1; j < nodeNames.length; j++) { // final Long to = index.get("name", nodeNames[j]).getSingle(); final Long to = cache.get(name); batchInserter.createRelationship( from, to, DynamicRelationshipType.withName(relationshipType), null); } rels++; if ((rels % REPORT_COUNT) == 0) { System.out.printf( "%d relationships created. Took %d %n", rels, (System.currentTimeMillis() - batchTime)); batchTime = System.currentTimeMillis(); } } System.out.println("Creating relationships took " + (System.currentTimeMillis() - time) / 1000); indexProvider.shutdown(); batchInserter.shutdown(); }
public static void createJsonData(String filePath) throws IOException { long time = System.currentTimeMillis(); final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(filePath))); Random r = new Random(-1L); int total = 100; for (int nodes = 0; nodes < total; nodes++) { // {"name" : "bar", relationships : [{"to" : "91", "type" : "LOVES", "data" : {"foo" : // "bar"}}]} // {"to" : "91", "type" : "LOVES", "data" : {"foo" : "bar"}} writer.printf("%07d|%07d|%07d%n", nodes, r.nextInt(total), r.nextInt(total)); } writer.close(); System.out.println( "Creating data took " + (System.currentTimeMillis() - time) / 1000 + " seconds"); }
@Test public void testEnableBatchTransactions() throws Exception { System.setProperty(Config.CONFIG_BATCH_TRANSACTION, "true"); Transaction tx = restAPI.beginTx(); tx.failure(); tx.finish(); assertTrue(tx instanceof BatchTransaction); }
@Override public Iterable<Relationship> expand(Path path, BranchState branchState) { if (System.currentTimeMillis() < stopTime) { Long minimumConnectTime = 45L * 60L; // 45 minutes switch (path.length()) { case 0: return path.endNode() .getRelationships(Direction.OUTGOING, RelationshipTypes.HAS_DESTINATION); case 1: { Node lastNode = path.endNode(); if (destinations.contains(((String) lastNode.getProperty("code"))) || exclusions.contains((String) lastNode.getProperty("code"))) { return Collections.emptyList(); } else { return path.endNode().getRelationships(Direction.OUTGOING, relationshipTypes); } } case 2: { return path.endNode().getRelationships(Direction.OUTGOING, relationshipTypes); } case 3: { return path.endNode() .getRelationships(Direction.OUTGOING, RelationshipTypes.HAS_DESTINATION); } case 4: { Node lastNode = path.endNode(); if (destinations.contains(((String) lastNode.getProperty("code")))) { return path.endNode().getRelationships(Direction.OUTGOING, relationshipTypes); } else { return Collections.emptyList(); } } case 5: { Node lastNode = path.endNode(); Iterator<Node> nodes = path.nodes().iterator(); nodes.next(); nodes.next(); Node lastFlight = nodes.next(); if (((Long) lastFlight.getProperty("arrives") + minimumConnectTime) > (Long) lastNode.getProperty("departs")) { return Collections.emptyList(); } if (lastNode.getProperty("code").equals(lastFlight.getProperty("code"))) { return Collections.emptyList(); } else { return path.endNode().getRelationships(Direction.OUTGOING, relationshipTypes); } } default: return Collections.emptyList(); } } else { return Collections.emptyList(); } }
@Before public void init() { System.setProperty(Config.CONFIG_BATCH_TRANSACTION, "true"); this.restAPI = ((RestGraphDatabase) getRestGraphDb()).getRestAPI(); }