Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Transaction


        {
            throw new IllegalArgumentException( "Graph Database must be provided when creating new SortedTree" );
        }
        this.baseNode = graphDb.createNode();

        Transaction tx = graphDb.beginTx();
        try
        {
            Node rootNode = graphDb.createNode();
            Relationship treeRootRelationship = baseNode.createRelationshipTo( rootNode, RelTypes.TREE_ROOT );
            this.treeRoot = new TreeNode( this, rootNode );
            baseNode.setProperty( NodeCollection.GRAPH_COLLECTION_CLASS, SortedTree.class.getName() );

            treeRootRelationship.setPropertyTREE_NAME, treeName );
            treeRootRelationship.setProperty( IS_UNIQUE_INDEX, isUniqueIndex );
            treeRootRelationship.setProperty( COMPARATOR_CLASS, nodeComparator.getClass().getName());

            this.treeName = treeName;
        this.isUniqueIndex = isUniqueIndex;
            this.nodeComparator = nodeComparator;

            tx.success();
        }
        finally
        {
            tx.finish();
        }
  }
View Full Code Here


    // todo always create an transaction for persist, atomic operation when no outside tx exists
    @Override
    public ENTITY persist() {
        if (!isDetached()) return getEntity();
        Transaction tx = graphDatabaseContext.beginTx();
        try {
            ENTITY result = delegate.persist();

            flushDirty();
            tx.success();
            return result;
        } finally {
            tx.finish();
        }
    }
View Full Code Here

    public void gettingTypeFromNullShouldFail() throws Exception {
        nodeTypeRepresentationStrategy.getJavaType(null);
    }

    private void createThing() {
        Transaction tx = graphDatabaseContext.beginTx();
        try {
            thingNode = graphDatabaseContext.createNode();
            thing = new Thing(thingNode);
            nodeTypeRepresentationStrategy.postEntityCreation(thingNode, Thing.class);
            thing.setName("thing");
            subThingNode = graphDatabaseContext.createNode();
            subThing = new SubThing(subThingNode);
            nodeTypeRepresentationStrategy.postEntityCreation(subThingNode, SubThing.class);
            subThing.setName("subThing");
            tx.success();
        } finally {
            tx.finish();
        }
    }
View Full Code Here

            throw error;
        }
    }

    private void checkNeo4jTransactionManager() {
        Transaction tx = null;
        try {
            tx = graphDatabaseContext.beginTx();
            updateStartTime();
            tx.success();
        } catch (Exception e) {
            AssertionError error = new AssertionError("transactionManager not correctly configured, please refer to the manual, setup section");
            error.initCause(e);
            throw error;
        } finally {
            try {
            if (tx != null) tx.finish();
            } catch(Exception e) {
                // ignore
            }
        }
    }
View Full Code Here

        assertEquals("developers", group.getPersistentState().getProperty("name"));
    }
    // own transaction handling because of http://wiki.neo4j.org/content/Delete_Semantics
    @Test(expected = NotFoundException.class)
    public void testDeleteEntityFromGDC() {
        Transaction tx = graphDatabaseContext.beginTx();
        Person p = persistedPerson("Michael", 35);
        Person spouse = persistedPerson("Tina", 36);
        p.setSpouse(spouse);
        long id = spouse.getId();
        graphDatabaseContext.removeNodeEntity(spouse);
        tx.success();
        tx.finish();
        Assert.assertNull("spouse removed " + p.getSpouse(), p.getSpouse());
        Person spouseFromIndex = personRepository.findByPropertyValue(Person.NAME_INDEX, "name", "Tina");
        Assert.assertNull("spouse not found in index",spouseFromIndex);
        Assert.assertNull("node deleted " + id, graphDatabaseContext.getNodeById(id));
    }
View Full Code Here

        Assert.assertNull("node deleted " + id, graphDatabaseContext.getNodeById(id));
    }

    @Test(expected = NotFoundException.class)
    public void testDeleteEntity() {
        Transaction tx = graphDatabaseContext.beginTx();
        Person p = persistedPerson("Michael", 35);
        Person spouse = persistedPerson("Tina", 36);
        p.setSpouse(spouse);
        long id = spouse.getId();
        spouse.remove();
        tx.success();
        tx.finish();
        Assert.assertNull("spouse removed " + p.getSpouse(), p.getSpouse());
        Person spouseFromIndex = personRepository.findByPropertyValue(Person.NAME_INDEX, "name", "Tina");
        Assert.assertNull("spouse not found in index", spouseFromIndex);
        Assert.assertNull("node deleted " + id, graphDatabaseContext.getNodeById(id));
    }
View Full Code Here

  private static Relationship rel(Link link) {
    return link.getPersistentState();
  }

  private Thing createThing() {
    Transaction tx = graphDatabaseContext.beginTx();
    try {
      Node node = graphDatabaseContext.createNode();
      thing = new Thing(node);
      noopNodeStrategy.postEntityCreation(node, Thing.class);
            Relationship rel = node.createRelationshipTo(graphDatabaseContext.createNode(), DynamicRelationshipType.withName("link"));
            link = new Link(rel);
            noopRelationshipStrategy.postEntityCreation(rel, Link.class);
      tx.success();
      return thing;
    } finally {
      tx.finish();
    }
  }
View Full Code Here

        createThingsAndLinks();
    Index<Node> typesIndex = graphDatabaseService.index().forNodes(IndexingNodeTypeRepresentationStrategy.INDEX_NAME);
    IndexHits<Node> thingHits;
    IndexHits<Node> subThingHits;

        Transaction tx = graphDatabaseService.beginTx();
        try
        {
            nodeTypeRepresentationStrategy.preEntityRemoval(node(thing));
            tx.success();
        }
        finally
        {
            tx.finish();
        }

    thingHits = typesIndex.get(IndexingNodeTypeRepresentationStrategy.INDEX_KEY, thing.getClass().getName());
    assertEquals(node(subThing), thingHits.getSingle());
    subThingHits = typesIndex.get(IndexingNodeTypeRepresentationStrategy.INDEX_KEY, subThing.getClass().getName());
    assertEquals(node(subThing), subThingHits.getSingle());

        tx = graphDatabaseService.beginTx();
        try {
            nodeTypeRepresentationStrategy.preEntityRemoval(node(subThing));
            tx.success();
        }
        finally
        {
            tx.finish();
        }

    thingHits = typesIndex.get(IndexingNodeTypeRepresentationStrategy.INDEX_KEY, thing.getClass().getName());
        assertNull(thingHits.getSingle());
    subThingHits = typesIndex.get(IndexingNodeTypeRepresentationStrategy.INDEX_KEY, subThing.getClass().getName());
View Full Code Here

  private static Node node(Thing thing) {
    return thing.getPersistentState();
  }

  private Thing createThingsAndLinks() {
    Transaction tx = graphDatabaseService.beginTx();
    try {
            Node n1 = graphDatabaseService.createNode();
            thing = new Thing(n1);
      nodeTypeRepresentationStrategy.postEntityCreation(n1, Thing.class);
            thing.setName("thing");
            Node n2 = graphDatabaseService.createNode();
            subThing = new SubThing(n2);
      nodeTypeRepresentationStrategy.postEntityCreation(n2, SubThing.class);
            subThing.setName("subThing");
      tx.success();
      return thing;
    } finally {
      tx.finish();
    }
  }
View Full Code Here

  private static Set<Node> set(Node... nodes) {
    return new HashSet<Node>(Arrays.asList(nodes));
  }

  private void manualCleanDb() {
    Transaction tx = graphDatabaseService.beginTx();
    try {
      cleanDb();
      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.