Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Transaction


   * @param idSourceKey identifies the generator
   * @param increment the difference between to consecutive values in the sequence
   * @return the next value in a sequence
   */
  public int nextValue(IdSourceKey idSourceKey, int increment) {
    Transaction tx = neo4jDb.beginTx();
    Lock lock = null;
    try {
      Node sequence = getSequence( idSourceKey );
      lock = tx.acquireWriteLock( sequence );
      int nextValue = updateSequenceValue( idSourceKey, sequence, increment );
      tx.success();
      lock.release();
      return nextValue;
    }
    finally {
      tx.close();
    }
  }
View Full Code Here


    public GraphDatabaseService getDatabase() {
        return db;
    }

    public void transaction(Trx trx) {
        Transaction trans = db.beginTx();
        try {
            trx.execute(db);
            trans.success();
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            log.error("Transaction failed", e);
            throw new RuntimeException(e);
        } finally {
            trans.finish();
        }

    }
View Full Code Here

    protected <T> Set<T> set(T... values) {
        return new HashSet<T>(Arrays.<T>asList(values));
    }

    protected void manualCleanDb() {
    Transaction tx = graphDatabaseService.beginTx();
    try {
      cleanDb();
      tx.success();
    } finally {
      tx.close();
    }
  }
View Full Code Here

    @Test public void testUserAddRemove() {
        service.setPermissionForUser("user1", RO);

        NodeManager nodeManager = graphDatabase.getDependencyResolver().resolveDependency(NodeManager.class);
        PropertyContainer properties = nodeManager.getGraphProperties();
        Transaction transaction = graphDatabase.beginTx();
        properties.setProperty("any other property", "should be ignored");
        transaction.success();
        transaction.finish();

        assertEquals(genericMap("user1", RO), service.getUsers());

        service.setPermissionForUser("user2", RW);
        assertEquals(genericMap("user1", RO, "user2", RW), service.getUsers());
View Full Code Here

        return isVerb(method, "PUT", "POST", "DELETE") && rights.contains("W") ||
                isVerb(method, "GET") && rights.contains("R");
    }

    private String getCredentials(String cred) {
        Transaction tx = graph.beginTx();
        try {
            PropertyContainer properties = getGraphProperties();
            String userKey = getUserKey(cred);
            Object result = properties.getProperty(userKey, "");
            String credentials = (result instanceof Boolean) ? "" : (String) result;
            tx.success();
            return credentials;
        } finally {
            tx.finish();
        }
    }
View Full Code Here

        }
        return false;
    }

    public void setPermissionForUser(String user, Permission permission) {
        Transaction transaction = graph.beginTx();
        try {
            PropertyContainer properties = getGraphProperties();
            String key = getUserKey(user);
            if (permission == Permission.NONE) {
                properties.removeProperty(key);
            } else {
                properties.setProperty(key, permission.name());
            }
            transaction.success();
        } catch (Exception e) {
            transaction.failure();
        } finally {
            transaction.finish();
        }
    }
View Full Code Here

    }
  }
  public void putPageRankToLucence(){
    Index<Node> ix = graphDB.index().forNodes("pageRank");
   
    Transaction tx = graphDB.beginTx();
    try {
      int cnt = 0;
      for (Node n:graphDB.getAllNodes()){
        if (n.hasProperty("pageRankValue")){
          if (n.hasProperty("title")){
            //String tmp = (String)n.getProperty("title");
            Double pr = - (Double)n.getProperty("pageRankValue");
            ix.add(n, "pr", pr);
          }
          if (n.hasProperty("name")){
            //String tmp = (String)n.getProperty("name");
            Double pr = - (Double)n.getProperty("pageRankValue");
            ix.add(n, "pr", pr);
          }
        }
        if (cnt++%10000==0){
          System.out.println(cnt);
          tx.success();
          tx.finish();
          tx = graphDB.beginTx();
        }
      }
      tx.success();
    }catch (Exception e){
      e.printStackTrace();
    }finally{
      tx.finish();
    }
  }
View Full Code Here

  }

  private void updatePageRankValues(HashMap<Long, Double> nodeIndex) {
    IOHelper.strongLog("start to hit the disk");
    int cnt = 0;
    Transaction tx = db.beginTx();
    try {
      for (Entry<Long, Double> e : nodeIndex.entrySet()) {
        cnt++;
        if (cnt > 50000){
          tx.success();
          tx.finish();
          cnt=0;
          tx = db.beginTx();
          IOHelper.log("updated another 50k nodes with PR properties");
        }
        Node n = db.getNodeById(e.getKey());
        n.setProperty("pageRankValue", e.getValue());
      }
      tx.success();
    } finally {
      tx.finish();
    }
  }
View Full Code Here

  private static EmbeddedGraphDatabase graphDB;
  private static Index<Node> index;
 
  public static void fillDummyValues(){
    System.out.println("Filling Dummy Nodes");
    Transaction tx = graphDB.beginTx();
   
    Node node1 = graphDB.createNode();
    Node node2 = graphDB.createNode();
    Node node3 = graphDB.createNode();
    Node node4 = graphDB.createNode();
   
    node1.setProperty("label", "my first, and node- stopword working practice Title!");
    node2.setProperty("label", "Secondos, and Nodos");
    node3.setProperty("label", "Tertios, Nodos");
    node4.setProperty("label", "Quartios- Nodos");

    index.add(node1 ,"score", new ValueContext( 1 ).indexNumeric());
    index.add(node2 ,"score", new ValueContext( 0 ).indexNumeric());
    index.add(node3 ,"score", new ValueContext( 2 ).indexNumeric());
    index.add(node4 ,"score", new ValueContext( 3 ).indexNumeric());

   
    index.add(node1, "label", node1.getProperty("label"));
    index.add(node2, "label", node2.getProperty("label"));
    index.add(node3, "label", node3.getProperty("label"));
    index.add(node4, "label", node4.getProperty("label"));
   
    // DynamicRelationshipType testType = DynamicRelationshipType.withName("test");
    // node1.createRelationshipTo(node2, testType);
   
    tx.success();
    tx.finish();
   
  }
View Full Code Here

    this.graphDB = graphDB;
  }

  //TODO: decide if tanimoto or absolute score should be used! I think absolutes are better
  public void calculateTopKCoAuthors(int transactionThreshhold, int k){
    Transaction tx = graphDB.beginTx();
    try {
      int transactionCount = 0;
      for (Node author:graphDB.getAllNodes()){
        if (!author.hasProperty("name"))continue;
        HashMap<Node, Integer> coAuthors = new HashMap<Node, Integer>();
        for (Relationship rel: author.getRelationships(DBRelationshipTypes.WRITTEN_BY)){
          Node paper = rel.getOtherNode(author);
          for (Relationship coAuthorRel: paper.getRelationships(DBRelationshipTypes.WRITTEN_BY)){
            Node coAuthor = coAuthorRel.getOtherNode(paper);
            if (coAuthor.getId()==author.getId())continue;
 
            if (coAuthors .containsKey(coAuthor))
              coAuthors.put(coAuthor, coAuthors.get(coAuthor) + 1);
            else
              coAuthors.put(coAuthor, 1);
 
          }
        }
       
        Algo<Node, Integer> a = new Algo<Node, Integer>();
       
        TreeMap<Integer, Set<Node>> topkCoAuthors = a.getTopkElements(coAuthors, k);       

        int topkCnt=0;
//        String log = "CoAuthors of " + author.getProperty("name");

        for (Integer coAuthorCount: topkCoAuthors.descendingKeySet()){
//          log = log + "\n" + coAuthorCount + "\t";
          for (Node coAuthor: topkCoAuthors.get(coAuthorCount)){
//            log = log + (String)coAuthor.getProperty("name") + "\t";
            Relationship coAuthorRel = author.createRelationshipTo(coAuthor, DBRelationshipTypes.CO_AUTHOR_COUNT);
            coAuthorRel.setProperty(DBRelationshipProperties.CO_AUTHOR_COUNT,coAuthorCount);
            if (++topkCnt>=k)break;
          }

          if (topkCnt>=k)break;         
       
        if (++transactionCount % transactionThreshhold == 0){
          tx.success();
          tx.finish();
          tx = graphDB.beginTx();
          IOHelper.log(transactionCount + " nodes have been attached with coAuthorshiprelations so far");     
        }
//        IOHelper.log(log);

//        System.out.println(" ");
      }
      tx.success();
    }finally{
      tx.finish();
    }
  }
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.