@contribute
2016-09-23T03:41:06.000000Z
字数 6695
阅读 2245
tinkerpop3
g.V()
和g.E()
两种方式,也就是说,极可能需遍历所有的点也可能遍历所有的边。g.V().outE()
);获取一个edge时,也能很快的找到edge对应的出点和入点(如g.E().outV()
)。OLTP需要实现的接口无外乎包含以下几种类型:
- 对vertex、edge、property的增删改查操作。
- 获取vertex、edge或property的集合的Iterator。
/**
* Retrieve the vertex (or vertices) associated with this edge as defined by the direction.
* If the direction is {@link Direction#BOTH} then the iterator order is: {@link Direction#OUT} then {@link Direction#IN}.
*
* @param direction Get the incoming vertex, outgoing vertex, or both vertices
* @return An iterator with 1 or 2 vertices
*/
public Iterator<Vertex> vertices(final Direction direction);
@Override
public <V> Iterator<Property<V>> properties(final String... propertyKeys);
/**
* Add an outgoing edge to the vertex with provided label and edge properties as key/value pairs.
* These key/values must be provided in an even number where the odd numbered arguments are {@link String}
* property keys and the even numbered arguments are the related property values.
*
* @param label The label of the edge
* @param inVertex The vertex to receive an incoming edge from the current vertex
* @param keyValues The key/value pairs to turn into edge properties
* @return the newly created edge
*/
public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues);
/**
* Create a new vertex property. If the cardinality is {@link VertexProperty.Cardinality#single}, then set the key
* to the value. If the cardinality is {@link VertexProperty.Cardinality#list}, then add a new value to the key.
* If the cardinality is {@link VertexProperty.Cardinality#set}, then only add a new value if that value doesn't
* already exist for the key. If the value already exists for the key, add the provided key value vertex property
* properties to it.
*
* @param cardinality the desired cardinality of the property key
* @param key the key of the vertex property
* @param value The value of the vertex property
* @param keyValues the key/value pairs to turn into vertex property properties
* @param <V> the type of the value of the vertex property
* @return the newly created vertex property
*/
public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues);
/**
* Gets an {@link Iterator} of incident edges.
*
* @param direction The incident direction of the edges to retrieve off this vertex
* @param edgeLabels The labels of the edges to retrieve. If no labels are provided, then get all edges.
* @return An iterator of edges meeting the provided specification
*/
public Iterator<Edge> edges(final Direction direction, final String... edgeLabels);
/**
* Gets an {@link Iterator} of adjacent vertices.
*
* @param direction The adjacency direction of the vertices to retrieve off this vertex
* @param edgeLabels The labels of the edges associated with the vertices to retrieve. If no labels are provided,
* then get all edges.
* @return An iterator of vertices meeting the provided specification
*/
public Iterator<Vertex> vertices(final Direction direction, final String... edgeLabels);
/**
* {@inheritDoc}
*/
@Override
public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys);
/**
* {@inheritDoc}
*/
@Override
public <U> Iterator<Property<U>> properties(final String... propertyKeys);
/**
* Gets the unique identifier for the graph {@code Element}.
*
* @return The id of the element
*/
public Object id();
/**
* Gets the label for the graph {@code Element} which helps categorize it.
*
* @return The label of the element
*/
public String label();
/**
* Get the graph that this element is within.
*
* @return the graph of this element
*/
public Graph graph();
/**
* Add or set a property value for the {@code Element} given its key.
*/
public <V> Property<V> property(final String key, final V value);
/**
* Get an {@link Iterator} of properties.
*/
public <V> Iterator<? extends Property<V>> properties(final String... propertyKeys);
/**
* Removes the {@code Element} from the graph.
*/
public void remove();
KuazVertex
public class KuazVertex {
private Object id;
private String label;
private List<Object> outEdgeIds;
private List<Object> inEdgeIds;
}
KuazEdge
public class KuazEdge {
private Object id;
private String label;
private Object outVertexId;
private Object inVertexId;
}
KuazProperty
public class KuazProperty {
private static String value = "value";
private static String property = "property";
/**
* 属性所属的点或边的id.
*/
private Object elementId;
/**
* 属性id.
*/
private String propertyId;
/**
* 属性的类型是key/value还是属性中有属性。
*/
private String propertyType = value;
/**
* 属性名
*/
private String propertyKey;
/**
* 属性值
*/
private Object propertyValue;
/**
* 用于存多值属性和属性中的属性的id。
*/
private List<Object> proerties;
}
- 采用 Object + Map 的设计设计方案。
- 只建立vertexCache和edgeCache两个Cache。
- vertex和edge的属性分别存在对应的Object中的Map中。
g.V()
和g.E()
开始的两种GraphTraversal。
public class KuazEdge {
private Object id;
@QuerySqlField(index = true)
private String label;
@AffinityKeyMapped
private Object outVertexId;
@AffinityKeyMapped
private Object inVertexId;
private Map<String, Object> properties;
}
public class KuazVertex {
private Object id;
@QuerySqlField(index = true)
private String label;
private List<Object> outEdgeIds;
private List<Object> inEdgeIds;
private Map<String, Map<String, Object>> properties;
}
public class KuazEdge {
private Object id;
private String label;
private Object outVid;
private Object inVid;
private List<Property> properties;
}
public class KuazVertex {
private Object id;
private String label;
private Object outEid;
private Object inEid;
private List<VertexProperty> property;
}
public class Property {
protected Object id;
protected String key;
protected String value;
}
public class VertexProperty extends Property {
private List<Property> properties;
}
public class KuazEdge {
private Object id;
private String label;
private Object outVid;
private Object inVid;
private List<Property> properties;
}
public class KuazVertex {
private Object id;
private String label;
private KuazEdge outEdge;
private KuazEdge inEdge;
private List<VertexProperty> property;
}
public class Property {
protected Object id;
protected String key;
protected String value;
}
public class VertexProperty extends Property {
private List<Property> properties;
}
public class KuazEdge {
private Object id;
private String label;
private Object outVid;
private Object inVid;
private List<Property> properties;
}
public class KuazVertex {
private Object id;
private String label;
private KuazEdge outEdge;
private KuazEdge inEdge;
private List<VertexProperty> property;
}
public class Property {
protected Object id;
protected String key;
protected String value;
}
public class VertexProperty extends Property {
private List<Property> properties;
}
说明:采用两个edgeCache来存储KuzaEdge,一个cache跟出点做并置,另一个cache跟入点做并置。此设计是针对优化computer进行优化的。
g.V().hasLabel('person').count()