Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Transaction


        this.graph = graph;
    }

    public Map<String, Object> cleanDb() {
        Map<String, Object> result = new HashMap<String, Object>();
        Transaction tx = graph.beginTx();
        try {
            removeNodes(result);
            clearIndex(result);
            tx.success();
        } finally {
            tx.finish();
        }
        return result;
    }
View Full Code Here


            relList = nodeList;
            relationshipCache.put(start, relList);
        }

        if (!relList.contains(end)) {
            Transaction tx = db.beginTx();
            try {
                Node endNode = db.getNodeById(end);
                startNode.createRelationshipTo(endNode, withName(relationshipType));
                tx.success();
            } catch (final Exception e) {
                tx.failure();
            } finally {
                tx.close();
                relList.add(end);
                relationshipCache.put(start, relList);
            }
        }
    }
View Full Code Here

            labeledText.setFocus(1);
        }

        // Add first matcher
        for (int i = 0; i < labeledText.getFocus(); i++) {
            Transaction tx = db.beginTx();
            getRootPatternNode(db);
            LearningManager.trainInput(Arrays.asList(labeledText.getText()), Arrays.asList(labeledText.getLabel()), GRAPH_MANAGER, db);
            tx.success();
            tx.close();
        }

        return Response.ok()
                .entity("{\"success\":\"true\"}")
                .type(MediaType.APPLICATION_JSON)
View Full Code Here

        if (node != null) {
            node.put(key, value);
        }

        // TODO: Remove this in favor of a distributed messaging bus architecture
        Transaction tx = graphDb.beginTx();
        graphDb.getNodeById(id).setProperty(key, value);
        tx.success();
        tx.close();

        return success;
    }
View Full Code Here

                .collect(Collectors.toList()));

        // Iterate through the inputs
        for (String input: inputs)
        {
            Transaction tx = db.beginTx();
            // Get data node
            Long dataNodeId = nodeManager.getOrCreateNode(dataNodeManager, input, db).getId();
            nodeManager.setNodeProperty(dataNodeId, "label", labels.toArray(new String[labels.size()]), db);

            Map<Long, Integer> patternMatchers = PatternMatcher.match(GraphManager.ROOT_TEMPLATE, input, db, graphManager);

            tx.success();
            tx.close();

            tx = db.beginTx();

            for (Long nodeId : patternMatchers.keySet()) {
                // Get property
                Integer matchCount = (Integer) nodeManager.getNodeProperty(nodeId, "matches", db);

                if (matchCount == null) {
                    matchCount = 0;
                    nodeManager.setNodeProperty(nodeId, "matches", matchCount, db);
                }


                // Set property
                nodeManager.setNodeProperty(nodeId, "matches", matchCount + patternMatchers.get(nodeId), db);

                // Get or create data relationship
                dataRelationshipManager.getOrCreateNode(nodeId, dataNodeId, db);

                for (Long labelId : labelNodeIds) {
                    // Get or create class relationship
                    classRelationshipCache.getOrCreateRelationship(nodeId, labelId, db, graphManager);
                }

                // Check if the match count has exceeded the threshold
                matchCount = (Integer) nodeManager.getNodeProperty(nodeId, "matches", db);
                Integer threshold = (Integer) nodeManager.getNodeProperty(nodeId, "threshold", db);


                if (matchCount > threshold) {
                    // Set match count to 0
                    nodeManager.setNodeProperty(nodeId, "matches", 0, db);

                    // Increase threshold
                    nodeManager.setNodeProperty(nodeId, "threshold", (threshold / GraphManager.MIN_THRESHOLD) + (threshold), db);

                    // Populate a map of matched patterns
                    Map<Integer, Map<String, PatternCount>> matchDictionary = new HashMap<>();
                    populatePatternMap(db, nodeId, matchDictionary);

                    // Generate nodes for every wildcard
                    generateChildPatterns(db, nodeManager.getNodeAsMap(nodeId, db), matchDictionary, graphManager);
                }

            }

            tx.success();
            tx.close();
        }
    }
View Full Code Here

        Assert.assertNotNull(f);
        Assert.assertNotNull(g);

        String expected = "a";

        Transaction tx = db.beginTx();
        String actual = (String)a.getProperty("value");
        tx.success();
        Assert.assertEquals(expected, actual);
    }
View Full Code Here

        NodeManager.globalNodeCache.invalidateAll();
        DataNodeManager.dataCache.invalidateAll();
        DataNodeManager dataNodeManager = new DataNodeManager();

        // Write some nodes to the database
        Transaction tx1 = db.beginTx();
        Node a = nodeManager.getOrCreateNode(dataNodeManager, "a", db);
        tx1.success();
        Assert.assertNotNull(a);

        String expected = "success";
        nodeManager.setNodeProperty(a.getId(), "test", expected, db);
        Transaction tx = db.beginTx();
        String actual = (String)NodeManager.getNodeFromGlobalCache(a.getId()).get("test");
        tx.success();

        Assert.assertEquals(expected, actual);
    }
View Full Code Here

            }
        }
    }

    private static void trainOnText(String[] text, String[] label, GraphDatabaseService db, GraphManager graphManager) {
        Transaction tx = db.beginTx();
        getRootPatternNode(db, graphManager);
        LearningManager.trainInput(Arrays.asList(text), Arrays.asList(label), graphManager, db);
        tx.success();
        tx.close();
    }
View Full Code Here

    addUniqueConstraints( identifierGenerators );
    addSequences( identifierGenerators );
  }

  private void addUniqueConstraints(Set<PersistentNoSqlIdentifierGenerator> identifierGenerators) {
    Transaction tx = null;
    try {
      tx = neo4jDb.beginTx();
      for ( IdentifierGenerator identifierGenerator : identifierGenerators ) {
        addUniqueConstraint( identifierGenerator );
      }
      tx.success();
    }
    finally {
      tx.close();
    }
  }
View Full Code Here

    }
    return true;
  }

  private void addSequences(Set<PersistentNoSqlIdentifierGenerator> identifierGenerators) {
    Transaction tx = null;
    try {
      tx = neo4jDb.beginTx();
      for ( IdentifierGenerator generator : identifierGenerators ) {
        addSequence( generator );
      }
      tx.success();
    }
    finally {
      tx.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.