Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Transaction


   * at runtime.
   *
   * @param identifierGenerators the generators to process
   */
  private void addSequences(Set<PersistentNoSqlIdentifierGenerator> identifierGenerators) {
    Transaction tx = null;
    try {
      tx = neo4jDb.beginTx();
      for ( PersistentNoSqlIdentifierGenerator generator : identifierGenerators ) {
        addSequence( generator );
      }
      tx.success();
    }
    finally {
      tx.close();
    }
  }
View Full Code Here


   * @param increment the difference between to consecutive values in the sequence
   * @param initialValue the initial value of the given generator
   * @return the next value in a sequence
   */
  public int nextValue(IdSourceKey idSourceKey, int increment, int initialValue) {
    Transaction tx = neo4jDb.beginTx();
    Lock lock = null;
    try {
      Node sequence = getSequence( idSourceKey );

      if ( sequence == null ) {
        // sequence nodes are expected to have been created up-front
        if ( idSourceKey.getMetadata().getType() == IdSourceType.SEQUENCE ) {
          throw new HibernateException( "Sequence missing: " + idSourceKey.getMetadata().getName() );
        }
        // table sequence nodes (think of them as rows in a generator table) are created upon first usage
        else {
          addTableSequence( idSourceKey.getMetadata(), (String) idSourceKey.getColumnValues()[0], initialValue );
          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

    addUniqueConstraints( identifierGenerators );
    addSequences( identifierGenerators );
  }

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

    if ( constraintMethod == UniqueConstraintSchemaUpdateStrategy.SKIP ) {
      log.tracef( "%1$s property set to %2$s: Skipping generation of unique constraints", Environment.UNIQUE_CONSTRAINT_SCHEMA_UPDATE_STRATEGY, UniqueConstraintSchemaUpdateStrategy.SKIP );
    }
    else {
      log.debug( "Creating missing constraints" );
      Transaction tx = null;
      try {
        tx = neo4jDb.beginTx();
        addUniqueConstraints( neo4jDb, configuration );
        tx.success();
      }
      finally {
        tx.close();
      }
    }
  }
View Full Code Here

        }
    }
    @Test
    public void testCreateWithVersion() throws Exception {
        final GraphInfo info = storage.create(new GraphInfo(Util.randomId(), "init", "query", "message","version"));
        Transaction tx = gdb.beginTx();
        final Node node = index.get("id", info.getId()).getSingle();
        assertNotNull(node);
        assertEquals(info.getId(), node.getProperty("id"));
        assertEquals(info.getVersion(),node.getProperty("version"));
        tx.success();tx.close();
    }
View Full Code Here

    }

    @Test
    public void testCreateWithNoRoot() throws Exception {
        final GraphInfo info = storage.create(new GraphInfo(Util.randomId(), "init", "query", "message","version",true));
        Transaction tx = gdb.beginTx();
        final Node node = index.get("id", info.getId()).getSingle();
        assertNotNull(node);
        assertEquals(info.getId(), node.getProperty("id"));
        assertEquals(info.getVersion(),node.getProperty("version"));
        assertEquals(!info.hasRoot(),(Boolean)node.getProperty("no_root"));
        tx.success();tx.close();
    }
View Full Code Here

    }

    @Test
    public void testCreateWithNullId() throws Exception {
        final GraphInfo info = storage.create(new GraphInfo(null, "init", "query", "message"));
        Transaction tx = gdb.beginTx();
        assertNotNull(info.getId());
        final Node node = index.get("id", info.getId()).getSingle();
        assertNotNull(node);
        assertEquals(info.getId(), node.getProperty("id"));
        tx.success();tx.close();
    }
View Full Code Here

    @Test
    public void testCreateWithEmptyId() throws Exception {
        final String id = " ";
        final GraphInfo info = storage.create(new GraphInfo(id, "init", "query", "message"));
        Transaction tx = gdb.beginTx();
        assertNotNull(info.getId());
        assertNotSame(id,info.getId());
        assertFalse(info.getId().trim().isEmpty());
        final Node node = index.get("id", info.getId()).getSingle();
        assertNull(index.get("id", id).getSingle());
        assertNotNull(node);
        assertEquals(info.getId(), node.getProperty("id"));
        tx.success();tx.close();
    }
View Full Code Here

    @Test
    public void testCreateWithIdWithSpace() throws Exception {
        final String id = "";
        final GraphInfo info = storage.create(new GraphInfo(id, "init", "query", "message"));
        Transaction tx = gdb.beginTx();
        assertNotNull(info.getId());
        assertNotSame(id,info.getId());
        assertFalse(info.getId().trim().isEmpty());
        final Node node = index.get("id", info.getId()).getSingle();
        assertNull(index.get("id", id).getSingle());
        assertNotNull(node);
        assertEquals(info.getId(), node.getProperty("id"));
        tx.success();tx.close();
    }
View Full Code Here

        assertEquals(info.getId(), node.getProperty("id"));
        tx.success();tx.close();
    }

    private void delete(Node node) {
        final Transaction tx = gdb.beginTx();
        node.delete();
        tx.success();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.