Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Transaction


            if (this.edgeIndexKeys.size() > 0)
                builder.setConfig(GraphDatabaseSettings.relationship_keys_indexable, edgeIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.relationship_auto_indexing, "true");

            rawGraphDB = builder.newGraphDatabase();

            Transaction tx = rawGraphDB.beginTx();
            try {
                GlobalGraphOperations graphOperations = GlobalGraphOperations.at(rawGraphDB);
                if (this.vertexIndexKeys.size() > 0)
                    populateKeyIndices(rawGraphDB, rawGraphDB.index().getNodeAutoIndexer(), graphOperations.getAllNodes(), Vertex.class);
                if (this.edgeIndexKeys.size() > 0)
                    populateKeyIndices(rawGraphDB, rawGraphDB.index().getRelationshipAutoIndexer(), graphOperations.getAllRelationships(), Edge.class);
                tx.success();
            } finally {
                tx.close();
            }
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        } finally {
            if (rawGraphDB != null) rawGraphDB.shutdown();
View Full Code Here


        if (!rawAutoIndexer.isEnabled())
            return;


        final Set<String> properties = rawAutoIndexer.getAutoIndexedProperties();
        Transaction tx = rawGraphDB.beginTx();

        final PropertyContainer kernel = ((GraphDatabaseAPI) rawGraphDB).getDependencyResolver().resolveDependency(NodeManager.class).getGraphProperties();
        kernel.setProperty(elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX, properties.toArray(new String[properties.size()]));

        int count = 0;
        for (final PropertyContainer pc : rawElements) {
            for (final String property : properties) {
                if (!pc.hasProperty(property)) continue;
                pc.setProperty(property, pc.getProperty(property));
                count++;
                if (count >= 10000) {
                    count = 0;
                    tx.success();
                    tx.finish();
                    tx = rawGraphDB.beginTx();
                }
            }
        }
        tx.success();
        tx.finish();
    }
View Full Code Here

                builder.setConfig(GraphDatabaseSettings.node_keys_indexable, vertexIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.node_auto_indexing, GraphDatabaseSetting.TRUE);
            if (this.edgeIndexKeys.size() > 0)
                builder.setConfig(GraphDatabaseSettings.relationship_keys_indexable, edgeIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.relationship_auto_indexing, GraphDatabaseSetting.TRUE);

            rawGraphDB = builder.newGraphDatabase();
            Transaction tx = rawGraphDB.beginTx();

            try {
                rawGraphDB.getReferenceNode().delete();
                tx.success();
            } catch (Exception e) {
                tx.failure();
            } finally {
                tx.finish();
            }

            GlobalGraphOperations graphOperations = GlobalGraphOperations.at(rawGraphDB);
            if (this.vertexIndexKeys.size() > 0)
                populateKeyIndices(rawGraphDB, rawGraphDB.index().getNodeAutoIndexer(), graphOperations.getAllNodes(), Vertex.class);
View Full Code Here

        if (!rawAutoIndexer.isEnabled())
            return;


        final Set<String> properties = rawAutoIndexer.getAutoIndexedProperties();
        Transaction tx = rawGraphDB.beginTx();

        final PropertyContainer kernel = ((GraphDatabaseAPI) rawGraphDB).getNodeManager().getGraphProperties();
        kernel.setProperty(elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX, properties.toArray(new String[properties.size()]));

        int count = 0;
        for (final PropertyContainer pc : rawElements) {
            for (final String property : properties) {
                if (!pc.hasProperty(property)) continue;
                pc.setProperty(property, pc.getProperty(property));
                count++;
                if (count >= 10000) {
                    count = 0;
                    tx.success();
                    tx.finish();
                    tx = rawGraphDB.beginTx();
                }
            }
        }
        tx.success();
        tx.finish();
    }
View Full Code Here

    public void testDatabase()
    {
        GraphDatabaseService database = module.findService( EmbeddedDatabaseService.class ).get().database();

        {
            Transaction tx = database.beginTx();

            try
            {
                Node rickard = database.createNode();
                rickard.setProperty( "name", "Rickard" );

                Node niclas = database.createNode();
                niclas.setProperty( "name", "Niclas" );

                rickard.createRelationshipTo( niclas, TestRelationships.KNOWS );

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

        List<List<Relationship>> roadPartsToMerge = wayMerger.merge(wayId, startNode);

        dumpPartsToLog(wayId, roadPartsToMerge);


        Transaction tx = graphDb.beginTx();

        optimize(wayId, roadPartsToMerge);

        tx.success();
        tx.finish();

    }
View Full Code Here

    }


    public void importXML(String xml) {

        Transaction tx = graphDb.beginTx();

        try {

            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
            xmlReader.setContentHandler(new MainOSMHandler(xmlReader, graphDb));
            xmlReader.parse(xml);

            // Hallelujah
            tx.success();

        } catch (SAXException e) {
            System.err.println(e);
            tx.failure();
        } catch (IOException e) {
            System.err.println(e);
            tx.failure();
        } finally {
            tx.finish();
        }
    }
View Full Code Here

        hits.close();
        return node;
   }
  
   private void makeRelationship(Node x, Node y, RelationshipType rt){
       Transaction tx = graphDb.beginTx();
       try{
           x.createRelationshipTo(y, rt);
           tx.success();    
       } catch (Exception ex){
           System.out.println(ex.getMessage());
       } finally {
           tx.finish();
      
   }
View Full Code Here

   
    private Node createUpdateIndexNode(String id, Map<String, Object> properties){      
        IndexHits<Node> hits = idIndex.get(ID_KEY, id);
        Node node = hits.getSingle();
        hits.close();          
        Transaction tx = graphDb.beginTx();
        try {
            if(node==null){
                node = graphDb.createNode();              
                node.setProperty(ID_KEY, id);          
                idIndex.add(node, ID_KEY, id);
            }          
            for(Entry<String, Object> entry: properties.entrySet()){
                String key = entry.getKey();
                Object value = entry.getValue();
                if(value!=JSONObject.NULL && key!=JSONObject.NULL) {
                    node.setProperty(key, value);
                }               
            }
            tx.success();      
        } catch (Exception ex){
            System.out.println("createUpdateIndexNode:" + ex.getMessage());           
        } finally {
            tx.finish();
        }
        return node;
    }
View Full Code Here

        return node;
    }
   
     private Node createNotIndexNode(){                  
        Node node = null;
        Transaction tx = graphDb.beginTx();
        try {           
            node = graphDb.createNode();                                           
            tx.success();      
        } catch (Exception ex){
            System.out.println("createNotIndexNode:" + ex.getMessage());           
        } finally {
            tx.finish();
        }
        return node;
    }
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.