* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.be.dao.titan;
-
-import com.thinkaurelius.titan.core.PropertyKey;
-import com.thinkaurelius.titan.core.TitanEdge;
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanGraphQuery;
-import com.thinkaurelius.titan.core.TitanVertex;
-import com.thinkaurelius.titan.core.TitanVertexQuery;
-import com.thinkaurelius.titan.graphdb.query.TitanPredicate;
+package org.openecomp.sdc.be.dao.janusgraph;
+
+import org.janusgraph.core.PropertyKey;
+import org.janusgraph.core.JanusGraphEdge;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphQuery;
+import org.janusgraph.core.JanusGraphVertex;
+import org.janusgraph.core.JanusGraphVertexQuery;
+import org.janusgraph.graphdb.query.JanusGraphPredicate;
import fj.data.Either;
import java.util.ArrayList;
import java.util.HashMap;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Qualifier;
-public class TitanGenericDao {
+public class JanusGraphGenericDao {
private static final String FAILED_TO_RETRIEVE_GRAPH_STATUS_IS = "Failed to retrieve graph. status is {}";
private static final String NO_EDGES_IN_GRAPH_FOR_CRITERIA = "No edges in graph for criteria";
private static final String FAILED_TO_CREATE_EDGE_FROM_TO = "Failed to create edge from [{}] to [{}]";
- private TitanGraphClient titanClient;
- private static Logger log = Logger.getLogger(TitanGenericDao.class.getName());
+ private JanusGraphClient janusGraphClient;
+ private static Logger log = Logger.getLogger(JanusGraphGenericDao.class.getName());
private static final String LOCK_NODE_PREFIX = "lock_";
- public TitanGenericDao(@Qualifier("titan-client") TitanGraphClient titanClient) {
- this.titanClient = titanClient;
- log.info("** TitanGenericDao created");
+ public JanusGraphGenericDao(@Qualifier("janusgraph-client") JanusGraphClient janusGraphClient) {
+ this.janusGraphClient = janusGraphClient;
+ log.info("** JanusGraphGenericDao created");
}
- public TitanOperationStatus commit() {
+ public JanusGraphOperationStatus commit() {
log.debug("doing commit.");
- return titanClient.commit();
+ return janusGraphClient.commit();
}
- public TitanOperationStatus rollback() {
+ public JanusGraphOperationStatus rollback() {
log.error("Going to execute rollback on graph.");
- return titanClient.rollback();
+ return janusGraphClient.rollback();
}
public <T, TStatus> void handleTransactionCommitRollback(boolean inTransaction, Either<T, TStatus> result) {
}
}
- public Either<TitanGraph, TitanOperationStatus> getGraph() {
- return titanClient.getGraph();
+ public Either<JanusGraph, JanusGraphOperationStatus> getGraph() {
+ return janusGraphClient.getGraph();
}
// For healthCheck
public boolean isGraphOpen() {
- return titanClient.getHealth();
+ return janusGraphClient.getHealth();
}
/**
* @param clazz
* @return
*/
- public <T extends GraphNode> Either<T, TitanOperationStatus> createNode(T node, Class<T> clazz) {
+ public <T extends GraphNode> Either<T, JanusGraphOperationStatus> createNode(T node, Class<T> clazz) {
log.debug("try to create node for ID [{}]", node.getKeyValueId());
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
T newNode;
try {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
Vertex vertex = tGraph.addVertex();
} catch (Exception e) {
log.debug("Failed to create Node for ID [{}]", node.getKeyValueId(), e);
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
}
}
- public Either<TitanVertex, TitanOperationStatus> createNode(GraphNode node) {
+ public Either<JanusGraphVertex, JanusGraphOperationStatus> createNode(GraphNode node) {
log.debug("try to create node for ID [{}]", node.getKeyValueId());
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
- TitanVertex vertex = tGraph.addVertex();
+ JanusGraphVertex vertex = tGraph.addVertex();
vertex.property(GraphPropertiesDictionary.LABEL.getProperty(), node.getLabel());
} catch (Exception e) {
log.debug("Failed to create Node for ID [{}]", node.getKeyValueId(), e);
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
* @param relation
* @return
*/
- public Either<GraphRelation, TitanOperationStatus> createRelation(GraphRelation relation) {
+ public Either<GraphRelation, JanusGraphOperationStatus> createRelation(GraphRelation relation) {
log.debug("try to create relation from [{}] to [{}] ", relation.getFrom(), relation.getTo());
RelationEndPoint from = relation.getFrom();
}
- private Either<GraphRelation, TitanOperationStatus> createEdge(String type, ImmutablePair<String, Object> from, ImmutablePair<String, Object> to, String fromLabel, String toLabel, Map<String, Object> properties) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ private Either<GraphRelation, JanusGraphOperationStatus> createEdge(String type, ImmutablePair<String, Object> from, ImmutablePair<String, Object> to, String fromLabel, String toLabel, Map<String, Object> properties) {
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
- Either<Vertex, TitanOperationStatus> fromV = getVertexByPropertyAndLabel(from.getKey(), from.getValue(), fromLabel);
+ Either<Vertex, JanusGraphOperationStatus> fromV = getVertexByPropertyAndLabel(from.getKey(), from.getValue(), fromLabel);
if (fromV.isRight()) {
- TitanOperationStatus error = fromV.right().value();
- if (TitanOperationStatus.NOT_FOUND.equals(error)) {
- return Either.right(TitanOperationStatus.INVALID_ID);
+ JanusGraphOperationStatus error = fromV.right().value();
+ if (JanusGraphOperationStatus.NOT_FOUND.equals(error)) {
+ return Either.right(JanusGraphOperationStatus.INVALID_ID);
} else {
return Either.right(error);
}
}
- Either<Vertex, TitanOperationStatus> toV = getVertexByPropertyAndLabel(to.getKey(), to.getValue(), toLabel);
+ Either<Vertex, JanusGraphOperationStatus> toV = getVertexByPropertyAndLabel(to.getKey(), to.getValue(), toLabel);
if (toV.isRight()) {
- TitanOperationStatus error = toV.right().value();
- if (TitanOperationStatus.NOT_FOUND.equals(error)) {
- return Either.right(TitanOperationStatus.INVALID_ID);
+ JanusGraphOperationStatus error = toV.right().value();
+ if (JanusGraphOperationStatus.NOT_FOUND.equals(error)) {
+ return Either.right(JanusGraphOperationStatus.INVALID_ID);
} else {
return Either.right(error);
}
return Either.left(newRelation);
} catch (Exception e) {
log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, from, to, e);
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
log.debug("Failed to create edge from [{}] to [{}] {}", from, to, graph.right().value());
}
}
- public TitanOperationStatus createEdge(Vertex vertexOut, Vertex vertexIn, GraphEdgeLabels type, Map<String, Object> properties) {
+ public JanusGraphOperationStatus createEdge(Vertex vertexOut, Vertex vertexIn, GraphEdgeLabels type, Map<String, Object> properties) {
try {
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
} catch (Exception e) {
log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, vertexOut, vertexIn, e);
- return TitanGraphClient.handleTitanException(e);
+ return JanusGraphClient.handleJanusGraphException(e);
}
- return TitanOperationStatus.OK;
+ return JanusGraphOperationStatus.OK;
}
* @param edge
* @return the copy operation status
*/
- public Either<Edge, TitanOperationStatus> copyEdge(Vertex out, Vertex in, Edge edge) {
+ public Either<Edge, JanusGraphOperationStatus> copyEdge(Vertex out, Vertex in, Edge edge) {
GraphEdgeLabels byName = GraphEdgeLabels.getByName(edge.label());
return this.saveEdge(out, in, byName, edgePropertiesToMap(edge));
}
return StreamSupport.stream(propertiesIterable.spliterator(), false).collect(Collectors.toMap(Property::key, Property::value));
}
- public Either<Edge, TitanOperationStatus> saveEdge(Vertex vertexOut, Vertex vertexIn, GraphEdgeLabels type, Map<String, Object> properties) {
+ public Either<Edge, JanusGraphOperationStatus> saveEdge(Vertex vertexOut, Vertex vertexIn, GraphEdgeLabels type, Map<String, Object> properties) {
try {
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
return Either.left(edge);
} catch (Exception e) {
log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, vertexOut, vertexIn, e);
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
}
- public TitanOperationStatus createEdge(TitanVertex vertexOut, GraphNode to, GraphEdgeLabels type, Map<String, Object> properties) {
+ public JanusGraphOperationStatus createEdge(JanusGraphVertex vertexOut, GraphNode to, GraphEdgeLabels type, Map<String, Object> properties) {
- TitanVertex vertexIn;
- Either<Vertex, TitanOperationStatus> toV = getVertexByPropertyAndLabel(to.getUniqueIdKey(), to.getUniqueId(), to.getLabel());
+ JanusGraphVertex vertexIn;
+ Either<Vertex, JanusGraphOperationStatus> toV = getVertexByPropertyAndLabel(to.getUniqueIdKey(), to.getUniqueId(), to.getLabel());
if (toV.isRight()) {
- TitanOperationStatus error = toV.right().value();
- if (TitanOperationStatus.NOT_FOUND.equals(error)) {
- return TitanOperationStatus.INVALID_ID;
+ JanusGraphOperationStatus error = toV.right().value();
+ if (JanusGraphOperationStatus.NOT_FOUND.equals(error)) {
+ return JanusGraphOperationStatus.INVALID_ID;
} else {
return error;
}
}
- vertexIn = (TitanVertex) toV.left().value();
+ vertexIn = (JanusGraphVertex) toV.left().value();
return createEdge(vertexOut, vertexIn, type, properties);
}
* @param properties
* @return
*/
- public Either<GraphRelation, TitanOperationStatus> createRelation(GraphNode from, GraphNode to, GraphEdgeLabels label, Map<String, Object> properties) {
+ public Either<GraphRelation, JanusGraphOperationStatus> createRelation(GraphNode from, GraphNode to, GraphEdgeLabels label, Map<String, Object> properties) {
log.debug("try to create relation from [{}] to [{}]", from.getKeyValueId(), to.getKeyValueId());
return createEdge(label.getProperty(), from.getKeyValueId(), to.getKeyValueId(), from.getLabel(), to.getLabel(), properties);
}
- public Either<GraphRelation, TitanOperationStatus> replaceRelationLabel(GraphNode from, GraphNode to, GraphEdgeLabels label, GraphEdgeLabels newLabel) {
+ public Either<GraphRelation, JanusGraphOperationStatus> replaceRelationLabel(GraphNode from, GraphNode to, GraphEdgeLabels label, GraphEdgeLabels newLabel) {
log.debug("try to replace relation {} to {} from [{}] to [{}]", label.name(), newLabel.name(), from.getKeyValueId(), to.getKeyValueId());
- Either<GraphRelation, TitanOperationStatus> getRelationResult = getRelation(from, to, label);
+ Either<GraphRelation, JanusGraphOperationStatus> getRelationResult = getRelation(from, to, label);
if (getRelationResult.isRight()) {
return getRelationResult;
}
GraphRelation origRelation = getRelationResult.left().value();
- Either<GraphRelation, TitanOperationStatus> createRelationResult = createRelation(from, to, newLabel, origRelation.toGraphMap());
+ Either<GraphRelation, JanusGraphOperationStatus> createRelationResult = createRelation(from, to, newLabel, origRelation.toGraphMap());
if (createRelationResult.isRight()) {
return createRelationResult;
}
- Either<GraphRelation, TitanOperationStatus> deleteRelationResult = deleteRelation(origRelation);
+ Either<GraphRelation, JanusGraphOperationStatus> deleteRelationResult = deleteRelation(origRelation);
if (deleteRelationResult.isRight()) {
return deleteRelationResult;
}
* @param clazz
* @return
*/
- public <T extends GraphNode> Either<T, TitanOperationStatus> getNode(String keyName, Object keyValue, Class<T> clazz) {
+ public <T extends GraphNode> Either<T, JanusGraphOperationStatus> getNode(String keyName, Object keyValue, Class<T> clazz) {
log.debug("Try to get node for key [{}] with value [{}] ", keyName, keyValue);
- Either<TitanVertex, TitanOperationStatus> vertexByProperty = getVertexByProperty(keyName, keyValue);
+ Either<JanusGraphVertex, JanusGraphOperationStatus> vertexByProperty = getVertexByProperty(keyName, keyValue);
if (vertexByProperty.isLeft()) {
try {
return Either.left(node);
} catch (Exception e) {
log.debug("Failed to get node for key [{}] with value [{}] ", keyName, keyValue, e);
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
log.debug("Failed to get node for key [{}] with value [{}] ", keyName, keyValue, vertexByProperty.right().value());
* @param label
* @return
*/
- public Either<GraphRelation, TitanOperationStatus> getRelation(GraphNode from, GraphNode to, GraphEdgeLabels label) {
+ public Either<GraphRelation, JanusGraphOperationStatus> getRelation(GraphNode from, GraphNode to, GraphEdgeLabels label) {
log.debug("try to get relation from [{}] to [{}]", from.getKeyValueId(), to.getKeyValueId());
- Either<Edge, TitanOperationStatus> edge = getEdgeByNodes(from, to, label);
+ Either<Edge, JanusGraphOperationStatus> edge = getEdgeByNodes(from, to, label);
if (edge.isLeft()) {
try {
return Either.left(relation);
} catch (Exception e) {
log.debug("Failed to get get relation from [{}] to [{}]", from.getKeyValueId(), to.getKeyValueId(), e);
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
log.debug("Failed to get get relation from [{}] to [{}] {}", from.getKeyValueId(), to.getKeyValueId(), edge.right().value());
}
}
- public Either<Edge, TitanOperationStatus> getEdgeByNodes(GraphNode from, GraphNode to, GraphEdgeLabels label) {
+ public Either<Edge, JanusGraphOperationStatus> getEdgeByNodes(GraphNode from, GraphNode to, GraphEdgeLabels label) {
ImmutablePair<String, Object> keyValueIdFrom = from.getKeyValueId();
ImmutablePair<String, Object> keyValueIdTo = to.getKeyValueId();
return getEdgeByVerticies(keyValueIdFrom.getKey(), keyValueIdFrom.getValue(), keyValueIdTo.getKey(), keyValueIdTo.getValue(), label.getProperty());
}
- public Either<GraphRelation, TitanOperationStatus> deleteIncomingRelationByCriteria(GraphNode to, GraphEdgeLabels label, Map<String, Object> props) {
+ public Either<GraphRelation, JanusGraphOperationStatus> deleteIncomingRelationByCriteria(GraphNode to, GraphEdgeLabels label, Map<String, Object> props) {
- Either<Edge, TitanOperationStatus> edgeByCriteria = getIncomingEdgeByCriteria(to, label, props);
+ Either<Edge, JanusGraphOperationStatus> edgeByCriteria = getIncomingEdgeByCriteria(to, label, props);
if (edgeByCriteria.isLeft()) {
- Either<TitanGraph, TitanOperationStatus> graph = getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = getGraph();
if (graph.isLeft()) {
Edge edge = edgeByCriteria.left().value();
log.debug("delete edge {} to {} ", label.getProperty(), to.getUniqueId());
}
- public Either<GraphRelation, TitanOperationStatus> getIncomingRelationByCriteria(GraphNode to, GraphEdgeLabels label, Map<String, Object> props) {
+ public Either<GraphRelation, JanusGraphOperationStatus> getIncomingRelationByCriteria(GraphNode to, GraphEdgeLabels label, Map<String, Object> props) {
- Either<Edge, TitanOperationStatus> edgeByCriteria = getIncomingEdgeByCriteria(to, label, props);
+ Either<Edge, JanusGraphOperationStatus> edgeByCriteria = getIncomingEdgeByCriteria(to, label, props);
if (edgeByCriteria.isLeft()) {
- Either<TitanGraph, TitanOperationStatus> graph = getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = getGraph();
if (graph.isLeft()) {
Edge edge = edgeByCriteria.left().value();
Map<String, Object> properties = getProperties(edge);
}
- public Either<Edge, TitanOperationStatus> getIncomingEdgeByCriteria(GraphNode to, GraphEdgeLabels label, Map<String, Object> props) {
+ public Either<Edge, JanusGraphOperationStatus> getIncomingEdgeByCriteria(GraphNode to, GraphEdgeLabels label, Map<String, Object> props) {
ImmutablePair<String, Object> keyValueIdTo = to.getKeyValueId();
- Either<TitanVertex, TitanOperationStatus> vertexFrom = getVertexByProperty(keyValueIdTo.getKey(), keyValueIdTo.getValue());
+ Either<JanusGraphVertex, JanusGraphOperationStatus> vertexFrom = getVertexByProperty(keyValueIdTo.getKey(), keyValueIdTo.getValue());
if (vertexFrom.isRight()) {
return Either.right(vertexFrom.right().value());
}
Vertex vertex = vertexFrom.left().value();
- TitanVertex titanVertex = (TitanVertex) vertex;
- TitanVertexQuery<?> query = titanVertex.query();
+ JanusGraphVertex janusGraphVertex = (JanusGraphVertex) vertex;
+ JanusGraphVertexQuery<?> query = janusGraphVertex.query();
query = query.labels(label.getProperty());
if (props != null && !props.isEmpty()) {
}
}
Edge matchingEdge = null;
- Iterable<TitanEdge> edges = query.edges();
+ Iterable<JanusGraphEdge> edges = query.edges();
if (edges == null) {
log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- Iterator<TitanEdge> eIter = edges.iterator();
+ Iterator<JanusGraphEdge> eIter = edges.iterator();
if (eIter.hasNext()) {
matchingEdge = eIter.next();
}
if (matchingEdge == null) {
log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);
}
- public Either<Edge, TitanOperationStatus> getEdgeByVerticies(String keyNameFrom, Object keyValueFrom, String keyNameTo, Object keyValueTo, String label) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ public Either<Edge, JanusGraphOperationStatus> getEdgeByVerticies(String keyNameFrom, Object keyValueFrom, String keyNameTo, Object keyValueTo, String label) {
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
- Either<TitanVertex, TitanOperationStatus> vertexFrom = getVertexByProperty(keyNameFrom, keyValueFrom);
+ Either<JanusGraphVertex, JanusGraphOperationStatus> vertexFrom = getVertexByProperty(keyNameFrom, keyValueFrom);
if (vertexFrom.isRight()) {
return Either.right(vertexFrom.right().value());
}
- Iterable<TitanEdge> edges = vertexFrom.left().value().query().labels(label).edges();
- Iterator<TitanEdge> eIter = edges.iterator();
+ Iterable<JanusGraphEdge> edges = vertexFrom.left().value().query().labels(label).edges();
+ Iterator<JanusGraphEdge> eIter = edges.iterator();
while (eIter.hasNext()) {
Edge edge = eIter.next();
Vertex vertexIn = edge.inVertex();
}
}
log.debug("No relation in graph from [{}={}] to [{}={}]", keyNameFrom, keyValueFrom, keyNameTo, keyValueTo);
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
} catch (Exception e) {
log.debug("Failed to get get relation from [{}={}] to [{}={}]", keyNameFrom, keyValueFrom, keyNameTo, keyValueTo, e);
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
return Either.right(graph.right().value());
}
}
- public Either<List<Edge>, TitanOperationStatus> getEdgesForNode(GraphNode node, Direction requestedDirection) {
+ public Either<List<Edge>, JanusGraphOperationStatus> getEdgesForNode(GraphNode node, Direction requestedDirection) {
- Either<List<Edge>, TitanOperationStatus> result;
+ Either<List<Edge>, JanusGraphOperationStatus> result;
ImmutablePair<String, Object> keyValueId = node.getKeyValueId();
- Either<TitanVertex, TitanOperationStatus> eitherVertex = getVertexByProperty(keyValueId.getKey(), keyValueId.getValue());
+ Either<JanusGraphVertex, JanusGraphOperationStatus> eitherVertex = getVertexByProperty(keyValueId.getKey(), keyValueId.getValue());
if (eitherVertex.isLeft()) {
List<Edge> edges = prepareEdgesList(eitherVertex.left().value(), requestedDirection);
private List<Edge> prepareEdgesList(Vertex vertex, Direction requestedDirection) {
List<Edge> edges = new ArrayList<>();
- Iterator<TitanEdge> edgesItr = ((TitanVertex) vertex).query().edges().iterator();
+ Iterator<JanusGraphEdge> edgesItr = ((JanusGraphVertex) vertex).query().edges().iterator();
while (edgesItr.hasNext()) {
Edge edge = edgesItr.next();
Direction currEdgeDirection = getEdgeDirection(vertex, edge);
* @param properties
* @return
*/
- public Either<GraphRelation, TitanOperationStatus> updateRelation(GraphNode from, GraphNode to, GraphEdgeLabels label, Map<String, Object> properties) {
+ public Either<GraphRelation, JanusGraphOperationStatus> updateRelation(GraphNode from, GraphNode to, GraphEdgeLabels label, Map<String, Object> properties) {
log.debug("try to update relation from [{}] to [{}]", from.getKeyValueId(), to.getKeyValueId());
return updateEdge(label.getProperty(), from.getKeyValueId(), to.getKeyValueId(), from.getLabel(), to.getLabel(), properties);
}
- private Either<GraphRelation, TitanOperationStatus> updateEdge(String type, ImmutablePair<String, Object> from, ImmutablePair<String, Object> to, String fromLabel, String toLabel, Map<String, Object> properties) {
+ private Either<GraphRelation, JanusGraphOperationStatus> updateEdge(String type, ImmutablePair<String, Object> from, ImmutablePair<String, Object> to, String fromLabel, String toLabel, Map<String, Object> properties) {
- Either<Edge, TitanOperationStatus> edgeS = getEdgeByVerticies(from.getKey(), from.getValue(), to.getKey(), to.getValue(), type);
+ Either<Edge, JanusGraphOperationStatus> edgeS = getEdgeByVerticies(from.getKey(), from.getValue(), to.getKey(), to.getValue(), type);
if (edgeS.isLeft()) {
try {
if (log.isDebugEnabled()) {
log.debug("Failed to update relation from [{}] to [{}] ", from, to, e);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
if (log.isDebugEnabled()) {
* @param relation
* @return
*/
- public Either<GraphRelation, TitanOperationStatus> updateRelation(GraphRelation relation) {
+ public Either<GraphRelation, JanusGraphOperationStatus> updateRelation(GraphRelation relation) {
log.debug("try to update relation from [{}] to [{}]", relation.getFrom(), relation.getTo());
RelationEndPoint from = relation.getFrom();
RelationEndPoint to = relation.getTo();
}
- private Either<Vertex, TitanOperationStatus> getVertexByPropertyAndLabel(String name, Object value, String label) {
+ private Either<Vertex, JanusGraphOperationStatus> getVertexByPropertyAndLabel(String name, Object value, String label) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
@SuppressWarnings("unchecked")
- Iterable<TitanVertex> vertecies = tGraph.query().has(name, value).has(GraphPropertiesDictionary.LABEL.getProperty(), label).vertices();
+ Iterable<JanusGraphVertex> vertecies = tGraph.query().has(name, value).has(GraphPropertiesDictionary.LABEL.getProperty(), label).vertices();
- java.util.Iterator<TitanVertex> iterator = vertecies.iterator();
+ java.util.Iterator<JanusGraphVertex> iterator = vertecies.iterator();
if (iterator.hasNext()) {
Vertex vertex = iterator.next();
return Either.left(vertex);
if (log.isDebugEnabled()) {
log.debug("No vertex in graph for key =" + name + " and value = " + value + " label = " + label);
}
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Failed to get vertex in graph for key ={} and value = {} label = {}",name,value,label);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
}
}
- public Either<TitanVertex, TitanOperationStatus> getVertexByProperty(String name, Object value) {
+ public Either<JanusGraphVertex, JanusGraphOperationStatus> getVertexByProperty(String name, Object value) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (value == null) {
if (log.isDebugEnabled()) {
log.debug("No vertex in graph for key = {} and value = {}", name, value);
}
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
if (graph.isLeft()) {
try {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
@SuppressWarnings("unchecked")
- Iterable<TitanVertex> vertecies = tGraph.query().has(name, value).vertices();
+ Iterable<JanusGraphVertex> vertecies = tGraph.query().has(name, value).vertices();
- java.util.Iterator<TitanVertex> iterator = vertecies.iterator();
+ java.util.Iterator<JanusGraphVertex> iterator = vertecies.iterator();
if (iterator.hasNext()) {
- TitanVertex vertex = iterator.next();
+ JanusGraphVertex vertex = iterator.next();
return Either.left(vertex);
} else {
if (log.isDebugEnabled()) {
log.debug("No vertex in graph for key ={} and value = {}", name, value);
}
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Failed to get vertex in graph for key = {} and value = ", name, value);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
if (log.isDebugEnabled()) {
}
}
- public <T extends GraphNode> Either<List<T>, TitanOperationStatus> getByCriteria(NodeTypeEnum type, Map<String, Object> hasProps, Map<String, Object> hasNotProps, Class<T> clazz) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteria(NodeTypeEnum type, Map<String, Object> hasProps, Map<String, Object> hasNotProps, Class<T> clazz) {
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
- TitanGraphQuery<? extends TitanGraphQuery> query = tGraph.query();
+ JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName());
if (hasProps != null && !hasProps.isEmpty()) {
query = query.hasNot(entry.getKey(), entry.getValue());
}
}
- Iterable<TitanVertex> vertices = query.vertices();
+ Iterable<JanusGraphVertex> vertices = query.vertices();
if (vertices == null) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- Iterator<TitanVertex> iterator = vertices.iterator();
+ Iterator<JanusGraphVertex> iterator = vertices.iterator();
List<T> result = new ArrayList<>();
while (iterator.hasNext()) {
log.debug("Number of fetced nodes in graph for criteria : from type = {} and properties has = {}, properties hasNot = {} is {}", type, hasProps, hasNotProps, result.size());
}
if (result.size() == 0) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(result);
if (log.isDebugEnabled()) {
log.debug("Failed get by criteria for type = {}", type, e);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
}
}
- public <T extends GraphNode> Either<List<T>, TitanOperationStatus> getByCriteria(NodeTypeEnum type, Class<T> clazz, List<ImmutableTriple<QueryType, String, Object>> props) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteria(NodeTypeEnum type, Class<T> clazz, List<ImmutableTriple<QueryType, String, Object>> props) {
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
- TitanGraphQuery<? extends TitanGraphQuery> query = tGraph.query();
+ JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName());
for (ImmutableTriple<QueryType, String, Object> prop : props) {
if (QueryType.HAS.equals(prop.getLeft())) {
query = query.hasNot(prop.getMiddle(), prop.getRight());
}
}
- Iterable<TitanVertex> vertices = query.vertices();
+ Iterable<JanusGraphVertex> vertices = query.vertices();
if (vertices == null) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- Iterator<TitanVertex> iterator = vertices.iterator();
+ Iterator<JanusGraphVertex> iterator = vertices.iterator();
List<T> result = new ArrayList<>();
while (iterator.hasNext()) {
result.add(element);
}
if (result.size() == 0) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(result);
if (log.isDebugEnabled()) {
log.debug("Failed get by criteria for type = {}", type, e);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
}
}
- public <T extends GraphNode> Either<List<T>, TitanOperationStatus> getByCriteria(NodeTypeEnum type, Map<String, Object> props, Class<T> clazz) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteria(NodeTypeEnum type, Map<String, Object> props, Class<T> clazz) {
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
- TitanGraphQuery<? extends TitanGraphQuery> query = tGraph.query();
+ JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName());
if (props != null && !props.isEmpty()) {
query = query.has(entry.getKey(), entry.getValue());
}
}
- Iterable<TitanVertex> vertices = query.vertices();
+ Iterable<JanusGraphVertex> vertices = query.vertices();
if (vertices == null) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- Iterator<TitanVertex> iterator = vertices.iterator();
+ Iterator<JanusGraphVertex> iterator = vertices.iterator();
List<T> result = new ArrayList<>();
while (iterator.hasNext()) {
log.debug("Number of fetced nodes in graph for criteria : from type = {} and properties = {} is {}", type, props, result.size());
}
if (result.size() == 0) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(result);
if (log.isDebugEnabled()) {
log.debug("Failed get by criteria for type = {} and properties = {}", type, props, e);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
}
}
- public <T extends GraphNode> Either<List<T>, TitanOperationStatus> getByCriteriaWithPredicate(NodeTypeEnum type, Map<String, Entry<TitanPredicate, Object>> props, Class<T> clazz) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteriaWithPredicate(NodeTypeEnum type, Map<String, Entry<JanusGraphPredicate, Object>> props, Class<T> clazz) {
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
- TitanGraphQuery<? extends TitanGraphQuery> query = tGraph.query();
+ JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName());
if (props != null && !props.isEmpty()) {
- TitanPredicate predicate = null;
+ JanusGraphPredicate predicate = null;
Object object = null;
- for (Map.Entry<String, Entry<TitanPredicate, Object>> entry : props.entrySet()) {
+ for (Map.Entry<String, Entry<JanusGraphPredicate, Object>> entry : props.entrySet()) {
predicate = entry.getValue().getKey();
object = entry.getValue().getValue();
query = query.has(entry.getKey(), predicate, object);
}
}
- Iterable<TitanVertex> vertices = query.vertices();
+ Iterable<JanusGraphVertex> vertices = query.vertices();
if (vertices == null) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- Iterator<TitanVertex> iterator = vertices.iterator();
+ Iterator<JanusGraphVertex> iterator = vertices.iterator();
List<T> result = new ArrayList<>();
while (iterator.hasNext()) {
result.add(element);
}
if (result.size() == 0) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
if (log.isDebugEnabled()) {
log.debug("No nodes in graph for criteria : from type = {} and properties = {}", type, props);
if (log.isDebugEnabled()) {
log.debug("Failed get by criteria for type = {} and properties = {}", type, props, e);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
}
}
- public <T extends GraphNode> Either<List<T>, TitanOperationStatus> getAll(NodeTypeEnum type, Class<T> clazz) {
+ public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getAll(NodeTypeEnum type, Class<T> clazz) {
return getByCriteria(type, null, clazz);
}
* @param clazz
* @return
*/
- public <T extends GraphNode> Either<T, TitanOperationStatus> updateNode(GraphNode node, Class<T> clazz) {
+ public <T extends GraphNode> Either<T, JanusGraphOperationStatus> updateNode(GraphNode node, Class<T> clazz) {
log.debug("Try to update node for {}", node.getKeyValueId());
ImmutablePair<String, Object> keyValueId = node.getKeyValueId();
- Either<Vertex, TitanOperationStatus> vertexByProperty = getVertexByPropertyAndLabel(keyValueId.getKey(), keyValueId.getValue(), node.getLabel());
+ Either<Vertex, JanusGraphOperationStatus> vertexByProperty = getVertexByPropertyAndLabel(keyValueId.getKey(), keyValueId.getValue(), node.getLabel());
if (vertexByProperty.isLeft()) {
try {
}
}
- Either<Vertex, TitanOperationStatus> vertexByPropertyAndLabel = getVertexByPropertyAndLabel(keyValueId.getKey(), keyValueId.getValue(), node.getLabel());
+ Either<Vertex, JanusGraphOperationStatus> vertexByPropertyAndLabel = getVertexByPropertyAndLabel(keyValueId.getKey(), keyValueId.getValue(), node.getLabel());
if (vertexByPropertyAndLabel.isRight()) {
return Either.right(vertexByPropertyAndLabel.right().value());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed to update node for {}", node.getKeyValueId(), e);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
if (log.isDebugEnabled()) {
}
- public TitanOperationStatus updateVertex(GraphNode node, Vertex vertex) {
+ public JanusGraphOperationStatus updateVertex(GraphNode node, Vertex vertex) {
log.debug("Try to update node for {}", node.getKeyValueId());
try {
if (log.isDebugEnabled()) {
log.debug("Failed to update node for {}", node.getKeyValueId(), e);
}
- return TitanGraphClient.handleTitanException(e);
+ return JanusGraphClient.handleJanusGraphException(e);
}
- return TitanOperationStatus.OK;
+ return JanusGraphOperationStatus.OK;
}
* @param clazz
* @return
*/
- public <T extends GraphNode> Either<T, TitanOperationStatus> deleteNode(GraphNode node, Class<T> clazz) {
+ public <T extends GraphNode> Either<T, JanusGraphOperationStatus> deleteNode(GraphNode node, Class<T> clazz) {
log.debug("Try to delete node for {}", node.getKeyValueId());
ImmutablePair<String, Object> keyValueId = node.getKeyValueId();
return deleteNode(keyValueId.getKey(), keyValueId.getValue(), clazz);
* @param clazz
* @return
*/
- public <T extends GraphNode> Either<T, TitanOperationStatus> deleteNode(String keyName, Object keyValue, Class<T> clazz) {
- Either<TitanVertex, TitanOperationStatus> vertexByProperty = getVertexByProperty(keyName, keyValue);
+ public <T extends GraphNode> Either<T, JanusGraphOperationStatus> deleteNode(String keyName, Object keyValue, Class<T> clazz) {
+ Either<JanusGraphVertex, JanusGraphOperationStatus> vertexByProperty = getVertexByProperty(keyName, keyValue);
if (vertexByProperty.isLeft()) {
try {
T node = GraphElementFactory.createElement(label, GraphElementTypeEnum.Node, properties, clazz);
if (node != null) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
- TitanGraph tGraph = graph.left().value();
+ JanusGraph tGraph = graph.left().value();
vertex.remove();
} else {
return Either.right(graph.right().value());
if (log.isDebugEnabled()) {
log.debug("Failed to delete node for {} = {} Missing label property on node", keyName, keyValue);
}
- return Either.right(TitanOperationStatus.MISSING_NODE_LABEL);
+ return Either.right(JanusGraphOperationStatus.MISSING_NODE_LABEL);
}
} else {
if (log.isDebugEnabled()) {
log.debug("Failed to delete node for {} = {} Missing label property on node", keyName, keyValue);
}
- return Either.right(TitanOperationStatus.MISSING_NODE_LABEL);
+ return Either.right(JanusGraphOperationStatus.MISSING_NODE_LABEL);
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Failed to delete node for {} = {}", keyName, keyValue, e);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
}
}
- public Either<GraphRelation, TitanOperationStatus> deleteRelation(GraphRelation relation) {
+ public Either<GraphRelation, JanusGraphOperationStatus> deleteRelation(GraphRelation relation) {
log.debug("try to delete relation from [{}] to [{}]", relation.getFrom(), relation.getTo());
RelationEndPoint from = relation.getFrom();
RelationEndPoint to = relation.getTo();
}
- public Either<Boolean, TitanOperationStatus> isRelationExist(GraphNode from, GraphNode to, GraphEdgeLabels edgeLabel) {
+ public Either<Boolean, JanusGraphOperationStatus> isRelationExist(GraphNode from, GraphNode to, GraphEdgeLabels edgeLabel) {
return getEdgeByNodes(from, to, edgeLabel)
.left()
.map(edge -> true)
.right()
- .bind(err -> err == TitanOperationStatus.NOT_FOUND ? Either.left(false): Either.right(err));
+ .bind(err -> err == JanusGraphOperationStatus.NOT_FOUND ? Either.left(false): Either.right(err));
}
- public Either<GraphRelation, TitanOperationStatus> deleteRelation(GraphNode from, GraphNode to, GraphEdgeLabels label) {
+ public Either<GraphRelation, JanusGraphOperationStatus> deleteRelation(GraphNode from, GraphNode to, GraphEdgeLabels label) {
log.debug("try to delete relation from [{}] to [{}]", from.getKeyValueId(), to.getKeyValueId());
return deleteEdge(label.getProperty(), from.getKeyValueId(), to.getKeyValueId(), from.getLabel(), to.getLabel());
}
- private Either<GraphRelation, TitanOperationStatus> deleteEdge(String type, ImmutablePair<String, Object> fromKeyId, ImmutablePair<String, Object> toKeyId, String fromLabel, String toLabel) {
- Either<Edge, TitanOperationStatus> edgeS = getEdgeByVerticies(fromKeyId.getKey(), fromKeyId.getValue(), toKeyId.getKey(), toKeyId.getValue(), type);
+ private Either<GraphRelation, JanusGraphOperationStatus> deleteEdge(String type, ImmutablePair<String, Object> fromKeyId, ImmutablePair<String, Object> toKeyId, String fromLabel, String toLabel) {
+ Either<Edge, JanusGraphOperationStatus> edgeS = getEdgeByVerticies(fromKeyId.getKey(), fromKeyId.getValue(), toKeyId.getKey(), toKeyId.getValue(), type);
if (edgeS.isLeft()) {
try {
Edge edge = edgeS.left().value();
GraphRelation newRelation = GraphElementFactory.createRelation(edge.label(), getProperties(edge), nodeOut, nodeIn);
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
edge.remove();
if (log.isDebugEnabled()) {
log.debug("Failed to delete relation {} from {} to {}", type, fromKeyId, toKeyId, e);
}
- return Either.right(TitanGraphClient.handleTitanException(e));
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
if (log.isDebugEnabled()) {
}
}
- public void setTitanGraphClient(TitanGraphClient titanGraphClient) {
- this.titanClient = titanGraphClient;
+ public void setJanusGraphClient(JanusGraphClient janusGraphClient) {
+ this.janusGraphClient = janusGraphClient;
}
- public Either<GraphRelation, TitanOperationStatus> deleteIncomingRelation(GraphRelation relation) {
+ public Either<GraphRelation, JanusGraphOperationStatus> deleteIncomingRelation(GraphRelation relation) {
RelationEndPoint to = relation.getTo();
ImmutablePair<String, Object> toKeyId = new ImmutablePair<>(to.getIdName(), to.getIdValue());
}
- private Either<GraphRelation, TitanOperationStatus> deleteIncomingEdge(String type, ImmutablePair<String, Object> toKeyId) {
+ private Either<GraphRelation, JanusGraphOperationStatus> deleteIncomingEdge(String type, ImmutablePair<String, Object> toKeyId) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
- Either<TitanVertex, TitanOperationStatus> rootVertexResult = getVertexByProperty(toKeyId.getKey(), toKeyId.getValue());
+ Either<JanusGraphVertex, JanusGraphOperationStatus> rootVertexResult = getVertexByProperty(toKeyId.getKey(), toKeyId.getValue());
if (rootVertexResult.isLeft()) {
Vertex rootVertex = rootVertexResult.left().value();
Iterator<Edge> edgesIterator = rootVertex.edges(Direction.IN, type);
if (edgesIterator.hasNext()) {
edge = edgesIterator.next();
if (edgesIterator.hasNext()) {
- return Either.right(TitanOperationStatus.MULTIPLE_EDGES_WITH_SAME_LABEL);
+ return Either.right(JanusGraphOperationStatus.MULTIPLE_EDGES_WITH_SAME_LABEL);
}
} else {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
log.debug("Find the tail vertex of the edge of type {} to vertex {}", type, toKeyId);
return Either.left(newRelation);
} else {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
} else {
}
- public Either<GraphRelation, TitanOperationStatus> deleteOutgoingRelation(GraphRelation relation) {
+ public Either<GraphRelation, JanusGraphOperationStatus> deleteOutgoingRelation(GraphRelation relation) {
RelationEndPoint from = relation.getFrom();
ImmutablePair<String, Object> fromKeyId = new ImmutablePair<>(from.getIdName(), from.getIdValue());
}
- private Either<GraphRelation, TitanOperationStatus> deleteOutgoingEdge(String type, ImmutablePair<String, Object> toKeyId) {
+ private Either<GraphRelation, JanusGraphOperationStatus> deleteOutgoingEdge(String type, ImmutablePair<String, Object> toKeyId) {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
- Either<TitanVertex, TitanOperationStatus> rootVertexResult = getVertexByProperty(toKeyId.getKey(), toKeyId.getValue());
+ Either<JanusGraphVertex, JanusGraphOperationStatus> rootVertexResult = getVertexByProperty(toKeyId.getKey(), toKeyId.getValue());
if (rootVertexResult.isLeft()) {
Vertex rootVertex = rootVertexResult.left().value();
Iterator<Edge> edgesIterator = rootVertex.edges(Direction.OUT, type);
if (edgesIterator.hasNext()) {
edge = edgesIterator.next();
if (edgesIterator.hasNext()) {
- return Either.right(TitanOperationStatus.MULTIPLE_EDGES_WITH_SAME_LABEL);
+ return Either.right(JanusGraphOperationStatus.MULTIPLE_EDGES_WITH_SAME_LABEL);
}
} else {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
log.debug("Find the tail vertex of the edge of type {} to vertex ", type, toKeyId);
return Either.left(newRelation);
} else {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
} else {
* @return
*/
- public TitanOperationStatus lockElement(String id, NodeTypeEnum type) {
+ public JanusGraphOperationStatus lockElement(String id, NodeTypeEnum type) {
StringBuffer lockId = new StringBuffer(LOCK_NODE_PREFIX);
lockId.append(type.getName()).append("_").append(id);
return lockNode(lockId.toString());
}
- public TitanOperationStatus lockElement(GraphNode node) {
+ public JanusGraphOperationStatus lockElement(GraphNode node) {
StringBuffer lockId = createLockElementId(node);
return lockNode(lockId.toString());
}
- private TitanOperationStatus lockNode(String lockId) {
- TitanOperationStatus status = TitanOperationStatus.OK;
+ private JanusGraphOperationStatus lockNode(String lockId) {
+ JanusGraphOperationStatus status = JanusGraphOperationStatus.OK;
GraphNodeLock lockNode = new GraphNodeLock(lockId);
- Either<GraphNodeLock, TitanOperationStatus> lockNodeNew = createNode(lockNode, GraphNodeLock.class);
+ Either<GraphNodeLock, JanusGraphOperationStatus> lockNodeNew = createNode(lockNode, GraphNodeLock.class);
if (lockNodeNew.isLeft()) {
log.debug("before commit, Lock node created for {}", lockId);
- return titanClient.commit();
+ return janusGraphClient.commit();
} else {
- Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
- TitanGraph tGraph = graph.left().value();
- Either<TitanVertex, TitanOperationStatus> vertex = getVertexByProperty(lockNode.getUniqueIdKey(), lockNode.getUniqueId());
+ JanusGraph tGraph = graph.left().value();
+ Either<JanusGraphVertex, JanusGraphOperationStatus> vertex = getVertexByProperty(lockNode.getUniqueIdKey(), lockNode.getUniqueId());
if (vertex.isLeft()) {
status = relockNode(lockNode, lockNodeNew, tGraph, vertex);
} else {
return status;
}
- private TitanOperationStatus relockNode(GraphNodeLock lockNode, Either<GraphNodeLock, TitanOperationStatus> lockNodeNew, TitanGraph tGraph, Either<TitanVertex, TitanOperationStatus> vertex) {
- TitanOperationStatus status = TitanOperationStatus.OK;
+ private JanusGraphOperationStatus relockNode(GraphNodeLock lockNode, Either<GraphNodeLock, JanusGraphOperationStatus> lockNodeNew, JanusGraph tGraph, Either<JanusGraphVertex, JanusGraphOperationStatus> vertex) {
+ JanusGraphOperationStatus status = JanusGraphOperationStatus.OK;
Long time = vertex.left().value().value(GraphPropertiesDictionary.CREATION_DATE.getProperty());
- Long lockTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getTitanLockTimeout();
+ Long lockTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getJanusGraphLockTimeout();
if (time + lockTimeout * 1000 < System.currentTimeMillis()) {
log.debug("Found not released lock node with id {}", lockNode.getUniqueId());
vertex.left().value().remove();
lockNodeNew = createNode(lockNode, GraphNodeLock.class);
if (lockNodeNew.isLeft()) {
log.debug("Lock node created for {}", lockNode.getUniqueIdKey());
- return titanClient.commit();
+ return janusGraphClient.commit();
} else {
log.debug("Failed Lock node for {} . Commit transacton for deleted previous vertex .", lockNode.getUniqueIdKey());
- titanClient.commit();
+ janusGraphClient.commit();
status = checkLockError(lockNode.getUniqueIdKey(), lockNodeNew);
}
} else {
log.debug("Failed Lock node for {} rollback transacton", lockNode.getUniqueIdKey());
- titanClient.rollback();
+ janusGraphClient.rollback();
status = checkLockError(lockNode.getUniqueIdKey(), lockNodeNew);
}
return status;
}
- public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> getChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz, boolean withEdges) {
+ public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> getChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz, boolean withEdges) {
List<ImmutablePair<T, GraphEdge>> immutablePairs = new ArrayList<>();
- Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graphRes = janusGraphClient.getGraph();
if (graphRes.isRight()) {
log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
return Either.right(graphRes.right().value());
}
- TitanGraph titanGraph = graphRes.left().value();
+ JanusGraph janusGraph = graphRes.left().value();
@SuppressWarnings("unchecked")
- Iterable<TitanVertex> vertices = titanGraph.query().has(key, uniqueId).vertices();
+ Iterable<JanusGraphVertex> vertices = janusGraph.query().has(key, uniqueId).vertices();
if (vertices == null || !vertices.iterator().hasNext()) {
- return Either.right(TitanOperationStatus.INVALID_ID);
+ return Either.right(JanusGraphOperationStatus.INVALID_ID);
}
Vertex rootVertex = vertices.iterator().next();
}
if (immutablePairs.isEmpty()) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(immutablePairs);
}
- public Either<List<ImmutablePair<TitanVertex, Edge>>, TitanOperationStatus> getChildrenVertecies(String key, String uniqueId, GraphEdgeLabels edgeType) {
+ public Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getChildrenVertecies(String key, String uniqueId, GraphEdgeLabels edgeType) {
- List<ImmutablePair<TitanVertex, Edge>> immutablePairs = new ArrayList<>();
+ List<ImmutablePair<JanusGraphVertex, Edge>> immutablePairs = new ArrayList<>();
- Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graphRes = janusGraphClient.getGraph();
if (graphRes.isRight()) {
log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
return Either.right(graphRes.right().value());
}
- TitanGraph titanGraph = graphRes.left().value();
+ JanusGraph janusGraph = graphRes.left().value();
@SuppressWarnings("unchecked")
- Iterable<TitanVertex> vertices = titanGraph.query().has(key, uniqueId).vertices();
+ Iterable<JanusGraphVertex> vertices = janusGraph.query().has(key, uniqueId).vertices();
if (vertices == null || !vertices.iterator().hasNext()) {
- return Either.right(TitanOperationStatus.INVALID_ID);
+ return Either.right(JanusGraphOperationStatus.INVALID_ID);
}
Vertex rootVertex = vertices.iterator().next();
if (edgesCreatorIterator != null) {
while (edgesCreatorIterator.hasNext()) {
Edge edge = edgesCreatorIterator.next();
- TitanVertex vertex = (TitanVertex) edge.inVertex();
+ JanusGraphVertex vertex = (JanusGraphVertex) edge.inVertex();
- ImmutablePair<TitanVertex, Edge> immutablePair = new ImmutablePair<>(vertex, edge);
+ ImmutablePair<JanusGraphVertex, Edge> immutablePair = new ImmutablePair<>(vertex, edge);
immutablePairs.add(immutablePair);
}
}
if (immutablePairs.isEmpty()) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(immutablePairs);
}
- public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> getChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
+ public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> getChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
return this.getChildrenNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz, true);
}
- private TitanOperationStatus checkLockError(String lockId, Either<GraphNodeLock, TitanOperationStatus> lockNodeNew) {
- TitanOperationStatus status;
- TitanOperationStatus error = lockNodeNew.right().value();
+ private JanusGraphOperationStatus checkLockError(String lockId, Either<GraphNodeLock, JanusGraphOperationStatus> lockNodeNew) {
+ JanusGraphOperationStatus status;
+ JanusGraphOperationStatus error = lockNodeNew.right().value();
log.debug("Failed to Lock node for {} error = {}", lockId, error);
- if (error.equals(TitanOperationStatus.TITAN_SCHEMA_VIOLATION) || error.equals(TitanOperationStatus.ILLEGAL_ARGUMENT)) {
- status = TitanOperationStatus.ALREADY_LOCKED;
+ if (error.equals(JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION) || error.equals(
+ JanusGraphOperationStatus.ILLEGAL_ARGUMENT)) {
+ status = JanusGraphOperationStatus.ALREADY_LOCKED;
} else {
status = error;
}
* @param node
* @return
*/
- public TitanOperationStatus releaseElement(GraphNode node) {
+ public JanusGraphOperationStatus releaseElement(GraphNode node) {
StringBuffer lockId = createLockElementId(node);
return unlockNode(lockId);
}
- private TitanOperationStatus unlockNode(StringBuffer lockId) {
+ private JanusGraphOperationStatus unlockNode(StringBuffer lockId) {
GraphNodeLock lockNode = new GraphNodeLock(lockId.toString());
- Either<GraphNodeLock, TitanOperationStatus> lockNodeNew = deleteNode(lockNode, GraphNodeLock.class);
+ Either<GraphNodeLock, JanusGraphOperationStatus> lockNodeNew = deleteNode(lockNode, GraphNodeLock.class);
if (lockNodeNew.isLeft()) {
log.debug("Lock node released for lock id = {}", lockId);
- return titanClient.commit();
+ return janusGraphClient.commit();
} else {
- titanClient.rollback();
- TitanOperationStatus error = lockNodeNew.right().value();
+ janusGraphClient.rollback();
+ JanusGraphOperationStatus error = lockNodeNew.right().value();
log.debug("Failed to Release node for lock id {} error = {}", lockId, error);
return error;
}
}
- public TitanOperationStatus releaseElement(String id, NodeTypeEnum type) {
+ public JanusGraphOperationStatus releaseElement(String id, NodeTypeEnum type) {
StringBuffer lockId = new StringBuffer(LOCK_NODE_PREFIX);
lockId.append(type.getName()).append("_").append(id);
return unlockNode(lockId);
return lockId;
}
- public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, TitanOperationStatus> getChild(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
+ public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, JanusGraphOperationStatus> getChild(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
- Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> childrenNodes = getChildrenNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz);
+ Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = getChildrenNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz);
if (childrenNodes.isRight()) {
return Either.right(childrenNodes.right().value());
List<ImmutablePair<T, GraphEdge>> value = childrenNodes.left().value();
if (value.size() > 1) {
- return Either.right(TitanOperationStatus.MULTIPLE_CHILDS_WITH_SAME_EDGE);
+ return Either.right(JanusGraphOperationStatus.MULTIPLE_CHILDS_WITH_SAME_EDGE);
}
return Either.left(value.get(0));
}
- public ImmutablePair<TitanVertex, Edge> getChildVertex(TitanVertex vertex, GraphEdgeLabels edgeType) {
+ public ImmutablePair<JanusGraphVertex, Edge> getChildVertex(JanusGraphVertex vertex, GraphEdgeLabels edgeType) {
- ImmutablePair<TitanVertex, Edge> pair = null;
+ ImmutablePair<JanusGraphVertex, Edge> pair = null;
Iterator<Edge> edges = vertex.edges(Direction.OUT, edgeType.getProperty());
if (edges.hasNext()) {
// get only first edge
Edge edge = edges.next();
- pair = new ImmutablePair<>((TitanVertex) edge.inVertex(), edge);
+ pair = new ImmutablePair<>((JanusGraphVertex) edge.inVertex(), edge);
}
return pair;
}
- public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> getParentNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
+ public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> getParentNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
List<ImmutablePair<T, GraphEdge>> immutablePairs = new ArrayList<>();
T data = null;
GraphEdge graphEdge = null;
- Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
+ Either<JanusGraph, JanusGraphOperationStatus> graphRes = janusGraphClient.getGraph();
if (graphRes.isRight()) {
log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
return Either.right(graphRes.right().value());
}
- TitanGraph titanGraph = graphRes.left().value();
+ JanusGraph janusGraph = graphRes.left().value();
@SuppressWarnings("unchecked")
- Iterable<TitanVertex> vertices = titanGraph.query().has(key, uniqueId).vertices();
+ Iterable<JanusGraphVertex> vertices = janusGraph.query().has(key, uniqueId).vertices();
if (vertices == null || !vertices.iterator().hasNext()) {
- return Either.right(TitanOperationStatus.INVALID_ID);
+ return Either.right(JanusGraphOperationStatus.INVALID_ID);
}
Vertex rootVertex = vertices.iterator().next();
}
if (immutablePairs.isEmpty()) {
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(immutablePairs);
}
- public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, TitanOperationStatus> getParentNode(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
+ public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, JanusGraphOperationStatus> getParentNode(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
- Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> parentNodesRes = this.getParentNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz);
+ Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> parentNodesRes = this.getParentNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz);
if (parentNodesRes.isRight()) {
log.debug("failed to get edge key:{} uniqueId:{} edgeType {} nodeTypeEnum: {}, reason:{}", key, uniqueId, edgeType, nodeTypeEnum, parentNodesRes.right().value());
List<ImmutablePair<T, GraphEdge>> value = parentNodesRes.left().value();
if (value.size() > 1) {
- return Either.right(TitanOperationStatus.MULTIPLE_CHILDS_WITH_SAME_EDGE);
+ return Either.right(JanusGraphOperationStatus.MULTIPLE_CHILDS_WITH_SAME_EDGE);
}
return Either.left(value.get(0));
}
- public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, TitanOperationStatus> getChildByEdgeCriteria(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz, Map<String, Object> edgeProperties) {
+ public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, JanusGraphOperationStatus> getChildByEdgeCriteria(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz, Map<String, Object> edgeProperties) {
- Either<Edge, TitanOperationStatus> outgoingEdgeByCriteria = getOutgoingEdgeByCriteria(key, uniqueId, edgeType, edgeProperties);
+ Either<Edge, JanusGraphOperationStatus> outgoingEdgeByCriteria = getOutgoingEdgeByCriteria(key, uniqueId, edgeType, edgeProperties);
if (outgoingEdgeByCriteria.isRight()) {
- TitanOperationStatus status = outgoingEdgeByCriteria.right().value();
+ JanusGraphOperationStatus status = outgoingEdgeByCriteria.right().value();
log.debug("Cannot find outgoing edge from vertex {} with label {} and properties {}" + uniqueId, edgeType, edgeProperties);
return Either.right(status);
}
return Either.left(immutablePair);
}
- public Either<ImmutablePair<TitanVertex, Edge>, TitanOperationStatus> getChildByEdgeCriteria(TitanVertex vertex, GraphEdgeLabels edgeType, Map<String, Object> edgeProperties) {
+ public Either<ImmutablePair<JanusGraphVertex, Edge>, JanusGraphOperationStatus> getChildByEdgeCriteria(JanusGraphVertex vertex, GraphEdgeLabels edgeType, Map<String, Object> edgeProperties) {
- Either<Edge, TitanOperationStatus> outgoingEdgeByCriteria = getOutgoingEdgeByCriteria(vertex, edgeType, edgeProperties);
+ Either<Edge, JanusGraphOperationStatus> outgoingEdgeByCriteria = getOutgoingEdgeByCriteria(vertex, edgeType, edgeProperties);
if (outgoingEdgeByCriteria.isRight()) {
- TitanOperationStatus status = outgoingEdgeByCriteria.right().value();
+ JanusGraphOperationStatus status = outgoingEdgeByCriteria.right().value();
log.debug("Cannot find outgoing edge from vertex {} with label {} and properties {}", vertex, edgeType, edgeProperties);
return Either.right(status);
}
Edge edge = outgoingEdgeByCriteria.left().value();
- TitanVertex outgoingVertex = (TitanVertex) edge.inVertex();
+ JanusGraphVertex outgoingVertex = (JanusGraphVertex) edge.inVertex();
- ImmutablePair<TitanVertex, Edge> immutablePair = new ImmutablePair<>(outgoingVertex, edge);
+ ImmutablePair<JanusGraphVertex, Edge> immutablePair = new ImmutablePair<>(outgoingVertex, edge);
return Either.left(immutablePair);
}
- public Either<Edge, TitanOperationStatus> getOutgoingEdgeByCriteria(String key, String value, GraphEdgeLabels label, Map<String, Object> props) {
+ public Either<Edge, JanusGraphOperationStatus> getOutgoingEdgeByCriteria(String key, String value, GraphEdgeLabels label, Map<String, Object> props) {
- Either<TitanVertex, TitanOperationStatus> vertexFrom = getVertexByProperty(key, value);
+ Either<JanusGraphVertex, JanusGraphOperationStatus> vertexFrom = getVertexByProperty(key, value);
if (vertexFrom.isRight()) {
- TitanOperationStatus status = vertexFrom.right().value();
- if (status == TitanOperationStatus.NOT_FOUND) {
- return Either.right(TitanOperationStatus.INVALID_ID);
+ JanusGraphOperationStatus status = vertexFrom.right().value();
+ if (status == JanusGraphOperationStatus.NOT_FOUND) {
+ return Either.right(JanusGraphOperationStatus.INVALID_ID);
}
return Either.right(status);
}
return getOutgoingEdgeByCriteria(vertexFrom.left().value(), label, props);
}
- public Either<Edge, TitanOperationStatus> getOutgoingEdgeByCriteria(TitanVertex vertex, GraphEdgeLabels label, Map<String, Object> props) {
+ public Either<Edge, JanusGraphOperationStatus> getOutgoingEdgeByCriteria(JanusGraphVertex vertex, GraphEdgeLabels label, Map<String, Object> props) {
- TitanVertexQuery<?> query = vertex.query();
+ JanusGraphVertexQuery<?> query = vertex.query();
query = query.direction(Direction.OUT).labels(label.getProperty());
if (props != null && !props.isEmpty()) {
}
}
Edge matchingEdge = null;
- Iterable<TitanEdge> edges = query.edges();
+ Iterable<JanusGraphEdge> edges = query.edges();
if (edges == null) {
log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- Iterator<TitanEdge> eIter = edges.iterator();
+ Iterator<JanusGraphEdge> eIter = edges.iterator();
if (eIter.hasNext()) {
matchingEdge = eIter.next();
}
if (matchingEdge == null) {
log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);
}
- public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> deleteChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
+ public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> deleteChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
List<ImmutablePair<T, GraphEdge>> result = new ArrayList<>();
- Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> childrenNodesRes = getChildrenNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz);
+ Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> childrenNodesRes = getChildrenNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz);
if (childrenNodesRes.isRight()) {
- TitanOperationStatus status = childrenNodesRes.right().value();
+ JanusGraphOperationStatus status = childrenNodesRes.right().value();
return Either.right(status);
}
List<ImmutablePair<T, GraphEdge>> list = childrenNodesRes.left().value();
for (ImmutablePair<T, GraphEdge> pair : list) {
T node = pair.getKey();
- Either<T, TitanOperationStatus> deleteNodeRes = this.deleteNode(node, clazz);
+ Either<T, JanusGraphOperationStatus> deleteNodeRes = this.deleteNode(node, clazz);
if (deleteNodeRes.isRight()) {
- TitanOperationStatus status = deleteNodeRes.right().value();
+ JanusGraphOperationStatus status = deleteNodeRes.right().value();
log.error("Failed to delete node {} . status is {}", node, status);
return Either.right(status);
}
return result;
}
- public Object getProperty(TitanVertex vertex, String key) {
- PropertyKey propertyKey = titanClient.getGraph().left().value().getPropertyKey(key);
+ public Object getProperty(JanusGraphVertex vertex, String key) {
+ PropertyKey propertyKey = janusGraphClient.getGraph().left().value().getPropertyKey(key);
return vertex.valueOrNull(propertyKey);
}
return value;
}
- public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> getChildrenByEdgeCriteria(Vertex vertex, String vertexUniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz,
- Map<String, Object> edgeProperties) {
+ public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> getChildrenByEdgeCriteria(Vertex vertex, String vertexUniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz,
+ Map<String, Object> edgeProperties) {
List<ImmutablePair<T, GraphEdge>> result = new ArrayList<>();
- Either<List<Edge>, TitanOperationStatus> outgoingEdgeByCriteria = getOutgoingEdgesByCriteria(vertex, edgeType, edgeProperties);
+ Either<List<Edge>, JanusGraphOperationStatus> outgoingEdgeByCriteria = getOutgoingEdgesByCriteria(vertex, edgeType, edgeProperties);
if (outgoingEdgeByCriteria.isRight()) {
- TitanOperationStatus status = outgoingEdgeByCriteria.right().value();
+ JanusGraphOperationStatus status = outgoingEdgeByCriteria.right().value();
log.debug("Cannot find outgoing edge from vertex {} with label {} and properties {}", vertexUniqueId, edgeType, edgeProperties);
return Either.right(status);
}
return Either.left(result);
}
- public Either<List<Edge>, TitanOperationStatus> getOutgoingEdgesByCriteria(Vertex vertexFrom, GraphEdgeLabels label, Map<String, Object> props) {
+ public Either<List<Edge>, JanusGraphOperationStatus> getOutgoingEdgesByCriteria(Vertex vertexFrom, GraphEdgeLabels label, Map<String, Object> props) {
List<Edge> edgesResult = new ArrayList<>();
- TitanVertex titanVertex = (TitanVertex) vertexFrom;
- TitanVertexQuery<?> query = titanVertex.query();
+ JanusGraphVertex janusGraphVertex = (JanusGraphVertex) vertexFrom;
+ JanusGraphVertexQuery<?> query = janusGraphVertex.query();
query = query.direction(Direction.OUT).labels(label.getProperty());
}
}
- Iterable<TitanEdge> edges = query.edges();
- Iterator<TitanEdge> eIter = edges.iterator();
+ Iterable<JanusGraphEdge> edges = query.edges();
+ Iterator<JanusGraphEdge> eIter = edges.iterator();
if (edges == null || !eIter.hasNext()) {
log.debug("No edges found in graph for criteria (label = {} properties={})", label.getProperty(), props);
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
while (eIter.hasNext()) {
if (edgesResult.isEmpty()) {
log.debug("No edges found in graph for criteria (label = {} properties={})", label.getProperty(), props);
- return Either.right(TitanOperationStatus.NOT_FOUND);
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(edgesResult);