use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException 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;
}
use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.
the class TestGraphTransactionOnBatch method testDuplicateEdgeAlreadyPresentRollback.
@Test
public void testDuplicateEdgeAlreadyPresentRollback() {
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.setSuperClass(E);
clazz.createProperty("aKey", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex V \n LET b = create vertex V \n LET c =create edge Test from $a to $b SET aKey = \"12345\" \n commit \n" + " RETURN $c")).execute();
try {
db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex V \n LET b = create vertex V \n LET c =create edge Test from $a to $b SET aKey = \"12345\"\n COMMIT \n" + " RETURN $c")).execute();
Assert.fail("expected record duplicate exception");
} catch (ORecordDuplicatedException ex) {
}
List<ODocument> res = db.query(new OSQLSynchQuery("select from Test"));
Assert.assertEquals(1, res.size());
}
use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.
the class OGraphImporterMTAPITest method main.
public static void main(String[] args) throws IOException, InterruptedException {
OGlobalConfiguration.ENVIRONMENT_LOCK_MANAGER_CONCURRENCY_LEVEL.setValue(64);
// String dbUrl = "memory:amazonReviews";
final String dbUrl = "plocal:/temp/databases/amazonReviews";
final File f = new File("/temp/databases/amazonReviews");
if (f.exists())
OFileUtils.deleteRecursively(f);
final OrientGraph roGraph = new OrientGraph(dbUrl, "admin", "admin");
final OrientGraphNoTx graph = new OrientGraphNoTx(dbUrl, "admin", "admin");
OrientVertexType user = graph.createVertexType("User", 64);
user.createProperty("uid", OType.STRING);
user.createIndex("User.uid", OClass.INDEX_TYPE.UNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "uid" });
OrientVertexType product = graph.createVertexType("Product", 64);
product.createProperty("uid", OType.STRING);
product.createIndex("Product.uid", OClass.INDEX_TYPE.UNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "uid" });
graph.createEdgeType("Reviewed");
final File file = new File("/Users/luca/Downloads/ratings_Books.csv");
final BufferedReader br = new BufferedReader(new FileReader(file));
final AtomicLong retry = new AtomicLong();
Orient.instance().scheduleTask(new TimerTask() {
@Override
public void run() {
roGraph.makeActive();
final long vertexCount = roGraph.countVertices();
final long edgeCount = roGraph.countEdges();
System.out.println(String.format("%d vertices=%d %d/sec edges=%d %d/sec retry=%d", row, vertexCount, ((vertexCount - lastVertexCount) * 1000 / 2000), edgeCount, ((edgeCount - lastEdgeCount) * 1000 / 2000), retry.get()));
lastVertexCount = vertexCount;
lastEdgeCount = edgeCount;
}
}, 2000, 2000);
final ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<String>(10000);
final Thread[] threads = new Thread[parallel];
for (int i = 0; i < parallel; ++i) {
threads[i] = new Thread() {
@Override
public void run() {
final OrientGraph localGraph = new OrientGraph(dbUrl, "admin", "admin", false);
final OIndex<?> userIndex = localGraph.getRawGraph().getMetadata().getIndexManager().getIndex("User.uid");
final OIndex<?> productIndex = localGraph.getRawGraph().getMetadata().getIndexManager().getIndex("Product.uid");
localGraph.begin();
for (int i = 0; ; ++i) {
final String line;
try {
line = queue.take();
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
final String[] parts = line.split(",");
if (parts.length != 4) {
// SKIP IT
System.out.print("Skipped invalid line " + i + ": " + line);
continue;
}
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("score", new Float(parts[2]).intValue());
properties.put("date", Long.parseLong(parts[3]));
for (int localRetry = 0; localRetry < 100; ++localRetry) {
try {
final Object k1 = userIndex.get(parts[0]);
OrientVertex v1;
if (k1 == null) {
v1 = localGraph.addVertex("class:User", "uid", parts[0]);
} else
v1 = localGraph.getVertex(k1);
final Object k2 = productIndex.get(parts[1]);
OrientVertex v2;
if (k2 == null) {
v2 = localGraph.addVertex("class:Product", "uid", parts[1]);
} else
v2 = localGraph.getVertex(k2);
final OrientEdge edge = localGraph.addEdge(null, v1, v2, "Reviewed");
edge.setProperties(properties);
if (i % 2 == 0) {
localGraph.commit();
localGraph.begin();
}
break;
} catch (ONeedRetryException e) {
// RETRY
retry.incrementAndGet();
} catch (ORecordDuplicatedException e) {
// RETRY
retry.incrementAndGet();
}
}
}
}
};
}
for (int i = 0; i < parallel; ++i) threads[i].start();
try {
for (String line; (line = br.readLine()) != null; ) {
row++;
queue.put(line);
}
} finally {
br.close();
}
for (int i = 0; i < parallel; ++i) threads[i].join();
graph.shutdown();
roGraph.shutdown();
}
use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.
the class TestGraphTransactionOnBatch method testDuplicateRollback.
@Test
public void testDuplicateRollback() {
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.setSuperClass(V);
clazz.createProperty("id", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
try {
db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex Test SET id = \"12345678\" \n LET b = create vertex Test SET id = \"4kkrPhGe\" \n LET c =create vertex Test SET id = \"4kkrPhGe\" \n COMMIT \n RETURN $b ")).execute();
Assert.fail("expected record duplicate exception");
} catch (ORecordDuplicatedException ex) {
}
try {
db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex Test content {\"id\": \"12345678\"} \n LET b = create vertex Test content {\"id\": \"4kkrPhGe\"} \n LET c =create vertex Test content { \"id\": \"4kkrPhGe\"} \n COMMIT \n RETURN $b ")).execute();
Assert.fail("expected record duplicate exception");
} catch (ORecordDuplicatedException ex) {
}
List<ODocument> res = db.query(new OSQLSynchQuery("select from Test"));
Assert.assertEquals(0, res.size());
}
use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.
the class EdgeIndexingTest method testOutLinksUniqueness.
/**
* Test that "in_vertex" has edges to only single "out_vertex" but we may have several edges to single "out_vertex".
*/
@Test
public void testOutLinksUniqueness() {
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);
graph.commit();
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();
}
Aggregations