view app/models/TPGraph.java @ 13:9b677755cb93

create action Claim/createClaim
author one
date Tue, 02 Oct 2012 11:39:39 +0900 (2012-10-02)
parents d050b7fb4cda
children 7cdc9d19834f
line wrap: on
line source
package models;

import scala.reflect.generic.Trees.This;

import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.tg.TinkerGraph;

public class TPGraph {

	private static TPGraph instance = new TPGraph();
	private Object claimRootId;
	private Object userRootId;
	
	/*
	 *  Edge type
	 */
	protected final String CHILD = "child";
	
	
	private TPGraph() {
		
	}
	
	public static TPGraph getInstance() {
		return instance;
	}

	private Graph graph; 
	private String path = null;
	
	public void setPath(String path) {
		this.path = path;
	}

	public Graph newGraph() {
		if (path == null) {
			graph = new TinkerGraph();
		} else {
			graph = new TinkerGraph(path);
			
		}
		return graph;
	}

	public Graph getGraph() {
		return graph;
	}
	
	public void setClaimRootId(Object id) {
		this.claimRootId = id;
	}
	
	public void setUserRootId(Object id) {
		this.userRootId = id;
	}
	
	public Object getClaimRootId() {
		return claimRootId;
	}

	public Object getUserRootId() {
		return userRootId;
	}

	public Vertex getClaimRootVertex() {
		return graph.getVertex(claimRootId);
	}
	
	public Vertex getUserRootVertex() {
		return graph.getVertex(userRootId);
	}

	public void setLabelToRootUser(UserModel user) {
		Vertex rootUser = getUserRootVertex(); 
		/* 
		 *  rootUser ---child---> newUser
		 */
		graph.addEdge(null, rootUser, user.getVertex(), CHILD);
	}

	public void setLabelToRootClaim(ClaimModel claim) {
		Vertex rootClaim = getClaimRootVertex(); 
		/* 
		 *  rootUser ---child---> newUser
		 */
		graph.addEdge(null, rootUser, user.getVertex(), CHILD);
	}
	
	
	
	public void shutdownGraph() {
		graph.shutdown();
	}
	
	
	
	

	
}