Java 类org.neo4j.graphdb.ResourceIterator 实例源码

项目:dnainator    文件:AnalyzeCommand.java   
/**
 * Scores the amount of drug resistance mutations.
 * @param service   the graph service
 */
private void scoreDRMutations(GraphDatabaseService service) {
    Map<String, Object> params = new HashMap<>(1);
    service.findNodes(NodeLabels.DRMUTATION).forEachRemaining(drannotations ->
        drannotations.getRelationships(RelTypes.ANNOTATED).forEach(node -> {
            // From the startref of the annotation
            // subtract the startref of the annotated node
            // and add the base distance of the annotated node
            int basedist = (int) drannotations.getProperty(AnnotationProperties.STARTREF.name())
                - (int) node.getStartNode().getProperty(SequenceProperties.STARTREF.name())
                + (int) node.getStartNode().getProperty(SequenceProperties.BASE_DIST.name());

            params.put("dist", basedist);
            ResourceIterator<Node> mutations = service.execute(GET_NODES_BASEDIST, params)
                                .columnAs(LABEL);
            mutations.forEachRemaining(m -> {
                int score = (int) m.getProperty(Scores.DR_MUT.name(), 0);
                m.setProperty(Scores.DR_MUT.name(), score + 1);
            });
        })
    );
}
项目:dnainator    文件:Neo4jGraph.java   
@Override
public void addAnnotation(Annotation a) {
    Map<String, Object> parameters = new HashMap<>(2);
    parameters.put("from", a.getStart());
    parameters.put("to", a.getEnd());
    execute(e -> {
        Node annotation = e.createNode(NodeLabels.ANNOTATION);
        annotation.setProperty(AnnotationProperties.ID.name(), a.getGeneName());
        annotation.setProperty(AnnotationProperties.STARTREF.name(), a.getStart());
        annotation.setProperty(AnnotationProperties.ENDREF.name(), a.getEnd());
        annotation.setProperty(AnnotationProperties.SENSE.name(), a.isSense());

        ResourceIterator<Node> nodes = service.execute(GET_REF_RANGE, parameters).columnAs("n");
        nodes.forEachRemaining(n -> n.createRelationshipTo(annotation, RelTypes.ANNOTATED));
    });
}
项目:neo4j-lucene5-index    文件:LuceneSnapshotter.java   
ResourceIterator<File> snapshot( File indexDir, LuceneIndexWriter writer ) throws IOException
{
    SnapshotDeletionPolicy deletionPolicy = (SnapshotDeletionPolicy) writer.getIndexDeletionPolicy();

    try
    {
        return new LuceneSnapshotIterator( indexDir, deletionPolicy.snapshot(), deletionPolicy );
    }
    catch(IllegalStateException e)
    {
        if(e.getMessage().equals( NO_INDEX_COMMIT_TO_SNAPSHOT ))
        {
            return emptyIterator();
        }
        throw e;
    }
}
项目:neo4j-lucene5-index    文件:LuceneSnapshotterTest.java   
@Test
public void shouldReturnRealSnapshotIfIndexAllowsIt() throws Exception
{
    // Given
    LuceneSnapshotter snapshotter = new LuceneSnapshotter();

    when(luceneSnapshot.getFileNames()).thenReturn( asList("a", "b") );

    // When
    ResourceIterator<File> snapshot = snapshotter.snapshot( indexDir, writer );

    // Then
    assertEquals( new File(indexDir, "a"), snapshot.next() );
    assertEquals( new File(indexDir, "b"), snapshot.next() );
    assertFalse( snapshot.hasNext() );
    snapshot.close();

    verify( snapshotPolicy ).release( any(IndexCommit.class) );
}
项目:neo4j-lucene5-index    文件:LuceneSnapshotterTest.java   
@Test
public void shouldReturnEmptyIteratorWhenNoCommitsHaveBeenMade() throws Exception
{
    // Given
    LuceneSnapshotter snapshotter = new LuceneSnapshotter();

    when(luceneSnapshot.getFileNames()).thenThrow( new IllegalStateException( "No index commit to snapshot" ));

    // When
    ResourceIterator<File> snapshot = snapshotter.snapshot( indexDir, writer );

    // Then
    assertFalse( snapshot.hasNext() );
    snapshot.close();

    verify( snapshotPolicy ).snapshot();
    verifyNoMoreInteractions( snapshotPolicy );
}
项目:knowledge-extraction    文件:Neo4JDb.java   
private Node getNode(Label label, String key, Object value) {
    Node node = null;
    try (Transaction tx = graphDb.beginTx()) {
        ResourceIterator<Node> nodes = null;
        if (label != null){
            nodes = graphDb.findNodesByLabelAndProperty(
                label, key, value).iterator();
        }
        else {
            String validValue = StringEscapeUtils.escapeJavaScript((String) value);
            ExecutionEngine engine = new ExecutionEngine(graphDb);
            nodes = engine.execute(
                    "START n=node(*)"
                    + " WHERE n." + key + "=\"" + validValue + "\""
                    + " RETURN n").columnAs("n");

        }
        if (nodes.hasNext()) {
            node = nodes.next();
        }
        nodes.close();
    }
    return node;
}
项目:neoprofiler    文件:QueryRunner.java   
public Map<String,List<Object>> runQueryComplexResult(NeoProfiler parent, String query, String...columns) {
    HashMap<String,List<Object>> all = new HashMap<String,List<Object>>();

    ExecutionEngine engine = new ExecutionEngine(parent.getDB());
    List<Object> retvals = new ArrayList<Object>();

    try ( Transaction tx = parent.getDB().beginTx() ) {
        // log.info(query);
        ExecutionResult result = engine.execute(query);

        ResourceIterator<Map<String,Object>> rows = result.iterator();

        while(rows.hasNext()) {
            Map<String,Object> row = rows.next();

            for(String col : columns) { 
                if(!all.containsKey(col)) all.put(col, new ArrayList<Object>());
                all.get(col).add(row.get(col));
            }
        }

        rows.close();
    } // End try

    return all;
}
项目:neoprofiler    文件:QueryRunner.java   
public Object runQuerySingleResult(NeoProfiler parent, String query, String columnReturn) {     
    ExecutionEngine engine = new ExecutionEngine(parent.getDB());

    try ( Transaction tx = parent.getDB().beginTx() ) {
        // log.info(query);
        ExecutionResult result = engine.execute(query);
        ResourceIterator<Object> vals = result.columnAs(columnReturn);

        if(vals.hasNext()) {
            Object retval = vals.next();
            vals.close();
            return retval;
        } 

        return null;
    }       
}
项目:neoprofiler    文件:QueryRunner.java   
public List<Object> runQueryMultipleResult(NeoProfiler parent, String query, String columnReturn) {
    ExecutionEngine engine = new ExecutionEngine(parent.getDB());
    List<Object> retvals = new ArrayList<Object>();

    try ( Transaction tx = parent.getDB().beginTx() ) {
        // log.info(query);
        ExecutionResult result = engine.execute(query);
        ResourceIterator<Object> rit = result.columnAs(columnReturn);

        while(rit.hasNext()) {              
            retvals.add(rit.next());
        }                   
    }

    return retvals;
}
项目:csvtreeloader    文件:CSVTreeBuilder.java   
/**
 * This version of the findOrMakeNode method only uses the index (or
 * cache) to find the nodes, because they are roots of their own trees.
 */
protected Node findOrMakeNode(String propertyValue, Map<String, String> record) {
    // First look in the cache
    Node node = cachedRoots.get(propertyValue);
    if (node == null) {
        // Then use the schema index to find the node
        parameters.put(this.column.property, propertyValue);
        ResourceIterator<Object> resultIterator = engine.execute(queryString, parameters).columnAs("n");
        node = (Node) resultIterator.next();
        if (node == null) {
            // Finally make a new node if none found
            node = super.findOrMakeNode(propertyValue, record);
        }
        cachedRoots.put(propertyValue, node);
    }
    return node;
}
项目:extended-objects    文件:EmbeddedNeo4jRepository.java   
@Override
protected <T> ResultIterable<T> find(EmbeddedLabel label, PropertyMetadata datastoreMetadata, Object datastoreValue) {
    String propertyName = datastoreMetadata.getName();
    ResourceIterator<Node> iterator = graphDatabaseService.findNodes(label.getDelegate(), propertyName, datastoreValue);
    return xoSession.toResult(new ResultIterator<EmbeddedNode>() {

        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public EmbeddedNode next() {
            return new EmbeddedNode(iterator.next());
        }

        @Override
        public void close() {
            iterator.close();
        }
    });
}
项目:extended-objects    文件:GraphDbBootstrapTest.java   
@Test
public void bootstrap() throws URISyntaxException {
    GraphDatabaseService graphDatabaseService = new TestGraphDatabaseFactory().newImpermanentDatabase();
    XOUnit xoUnit = XOUnitBuilder.create("graphDb:///", Neo4jXOProvider.class, A.class).property(GraphDatabaseService.class.getName(), graphDatabaseService).create();
    XOManagerFactory xoManagerFactory = XO.createXOManagerFactory(xoUnit);
    XOManager xoManager = xoManagerFactory.createXOManager();
    xoManager.currentTransaction().begin();
    A a = xoManager.create(A.class);
    a.setName("Test");
    xoManager.currentTransaction().commit();
    xoManager.close();
    xoManagerFactory.close();
    try (Transaction transaction = graphDatabaseService.beginTx()) {
        ResourceIterator<Node> iterator = graphDatabaseService.findNodes(label("A"), "name", "Test");
        assertThat(iterator.hasNext(), equalTo(true));
        Node node = iterator.next();
        assertThat(node.hasLabel(label("A")), equalTo(true));
        assertThat(node.getProperty("name"), equalTo((Object) "Test"));
        transaction.success();
    }
}
项目:graphdb-benchmarks    文件:Neo4jSingleInsertion.java   
public Node getOrCreate(String nodeId)
{
    Node result = null;

    try(final Transaction tx = ((GraphDatabaseAPI) neo4jGraph).tx().unforced().begin())
    {
        try
        {
            String queryString = "MERGE (n:Node {nodeId: {nodeId}}) RETURN n";
            Map<String, Object> parameters = new HashMap<String, Object>();
            parameters.put("nodeId", nodeId);
            ResourceIterator<Node> resultIterator = engine.execute(queryString, parameters).columnAs("n");
            result = resultIterator.next();
            tx.success();
        }
        catch (Exception e)
        {
            tx.failure();
            throw new BenchmarkingException("unable to get or create node " + nodeId, e);
        }
    }

    return result;
}
项目:WhiteLab2.0-Neo4J-Plugin    文件:IndexWarmUp.java   
@Override
    public void run() {
        try (Transaction tx = database.beginTx())
        {
            writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Warming up "+nodeLabel.toString()+" index...\n");
            writer.flush();
            int d = 0;

            ResourceIterator<Node> it = database.findNodes(nodeLabel);

            while (it.hasNext()) {
                Node node = it.next();
//              Boolean has_token_count = false;
                for (String prop : node.getPropertyKeys()) {
                    node.getProperty(prop);
                }

                for (Relationship in : node.getRelationships(Direction.INCOMING)) {
                    @SuppressWarnings("unused")
                    Node other = in.getOtherNode(node);
//                  for (String prop : other.getPropertyKeys()) {
//                      other.getProperty(prop);
//                  }
                }
                d++;
                if (d % 50000 == 0) {
                    writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - "+nodeLabel.toString()+": read "+String.valueOf(d)+" nodes so far...\n");
                    writer.flush();
                }
            }

            writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Finished warming up "+nodeLabel.toString()+" index.\n");
            writer.flush();

            tx.success();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
项目:WhiteLab2.0-Neo4J-Plugin    文件:CypherExecutor.java   
public Long getTotalTokenCount() {
    Long frequency = (long) 0;

    try ( Transaction ignored = database.beginTx(); ) {
        ResourceIterator<Node> it = database.findNodes(NodeLabel.NodeCounter);
        Node nodeCounter = it.next();
        Object count = nodeCounter.getProperty("word_token_count");
        if (count instanceof Integer)
            frequency = frequency + new Long((Integer) count);
        else if (count instanceof Long)
            frequency = frequency + (Long) count;
    }

    return frequency;
}
项目:federator    文件:Neo4J.java   
@Override
public List<Hit> query(Entity entity, Set<Value> values) throws Exception {

    List<Hit> hits = new ArrayList<Hit>();

    try (Transaction tx = graphDb.beginTx()) {

        for (Value queryValue : values) {

            ResourceIterator<Node> nodes = graphDb.findNodes(DynamicLabel.label(entity.getName()),
                    queryValue.getField().getFieldName(), queryValue.getValue());

            while (nodes.hasNext()) {

                Node node = nodes.next();

                List<Value> tempValues = new ArrayList<Value>();

                for (String property : node.getAllProperties().keySet()) {
                    Value value = new Value(entity.getName(), property,
                            node.getAllProperties().get(property).toString(), new Type(DataType.STRING.toString()));
                    tempValues.add(value);
                }

                Hit hit = new Hit();
                hit.setEntity(entity);
                hit.setValues(tempValues);

                hits.add(hit);
            }
        }
    }

    return hits;
}
项目:dnainator    文件:Neo4jQuery.java   
/**
 * Execute the query on the given database.
 * @param db the database to execute the query on.
 * @return the query result.
 */
public List<EnrichedSequenceNode> execute(GraphDatabaseService db) {
    sb.append("RETURN n");
    List<EnrichedSequenceNode> result;
    try (Transaction tx = db.beginTx()) {
        Result r = db.execute(sb.toString(), parameters);
        ResourceIterator<Node> it = r.columnAs("n");
        result = IteratorUtil.asCollection(it).stream()
            .map(e -> new Neo4jSequenceNode(db, e))
            .filter(p)
            .collect(Collectors.toList());
        tx.success();
    }
    return result;
}
项目:dnainator    文件:Neo4jGraph.java   
/**
 * Retrieves a resource iterator over all roots.
 * The roots are all the nodes with no incoming edges.
 * @return  a resource iterator
 */
protected ResourceIterator<Node> rootIterator() {
    ResourceIterator<Node> roots;
    Result res = service.execute(GET_ROOT);
    roots = res.columnAs("s");
    return roots;
}
项目:dnainator    文件:Neo4jGraph.java   
@Override
public List<EnrichedSequenceNode> getRank(int rank) {
    return query(e -> {
        ResourceIterator<Node> res = e.findNodes(NodeLabels.NODE,
                SequenceProperties.RANK.name(), rank);
        List<EnrichedSequenceNode> nodes = new LinkedList<>();
        res.forEachRemaining(n -> nodes.add(createSequenceNode(n)));

        return nodes;
    });
}
项目:dnainator    文件:Neo4jGraph.java   
@Override
public TreeNode getTree() {
    return query(e -> {
        ResourceIterator<Node> dbroots = e.execute(GET_PHYLO_ROOT).columnAs("n");
        Node dbroot = dbroots.next();

        return getTree(dbroot, new TreeNode(null));
    });
}
项目:neo4j-lucene5-index    文件:LuceneIndexIT.java   
@Test
public void shouldProvideStoreSnapshot() throws Exception
{
    // Given
    updateAndCommit( asList(
            add( nodeId, value ),
            add( nodeId2, value ) ) );
    accessor.force();

    // When & Then
    try ( ResourceIterator<File> snapshot = accessor.snapshotFiles() )
    {
        assertThat( asUniqueSetOfNames( snapshot ), equalTo( asSet( "_0.cfe", "_0.cfs", "_0.si", "segments_1" ) ) );
    }
}
项目:neo4j-lucene5-index    文件:LuceneIndexIT.java   
@Test
public void shouldProvideStoreSnapshotWhenThereAreNoCommits() throws Exception
{
    // Given
    // A completely un-used index

    // When & Then
    try(ResourceIterator<File> snapshot = accessor.snapshotFiles())
    {
        assertThat( asUniqueSetOfNames( snapshot ), equalTo( emptySetOf( String.class ) ) );
    }
}
项目:neo4j-lucene5-index    文件:LuceneIndexIT.java   
private Set<String> asUniqueSetOfNames( ResourceIterator<File> files )
{
    ArrayList<String> out = new ArrayList<>();
    while(files.hasNext())
        out.add( files.next().getName() );
    return asUniqueSet( out );
}
项目:aomrolemapper    文件:Neo4jAOM.java   
private Node findEntityByIDAndEntityType(Object id, IEntityType entityType) throws EsfingeAOMException {
    ResourceIterator<Node> findNodes = graphdb.findNodes(Label.label(entityType.getName()));
    for (Node entityTypeGraphNode : findNodes.stream().collect(Collectors.toList())) {
        Iterable<Relationship> typeObjectsRelationships = entityTypeGraphNode.getRelationships(RELATIONSHIP_ENTITY_TYPE_OBJECT);
        for (Relationship relationship : Iterables.asList(typeObjectsRelationships)) {
            Node entityGraphNode = relationship.getEndNode();
            if(entityGraphNode.getProperty(ID_FIELD_NAME).equals(id)){
                return entityGraphNode;
            }
        }
    }
    return null;
}
项目:aomrolemapper    文件:Neo4jAOM.java   
@Override
public List<String> getAllEntityTypeIds() throws EsfingeAOMException {
    List<String> entityTypeIds = new ArrayList<String>();

    Transaction t = beginTx();
    try {
        ResourceIterator<Node> entityTypeNodes = graphdb.findNodes(LABEL_ENTITY_TYPE_CLASS);
        entityTypeNodes.stream().forEach(
            (node) -> 
                entityTypeIds.add((String) node.getProperty(ID_FIELD_NAME))
            );

        successTx(t);
        return entityTypeIds;
    } catch (Exception e) {
        failureTx(t);
        throw new EsfingeAOMException(e);
    }
}
项目:aomrolemapper    文件:Neo4jAOM.java   
@Override
public List<Object> getAllEntityIDsForType(IEntityType entityType) throws EsfingeAOMException {

    Transaction t = beginTx();

    try {

        List<Object> entityIDs = new ArrayList<Object>();
        ResourceIterator<Node> findNodes = graphdb.findNodes(Label.label(entityType.getName()));
        findNodes.forEachRemaining(
            (entityTypeGraphNode) -> {
                Iterable<Relationship> typeObjectsRelationships = entityTypeGraphNode.getRelationships(RELATIONSHIP_ENTITY_TYPE_OBJECT);
                typeObjectsRelationships.forEach(
                    (relationship) -> {
                        Node entityGraphNode = relationship.getEndNode();
                        Object entityTypeID = entityGraphNode.getProperty(ID_FIELD_NAME);
                        entityIDs.add(entityTypeID);
                    }
                );
            }
        );

        successTx(t);
        return entityIDs;
    } catch (Exception e) {
        failureTx(t);
        throw new EsfingeAOMException(e);
    }
}
项目:SciGraph    文件:ReachabilityIndex.java   
/***
 * Manage a reachability index object on a graph
 * 
 * @param graphDb
 *          The graph on which to build the reachability index
 */
@Inject
public ReachabilityIndex(GraphDatabaseService graphDb) {
  this.graphDb = graphDb;
  try (Transaction tx = graphDb.beginTx()) {
    ResourceIterator<Node> nodes = graphDb.findNodes(REACHABILITY_METADATA);
    metaDataNode = getOnlyElement(nodes, graphDb.createNode(REACHABILITY_METADATA));
    tx.success();
  }
}
项目:SciGraph    文件:EdgeLabelerTest.java   
@Test
public void canBeTransformedToTinkerGraph() {
  TinkerGraphUtil tgu = new TinkerGraphUtil(curieUtil);
  ResourceIterator<Node> nodes = graphDb.getAllNodes().iterator();
  while (nodes.hasNext()) {
    tgu.addElement(nodes.next());
  }
  ResourceIterator<Relationship> relationships = graphDb.getAllRelationships().iterator();
  while (relationships.hasNext()) {
    tgu.addElement(relationships.next());
  }
}
项目:SciGraph    文件:CliqueTest.java   
@Test
public void edgesAreMovedToLeader() {
  ResourceIterator<Node> allNodes = graphDb.getAllNodes().iterator();
  Node n1 = getNode("http://x.org/a", allNodes);
  Node n2 = getNode("http://x.org/b", allNodes);
  Node n3 = getNode("http://x.org/c", allNodes);
  Node n4 = getNode("http://x.org/d", allNodes);
  Node n5 = getNode("http://x.org/e", allNodes);
  assertThat(n1.getDegree(RelationshipType.withName("hasPhenotype")), is(0));
  assertThat(n2.getDegree(RelationshipType.withName("hasPhenotype")), is(1));
  assertThat(n3.getDegree(RelationshipType.withName("hasPhenotype")), is(1));
  assertThat(n1.getDegree(IS_EQUIVALENT), is(1));
  assertThat(n2.getDegree(IS_EQUIVALENT), is(2));
  assertThat(n3.getDegree(IS_EQUIVALENT), is(1));
  assertThat(n4.getDegree(), is(2));
  assertThat(n5.getDegree(), is(2));

  clique.run();

  assertThat(n1.getDegree(RelationshipType.withName("hasPhenotype")), is(2));
  assertThat(n2.getDegree(RelationshipType.withName("hasPhenotype")), is(0));
  assertThat(n3.getDegree(RelationshipType.withName("hasPhenotype")), is(0));
  assertThat(n1.getDegree(IS_EQUIVALENT), is(2));
  assertThat(n2.getDegree(IS_EQUIVALENT), is(1));
  assertThat(n3.getDegree(IS_EQUIVALENT), is(1));
  assertThat(n4.getDegree(), is(3));
  assertThat(n5.getDegree(), is(1));
  assertThat(n1.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(true));
  assertThat(n2.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false));
  assertThat(n3.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false));
  assertThat(n4.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(true));
  assertThat(n5.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false));
}
项目:WikiN-G-ER    文件:GraphTest.java   
public GraphTest() {
        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("./database/");
        Transaction tx = graphDb.beginTx();     
        Label label = DynamicLabel.label( "message" );

//      firstNode = graphDb.createNode();
//      firstNode.setProperty( "message", "Hello, " );
//      secondNode = graphDb.createNode();
//      secondNode.setProperty( "message", "World!" );
//
//      relationship = firstNode.createRelationshipTo( secondNode, RelTypes.KNOWS );
//      relationship.setProperty( "message", "brave Neo4j " );
//      
//      System.out.print( firstNode.getProperty( "message" ) );
//      System.out.print( relationship.getProperty( "message" ) );
//      System.out.print( secondNode.getProperty( "message" ) );
//              
//      firstNode.getSingleRelationship( RelTypes.KNOWS, Direction.OUTGOING ).delete();
//      firstNode.delete();
//      secondNode.delete();

        ResourceIterator<Node> users = graphDb
                .findNodesByLabelAndProperty( label, "message", "Hello, " )
                .iterator();

        Node firstUserNode;
        if ( users.hasNext() )
        {
            firstUserNode = users.next();
            System.out.println("test: " + firstUserNode.getProperty("message"));
        }
        users.close();

        tx.success();
        graphDb.shutdown();
    }
项目:csvtreeloader    文件:CSVTreeBuilder.java   
private RootTreeNodeBuilder(ColumnSpec columnSpec, RelationshipType child, GraphDatabaseService db, ExecutionEngine engine) {
    super(columnSpec, null, child);
    this.db = db;
    this.engine = engine;
    try (Transaction tx = db.beginTx()) {
        boolean indexExists = false;
        for (IndexDefinition index : db.schema().getIndexes(this.column.label)) {
            ArrayList<String> keys = new ArrayList<String>();
            for (String key : index.getPropertyKeys()) {
                keys.add(key);
            }
            if (keys.size() != 1 || !keys.get(0).equals(this.column.property)) {
                throw new RuntimeException("Schema Index for " + this.column.label + "." + this.column.property
                        + " cannot be made because different index for " + this.column.label + "." + keys
                        + " already exists");
            }
            indexExists = true;
        }
        if (!indexExists) {
            db.schema().constraintFor(this.column.label).assertPropertyIsUnique(this.column.property).create();
        }
        tx.success();
    }
    queryString = "MERGE (n:" + column.label + " {" + column.property + ": {" + column.property + "}}) RETURN n";
    try (Transaction tx = db.beginTx()) {
        ResourceIterator<Object> resultIterator = engine.execute("MATCH (n:" + column.label + ") RETURN n").columnAs(
                "n");
        while (resultIterator.hasNext()) {
            Node node = (Node) resultIterator.next();
            cachedRoots.put(node.getProperty(column.property).toString(), node);
        }
        tx.success();
        debug("Cached " + cachedRoots.size() + " existing tree roots with Label '" + this.column.label + "'");
    }
}
项目:checklistbank    文件:ImportDb.java   
private List<Node> filterByRank(ResourceIterator<Node> nodes, Rank rank) {
  List<Node> matchingRanks = Lists.newArrayList();
  while (nodes.hasNext()) {
    Node n = nodes.next();
    if (rank == null || n.getProperty(NeoProperties.RANK, rank.ordinal()).equals(rank.ordinal())) {
      matchingRanks.add(n);
    }
  }
  return matchingRanks;
}
项目:checklistbank    文件:MultiRootPathIterator.java   
public static ResourceIterable<Path> create(final List<Node> roots, final TraversalDescription td) {
  return new ResourceIterable<Path>() {
    @Override
    public ResourceIterator<Path> iterator() {
      return new MultiRootPathIterator(roots, td);
    }
  };
}
项目:checklistbank    文件:MultiRootNodeIterator.java   
public static ResourceIterable<Node> create(final List<Node> roots, final TraversalDescription td) {
  return new ResourceIterable<Node>() {
    @Override
    public ResourceIterator<Node> iterator() {
      return new MultiRootNodeIterator(roots, td);
    }
  };
}
项目:checklistbank    文件:Traversals.java   
/**
 * Tries to find a parent node with the given rank
 * @param start node to start looking for parents, excluded from search
 * @return the parent node with requested rank or null
 */
public static Node findParentWithRank(Node start, Rank rank) {
  try(ResourceIterator<Node> parents = Traversals.PARENTS.traverse(start).nodes().iterator()) {
    while (parents.hasNext()) {
      Node p = parents.next();
      if ((int)p.getProperty(NeoProperties.RANK, -1) == rank.ordinal()) {
        return p;
      }
    }
  }
  return null;
}
项目:checklistbank    文件:BaseTest.java   
private void show(ResourceIterator<Node> iter) {
  System.out.println("\n\n");

  while (iter.hasNext()) {
    Node n = iter.next();
    NameUsage u = getUsageByNode(n);
    System.out.println("### " + n.getId() + " " + u.getScientificName());
    System.out.println(u);
  }
  iter.close();
}
项目:SnowGraph    文件:CodeIndexes.java   
public CodeIndexes(GraphDatabaseService db) {
    try (Transaction tx = db.beginTx()) {
        ResourceIterator<Node> nodes = db.getAllNodes().iterator();
        Set<Node> codeNodes = new HashSet<>();
        while (nodes.hasNext()) {
            Node node = nodes.next();
            if (node.hasLabel(Label.label(JavaCodeExtractor.CLASS)) || node.hasLabel(Label.label(JavaCodeExtractor.INTERFACE)) || node.hasLabel(Label.label(JavaCodeExtractor.METHOD))) {
                codeNodes.add(node);
            }
        }

        for (Node codeNode : codeNodes) {
            String name = "";
            boolean type = true;
            if (codeNode.hasLabel(Label.label(JavaCodeExtractor.CLASS)))
                name = (String) codeNode.getProperty(JavaCodeExtractor.CLASS_FULLNAME);
            if (codeNode.hasLabel(Label.label(JavaCodeExtractor.INTERFACE)))
                name = (String) codeNode.getProperty(JavaCodeExtractor.INTERFACE_FULLNAME);
            if (codeNode.hasLabel(Label.label(JavaCodeExtractor.METHOD))) {
                name = codeNode.getProperty(JavaCodeExtractor.METHOD_BELONGTO) + "." + codeNode.getProperty(JavaCodeExtractor.METHOD_NAME);
                type = false;
            }
            if (name.contains("$"))
                continue;
            if (type) {
                typeMap.put(name, codeNode.getId());
                idToTypeNameMap.put(codeNode.getId(), name);
                String shortName = name;
                int p = shortName.lastIndexOf('.');
                if (p > 0)
                    shortName = shortName.substring(p + 1, shortName.length());
                if (!typeShortNameMap.containsKey(shortName))
                    typeShortNameMap.put(shortName, new HashSet<>());
                typeShortNameMap.get(shortName).add(codeNode.getId());
            } else {
                if (!methodMap.containsKey(name))
                    methodMap.put(name, new HashSet<>());
                methodMap.get(name).add(codeNode.getId());
                idToMethodNameMap.put(codeNode.getId(), name);
                int p1 = name.lastIndexOf('.');
                int p2 = name.lastIndexOf('.', p1 - 1);
                String midName, shortName;
                if (p2 > 0) {
                    midName = name.substring(p2 + 1);
                    shortName = name.substring(p1 + 1);
                } else {
                    midName = name;
                    shortName = name.substring(p1 + 1);
                }
                if (!methodMidNameMap.containsKey(midName))
                    methodMidNameMap.put(midName, new HashSet<>());
                methodMidNameMap.get(midName).add(codeNode.getId());
                if (!methodShortNameMap.containsKey(shortName))
                    methodShortNameMap.put(shortName, new HashSet<>());
                methodShortNameMap.get(shortName).add(codeNode.getId());
            }
        }

        tx.success();
    }
}
项目:WhiteLab2.0-Neo4J-Plugin    文件:DatabaseAdministration.java   
@POST
@Path( "/warmup" )
public Response warmup() {
    final long start = System.currentTimeMillis();

    StreamingOutput stream = new StreamingOutput() {
        @Override
        public void write(OutputStream os) throws IOException, WebApplicationException {
            final Writer writer = new BufferedWriter(new OutputStreamWriter(os));
            System.out.println(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Warming up database...");
            writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Warming up database...\n");
            writer.flush();

            try (Transaction tx = database.beginTx()) {
                ResourceIterator<Node> corpIt = database.findNodes(NodeLabel.Corpus);

                while (corpIt.hasNext()) {
                    Node corpus = corpIt.next();
                    List<Thread> threads = new ArrayList<Thread>();

                    for (Relationship hasCollection : corpus.getRelationships(LinkLabel.HAS_COLLECTION, Direction.OUTGOING)) {
                        Node collection = hasCollection.getOtherNode(corpus);
                        Thread colWarmupThread = new Thread(new NodeWarmUp(database, writer, collection, start));
                        colWarmupThread.start();
                        threads.add(colWarmupThread);
                        if (threads.size() == 16)
                            threads = finishThreads(threads);
                    }

                    finishThreads(threads);
                }

                tx.success();
            }

            System.out.println(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Completed database warmup.");
            writer.write(HumanReadableFormatter.humanReadableTimeElapsed(System.currentTimeMillis() - start)+" - Completed database warmup.\n");
            writer.flush();
        }
    };
    return Response.ok().entity( stream ).type( MediaType.TEXT_PLAIN ).build();
}
项目:dnainator    文件:Neo4jGraph.java   
private ResourceIterator<Node> getAnnotationRange(Range r, String query) {
    Map<String, Object> parameters = new HashMap<>(2);
    parameters.put("from", r.getX());
    parameters.put("to", r.getY());
    return query(service -> service.execute(query, parameters).columnAs("a"));
}
项目:neo4j-lucene5-index    文件:LuceneBatchInserterIndex.java   
private IndexHits<Long> wrapIndexHits( final LegacyIndexHits ids )
{
    return new IndexHits<Long>()
    {
        @Override
        public boolean hasNext()
        {
            return ids.hasNext();
        }

        @Override
        public Long next()
        {
            return ids.next();
        }

        @Override
        public void remove()
        {
            throw new UnsupportedOperationException();
        }

        @Override
        public ResourceIterator<Long> iterator()
        {
            return this;
        }

        @Override
        public int size()
        {
            return ids.size();
        }

        @Override
        public void close()
        {
            ids.close();
        }

        @Override
        public Long getSingle()
        {
            try
            {
                long singleId = PrimitiveLongCollections.single( ids, -1L );
                return singleId == -1 ? null : singleId;
            }
            finally
            {
                close();
            }
        }

        @Override
        public float currentScore()
        {
            return 0;
        }
    };
}