Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.springframework.data.neo4j.support;
import static org.neo4j.helpers.collection.MapUtil.map;

Author(s):
mh
Since:
04.01.14
public class ReferenceNodes {
    public static final String ROOT_NAME = "root";
    private static ExecutionEngine engine;
    private static GraphDatabaseService dbRef;
    public static Node getReferenceNode(GraphDatabaseService db) {
        return getReferenceNode(db);
    }
    public static Node getReferenceNode(GraphDatabase db) {
        return getReferenceNode(db);
    }
    public static Node obtainReferenceNode(GraphDatabaseService db) {
        return obtainReferenceNode(db);
    }
    public static Node obtainReferenceNode(GraphDatabase db) {
        return obtainReferenceNode(db);
    }
    public static Node obtainReferenceNode(GraphDatabaseService dbString name) {
        return executeQuery(dbname"MERGE (ref:ReferenceNode {name:{name}}) RETURN ref");
    }
    private static Node executeQuery(GraphDatabaseService dbString nameString query) {
        if ( == null || db != ) {
             = new ExecutionEngine(db);
             = db;
        }
        ExecutionResult result = .execute(querymap("name"name));
        return IteratorUtil.single(result.<Node>columnAs("ref"));
    }
    public static Node getReferenceNode(GraphDatabaseService dbString name) {
        return executeQuery(dbname"MATCH (ref:ReferenceNode {name:{name}}) RETURN ref");
    }
    public static Node obtainReferenceNode(GraphDatabase dbString name) {
        return executeQuery(dbname"MERGE (ref:ReferenceNode {name:{name}}) RETURN ref");
    }
    private static Node executeQuery(GraphDatabase dbString nameString query) {
        CypherQueryEngine engine = db.queryEngine();
        return engine.query(query,map("name"name)).to(Node.class).singleOrNull();
    }
    public static Node getReferenceNode(GraphDatabase dbString name) {
        return executeQuery(dbname"MATCH (ref:ReferenceNode {name:{name}}) RETURN ref");
    }
New to GrepCode? Check out our FAQ X