use of com.thinkaurelius.titan.core.TitanEdge in project titan by thinkaurelius.
the class AllEdgesIterator method findNext.
private Edge findNext() {
TitanEdge rel = null;
while (rel == null) {
if (currentEdges.hasNext()) {
rel = (TitanEdge) currentEdges.next();
if (vertices != null && !vertices.contains(rel.vertex(Direction.IN)))
rel = null;
} else {
if (vertexIter.hasNext()) {
Vertex nextVertex = vertexIter.next();
currentEdges = nextVertex.edges(Direction.OUT);
} else
break;
}
}
return rel;
}
use of com.thinkaurelius.titan.core.TitanEdge in project titan by thinkaurelius.
the class ManagementSystem method setStatusEdges.
private void setStatusEdges(TitanSchemaVertex vertex, SchemaStatus status, Set<PropertyKeyVertex> keys) {
Preconditions.checkArgument(vertex.asIndexType().isMixedIndex());
for (TitanEdge edge : vertex.getEdges(TypeDefinitionCategory.INDEX_FIELD, Direction.OUT)) {
//Only address edges with matching keys
if (!keys.contains(edge.vertex(Direction.IN)))
continue;
TypeDefinitionDescription desc = edge.valueOrNull(BaseKey.SchemaDefinitionDesc);
assert desc.getCategory() == TypeDefinitionCategory.INDEX_FIELD;
Parameter[] parameters = (Parameter[]) desc.getModifier();
assert parameters[parameters.length - 1].key().equals(ParameterType.STATUS.getName());
if (parameters[parameters.length - 1].value().equals(status))
continue;
Parameter[] paraCopy = Arrays.copyOf(parameters, parameters.length);
paraCopy[parameters.length - 1] = ParameterType.STATUS.getParameter(status);
edge.remove();
addSchemaEdge(vertex, edge.vertex(Direction.IN), TypeDefinitionCategory.INDEX_FIELD, paraCopy);
}
for (PropertyKeyVertex prop : keys) prop.resetCache();
}
use of com.thinkaurelius.titan.core.TitanEdge in project titan by thinkaurelius.
the class ManagementSystem method setTypeModifier.
private void setTypeModifier(final TitanSchemaElement element, final ModifierType modifierType, final Object value) {
Preconditions.checkArgument(element != null, "null schema element");
TypeDefinitionCategory cat = modifierType.getCategory();
if (cat.hasDataType() && null != value) {
Preconditions.checkArgument(cat.getDataType().equals(value.getClass()), "modifier value is not of expected type " + cat.getDataType());
}
TitanSchemaVertex typeVertex;
if (element instanceof TitanSchemaVertex) {
typeVertex = (TitanSchemaVertex) element;
} else if (element instanceof TitanGraphIndex) {
IndexType index = ((TitanGraphIndexWrapper) element).getBaseIndex();
assert index instanceof IndexTypeWrapper;
SchemaSource base = ((IndexTypeWrapper) index).getSchemaBase();
typeVertex = (TitanSchemaVertex) base;
} else
throw new IllegalArgumentException("Invalid schema element: " + element);
// remove any pre-existing value for the modifier, or return if an identical value has already been set
for (TitanEdge e : typeVertex.getEdges(TypeDefinitionCategory.TYPE_MODIFIER, Direction.OUT)) {
TitanSchemaVertex v = (TitanSchemaVertex) e.vertex(Direction.IN);
TypeDefinitionMap def = v.getDefinition();
Object existingValue = def.getValue(modifierType.getCategory());
if (null != existingValue) {
if (existingValue.equals(value)) {
//Already has the right value, don't need to do anything
return;
} else {
e.remove();
v.remove();
}
}
}
if (null != value) {
TypeDefinitionMap def = new TypeDefinitionMap();
def.setValue(cat, value);
TitanSchemaVertex cVertex = transaction.makeSchemaVertex(TitanSchemaCategory.TYPE_MODIFIER, null, def);
addSchemaEdge(typeVertex, cVertex, TypeDefinitionCategory.TYPE_MODIFIER, null);
}
updateSchemaVertex(typeVertex);
updatedTypes.add(typeVertex);
}
use of com.thinkaurelius.titan.core.TitanEdge in project titan by thinkaurelius.
the class EdgeSerializerTest method testValueOrdering.
@Test
public void testValueOrdering() {
StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
TitanManagement mgmt = graph.openManagement();
EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
for (int i = 1; i <= 5; i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
mgmt.commit();
TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
TitanEdge e1 = v1.addEdge("father", v2);
for (int i = 1; i <= 5; i++) e1.property("key" + i, i);
graph.tx().commit();
e1.remove();
graph.tx().commit();
}
Aggregations