Search in sources :

Example 31 with ORecordDuplicatedException

use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.

the class EdgeIndexingTest method testOutLinksUniquenessThree.

/**
   * Test that "out_vertex" has edges to only single "in_vertex" but we may have several edges to single "in_vertex".
   */
@Test
public void testOutLinksUniquenessThree() {
    final String url = "memory:" + this.getClass().getSimpleName();
    OrientGraph graph = new OrientGraph(url, "admin", "admin", false);
    graph.drop();
    graph = new OrientGraph(url, "admin", "admin", false);
    graph.setUseLightweightEdges(true);
    graph.createEdgeType("link");
    OClass inVertexType = graph.createVertexType("IndexedInVertex");
    inVertexType.createProperty("in_link", OType.LINKBAG);
    inVertexType.createIndex("uniqueLinkIndex", "unique", "in_link");
    graph.setAutoStartTx(true);
    Vertex vertexOutOne = graph.addVertex(null);
    Vertex vertexInOne = graph.addVertex("class:IndexedInVertex");
    Vertex vertexInTwo = graph.addVertex("class:IndexedInVertex");
    vertexOutOne.addEdge("link", vertexInOne);
    vertexOutOne.addEdge("link", vertexInTwo);
    try {
        graph.commit();
        Assert.fail();
    // in vertex can be linked by only one out vertex.
    } catch (ORecordDuplicatedException e) {
    }
    graph.drop();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.junit.Test)

Example 32 with ORecordDuplicatedException

use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.

the class EdgeIndexingTest method testOutLinksUniquenessTwo.

/**
   * Test that "in_vertex" has edges to only single "out_vertex" but we may have several edges to single "out_vertex".
   */
@Test
public void testOutLinksUniquenessTwo() {
    final String url = "memory:" + this.getClass().getSimpleName();
    OrientGraph graph = new OrientGraph(url);
    graph.drop();
    graph = new OrientGraph(url);
    graph.setUseLightweightEdges(true);
    graph.createEdgeType("link");
    graph.setAutoStartTx(false);
    OClass outVertexType = graph.createVertexType("IndexedOutVertex");
    outVertexType.createProperty("out_link", OType.LINKBAG);
    outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");
    graph.setAutoStartTx(true);
    Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");
    Vertex vertexInOne = graph.addVertex(null);
    Vertex vertexInTwo = graph.addVertex(null);
    vertexOutOne.addEdge("link", vertexInOne);
    vertexOutOne.addEdge("link", vertexInTwo);
    Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
    vertexOutTwo.addEdge("link", vertexInTwo);
    try {
        graph.commit();
        // in vertex can be linked by only one out vertex.
        Assert.fail();
    } catch (ORecordDuplicatedException e) {
    }
    graph.drop();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.junit.Test)

Example 33 with ORecordDuplicatedException

use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.

the class IndexTest method testTransactionUniqueIndexTestOne.

public void testTransactionUniqueIndexTestOne() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(database.getURL());
    db.open("admin", "admin");
    if (!db.getMetadata().getSchema().existsClass("TransactionUniqueIndexTest")) {
        final OClass termClass = db.getMetadata().getSchema().createClass("TransactionUniqueIndexTest", 1, null);
        termClass.createProperty("label", OType.STRING);
        termClass.createIndex("idxTransactionUniqueIndexTest", INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "label" });
        db.getMetadata().getSchema().save();
    }
    ODocument docOne = new ODocument("TransactionUniqueIndexTest");
    docOne.field("label", "A");
    docOne.save();
    final List<ODocument> resultBeforeCommit = db.query(new OSQLSynchQuery<ODocument>("select from index:idxTransactionUniqueIndexTest"));
    Assert.assertEquals(resultBeforeCommit.size(), 1);
    db.begin();
    try {
        ODocument docTwo = new ODocument("TransactionUniqueIndexTest");
        docTwo.field("label", "A");
        docTwo.save();
        db.commit();
        Assert.fail();
    } catch (ORecordDuplicatedException oie) {
    }
    final List<ODocument> resultAfterCommit = db.query(new OSQLSynchQuery<ODocument>("select from index:idxTransactionUniqueIndexTest"));
    Assert.assertEquals(resultAfterCommit.size(), 1);
}
Also used : ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)33 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)19 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)17 Test (org.junit.Test)10 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)8 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)6 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)5 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)5 Vertex (com.tinkerpop.blueprints.Vertex)5 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)4 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)4 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)4 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)2 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)2