Search in sources :

Example 16 with OrientEdge

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();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 17 with OrientEdge

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");
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 18 with OrientEdge

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();
    }
}
Also used : OrientEdgeType(com.tinkerpop.blueprints.impls.orient.OrientEdgeType) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 19 with OrientEdge

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"));
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 20 with OrientEdge

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;
}
Also used : ArrayList(java.util.ArrayList) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OETLProcessHaltedException(com.orientechnologies.orient.etl.OETLProcessHaltedException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException)

Aggregations

OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)32 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 Test (org.junit.Test)17 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)12 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)6 Edge (com.tinkerpop.blueprints.Edge)5 HashSet (java.util.HashSet)5 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)4 HashMap (java.util.HashMap)4 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)3 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2 OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)2 OIndex (com.orientechnologies.orient.core.index.OIndex)2 OImmutableClass (com.orientechnologies.orient.core.metadata.schema.OImmutableClass)2 ODirtyManager (com.orientechnologies.orient.core.record.impl.ODirtyManager)2