use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class GraphValidationTest method edgesCannotBeVertices.
@Test
public void edgesCannotBeVertices() {
OrientGraphNoTx gNoTx = new OrientGraphNoTx(URL, "admin", "admin");
try {
gNoTx.createVertexType("TestV");
gNoTx.createEdgeType("TestE");
OrientVertex v = gNoTx.addVertex("class:TestV");
OrientVertex loadedV = gNoTx.getVertex(v.getIdentity());
try {
OrientEdge e = gNoTx.getEdge(v.getIdentity().toString());
Assert.fail();
} catch (IllegalArgumentException e) {
// OK
}
} finally {
gNoTx.shutdown();
}
OrientGraph g = new OrientGraph(URL, "admin", "admin");
try {
OrientVertex v = g.addVertex("class:TestV");
OrientVertex loadedV = g.getVertex(v.getIdentity().toString());
try {
OrientEdge e = g.getEdge(v.getIdentity());
Assert.fail();
} catch (IllegalArgumentException e) {
// OK
}
} finally {
g.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class TestFailOperationOnRemovedElement method testSetPropertiesRemovedEdge.
@Test(expected = ORecordNotFoundException.class)
public void testSetPropertiesRemovedEdge() {
OrientVertex v = grap.addVertex(null);
OrientVertex v1 = grap.addVertex(null);
OrientEdge e = (OrientEdge) v.addEdge("test", v1);
grap.commit();
e.remove();
e.setProperties("test", "test");
}
use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class IndexAgainstEdges method indexes.
@Test
public void indexes() {
OrientGraph g = new OrientGraph(URL, "admin", "admin");
try {
if (g.getVertexType("Profile") == null)
g.createVertexType("Profile");
if (g.getEdgeType("Friend") == null) {
final OrientEdgeType f = g.createEdgeType("Friend");
f.createProperty("in", OType.LINK);
f.createProperty("out", OType.LINK);
f.createIndex("Friend.in_out", OClass.INDEX_TYPE.UNIQUE, "in", "out");
}
OrientVertex luca = g.addVertex("class:Profile", "name", "Luca");
OrientVertex jay = g.addVertex("class:Profile", "name", "Jay");
OrientEdge friend = (OrientEdge) luca.addEdge("Friend", jay);
assertFalse(friend.isLightweight());
} finally {
g.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class TestGetProperties method getPropertiesFromEdge.
@Test
public void getPropertiesFromEdge() {
OrientVertex v = graph.addVertex(null);
OrientVertex v1 = graph.addVertex(null);
OrientEdge e = (OrientEdge) v.addEdge("test", v1);
e.setProperty("test", "test");
e.setProperty("test1", "test1");
Map<String, Object> props = e.getProperties();
Assert.assertEquals(2, props.size());
Assert.assertEquals("test", props.get("test"));
Assert.assertEquals("test1", props.get("test1"));
}
use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.
the class OEdgeTransformer method createEdge.
private List<OrientEdge> createEdge(final OrientVertex vertex, final Object joinCurrentValue, Object result) {
log(OETLProcessor.LOG_LEVELS.DEBUG, "joinCurrentValue=%s, lookupResult=%s", joinCurrentValue, result);
if (result == null) {
// APPLY THE STRATEGY DEFINED IN unresolvedLinkAction
switch(unresolvedLinkAction) {
case CREATE:
// Don't try to create a Vertex with a null value
if (joinCurrentValue != null) {
if (lookup != null) {
final String[] lookupParts = lookup.split("\\.");
final OrientVertex linkedV = pipeline.getGraphDatabase().addTemporaryVertex(lookupParts[0]);
linkedV.setProperty(lookupParts[1], joinCurrentValue);
if (targetVertexFields != null) {
for (String f : targetVertexFields.fieldNames()) linkedV.setProperty(f, resolve(targetVertexFields.field(f)));
}
linkedV.save();
log(OETLProcessor.LOG_LEVELS.DEBUG, "created new vertex=%s", linkedV.getRecord());
result = linkedV.getIdentity();
} else {
throw new OConfigurationException("Cannot create linked document because target class is unknown. Use 'lookup' field");
}
}
break;
case ERROR:
processor.getStats().incrementErrors();
log(OETLProcessor.LOG_LEVELS.ERROR, "%s: ERROR Cannot resolve join for value '%s'", getName(), joinCurrentValue);
break;
case WARNING:
processor.getStats().incrementWarnings();
log(OETLProcessor.LOG_LEVELS.INFO, "%s: WARN Cannot resolve join for value '%s'", getName(), joinCurrentValue);
break;
case SKIP:
return null;
case HALT:
throw new OETLProcessHaltedException("Cannot resolve join for value '" + joinCurrentValue + "'");
case NOTHING:
default:
return null;
}
}
if (result != null) {
final List<OrientEdge> edges;
if (OMultiValue.isMultiValue(result)) {
final int size = OMultiValue.getSize(result);
if (size == 0)
// NO EDGES
return null;
edges = new ArrayList<OrientEdge>(size);
} else
edges = new ArrayList<OrientEdge>(1);
for (Object o : OMultiValue.getMultiValueIterable(result)) {
OIdentifiable oid = (OIdentifiable) o;
final OrientVertex targetVertex = pipeline.getGraphDatabase().getVertex(oid);
try {
// CREATE THE EDGE
final OrientEdge edge;
if (directionOut)
edge = (OrientEdge) vertex.addEdge(edgeClass, targetVertex);
else
edge = (OrientEdge) targetVertex.addEdge(edgeClass, vertex);
if (edgeFields != null) {
for (String f : edgeFields.fieldNames()) edge.setProperty(f, resolve(edgeFields.field(f)));
}
edges.add(edge);
log(OETLProcessor.LOG_LEVELS.DEBUG, "created new edge=%s", edge);
} catch (ORecordDuplicatedException e) {
if (skipDuplicates) {
log(OETLProcessor.LOG_LEVELS.DEBUG, "skipped creation of new edge because already exists");
continue;
} else {
log(OETLProcessor.LOG_LEVELS.ERROR, "error on creation of new edge because it already exists (skipDuplicates=false)");
throw e;
}
}
}
return edges;
}
// NO EDGES
return null;
}
Aggregations