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();
}
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();
}
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);
}
Aggregations