use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class OSQLFunctionIn method fetchFromIndex.
private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
String edgeClassName = null;
if (iEdgeTypes == null) {
edgeClassName = "E";
} else if (iEdgeTypes.length == 1) {
edgeClassName = iEdgeTypes[0];
} else {
return null;
}
OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
if (edgeClass == null) {
return null;
}
Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("in", "out");
if (indexes == null || indexes.size() == 0) {
return null;
}
OIndex index = indexes.iterator().next();
OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
for (OIdentifiable to : iTo) {
OCompositeKey key = new OCompositeKey(iFrom, to);
Object indexResult = index.get(key);
if (indexResult instanceof OIdentifiable) {
indexResult = Collections.singleton(indexResult);
}
Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
}
result.add(identities);
}
return result;
}
use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class TestFailOperationOnRemovedElement method testPropertyTypeRemovedEdge.
@Test(expected = ORecordNotFoundException.class)
public void testPropertyTypeRemovedEdge() {
OrientVertex v = grap.addVertex(null);
OrientVertex v1 = grap.addVertex(null);
OrientEdge e = (OrientEdge) v.addEdge("test", v1);
grap.commit();
e.remove();
e.setProperty("test", "test", OType.STRING);
}
use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class OrientdbEdgeTest method testEdges.
@Test
public void testEdges() throws Exception {
OrientGraphFactory factory = getGraphFactory();
OrientBaseGraph g = factory.getNoTx();
try {
try {
g.createEdgeType("some-label");
} catch (OSchemaException ex) {
if (!ex.getMessage().contains("exists"))
throw (ex);
g.command(new OCommandSQL("delete edge some-label")).execute();
}
try {
g.createVertexType("some-v-label");
} catch (OSchemaException ex) {
if (!ex.getMessage().contains("exists"))
throw (ex);
g.command(new OCommandSQL("delete vertex some-v-label")).execute();
}
} finally {
g.shutdown();
}
OrientGraph t = factory.getTx();
try {
Vertex v1 = t.addVertex("class:some-v-label");
Vertex v2 = t.addVertex("class:some-v-label");
v1.setProperty("_id", "v1");
v2.setProperty("_id", "v2");
OrientEdge edge = t.addEdge(null, v1, v2, "some-label");
edge.setProperty("some", "thing");
t.commit();
t.shutdown();
t = factory.getTx();
assertEquals(2, t.countVertices("some-v-label"));
assertEquals(1, t.countEdges());
assertNotNull(t.getVertices("_id", "v1").iterator().next());
assertNotNull(t.getVertices("_id", "v2").iterator().next());
t.commit();
t.shutdown();
t = factory.getTx();
// works
assertEquals(1, t.getVertices("_id", "v1").iterator().next().query().labels("some-label").count());
// NoSuchElementException
assertNotNull(t.getVertices("_id", "v1").iterator().next().query().labels("some-label").edges().iterator().next());
t.commit();
} finally {
t.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class GraphDatabaseTest method testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe.
public void testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe() {
Iterable<OIdentifiable> deletedVertices = database.command(new OCommandSQL("delete from GraphVehicle return before limit 1 unsafe")).execute();
Assert.assertTrue(deletedVertices.iterator().hasNext());
OrientVertex v = (OrientVertex) deletedVertices.iterator().next();
Integer confirmDeleted = database.command(new OCommandSQL("delete from " + v.getIdentity() + " unsafe")).execute();
Assert.assertFalse(deletedVertices.iterator().hasNext());
Assert.assertEquals(confirmDeleted.intValue(), 0);
Iterable<Edge> edges = v.getEdges(Direction.BOTH);
for (Edge e : edges) {
Integer deletedEdges = database.command(new OCommandSQL("delete from " + ((OrientEdge) e).getIdentity() + " unsafe")).execute();
Assert.assertEquals(deletedEdges.intValue(), 1);
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class GraphDatabaseTest method testNewVertexAndEdgesWithFieldsInOneShoot.
public void testNewVertexAndEdgesWithFieldsInOneShoot() throws IOException {
OrientVertex vertexA = database.addVertex(null, "field1", "value1", "field2", "value2");
Map<String, Object> map = new HashMap<String, Object>();
map.put("field1", "value1");
map.put("field2", "value2");
OrientVertex vertexB = database.addVertex(null, map);
OrientEdge edgeC = database.addEdge(null, vertexA, vertexB, "E");
edgeC.setProperty("edgeF1", "edgeV2");
database.commit();
Assert.assertEquals(vertexA.getProperty("field1"), "value1");
Assert.assertEquals(vertexA.getProperty("field2"), "value2");
Assert.assertEquals(vertexB.getProperty("field1"), "value1");
Assert.assertEquals(vertexB.getProperty("field2"), "value2");
Assert.assertEquals(edgeC.getProperty("edgeF1"), "edgeV2");
}
Aggregations