use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.
the class OOrientDBLoader method load.
@Override
public void load(OETLPipeline pipeline, final Object input, OCommandContext context) {
if (input == null)
return;
if (dbAutoCreateProperties) {
autoCreateProperties(pipeline, input);
}
if (tx && dbType == DOCUMENT) {
final ODatabaseDocument documentDatabase = pipeline.getDocumentDatabase();
if (!documentDatabase.getTransaction().isActive()) {
documentDatabase.begin();
documentDatabase.getTransaction().setUsingLog(txUseLog);
}
}
if (input instanceof OrientVertex) {
final OrientVertex v = (OrientVertex) input;
try {
v.save(clusterName);
} catch (ORecordDuplicatedException e) {
if (skipDuplicates) {
} else {
throw e;
}
} finally {
}
} else if (input instanceof ODocument) {
final ODocument doc = (ODocument) input;
if (className != null) {
doc.setClassName(className);
}
if (clusterName != null) {
doc.save(clusterName);
} else {
doc.save();
}
}
progress.incrementAndGet();
// DO BATCH COMMIT
if (batchCommitSize > 0 && batchCounter.get() > batchCommitSize) {
if (dbType == DOCUMENT) {
final ODatabaseDocument documentDatabase = pipeline.getDocumentDatabase();
log(DEBUG, "committing batch");
documentDatabase.commit();
documentDatabase.begin();
documentDatabase.getTransaction().setUsingLog(txUseLog);
} else {
log(DEBUG, "committing batch");
pipeline.getGraphDatabase().commit();
}
batchCounter.set(0);
} else {
batchCounter.incrementAndGet();
}
}
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 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);
}
use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.
the class OClassIndexManager method onRecordAfterUpdate.
@Override
public void onRecordAfterUpdate(ODocument iDocument) {
iDocument = checkForLoading(iDocument);
final OClass cls = ODocumentInternal.getImmutableSchemaClass(iDocument);
if (cls == null)
return;
final Collection<OIndex<?>> indexes = cls.getIndexes();
if (!indexes.isEmpty()) {
final Set<String> dirtyFields = new HashSet<String>(Arrays.asList(iDocument.getDirtyFields()));
if (!dirtyFields.isEmpty()) {
for (final OIndex<?> index : indexes) {
try {
processIndexUpdate(iDocument, dirtyFields, index);
} catch (ORecordDuplicatedException ex) {
iDocument.undo();
iDocument.setDirty();
database.save(iDocument);
throw ex;
}
}
}
}
}
use of com.orientechnologies.orient.core.storage.ORecordDuplicatedException in project orientdb by orientechnologies.
the class OIndexTxAwareOneValue method checkEntry.
@Override
public ODocument checkEntry(final OIdentifiable iRecord, Object iKey) {
iKey = getCollatingValue(iKey);
// CHECK IF ALREADY EXISTS IN TX
if (!database.getTransaction().isActive()) {
final OIdentifiable previousRecord = get(iKey);
if (previousRecord != null && !previousRecord.equals(iRecord)) {
final ODocument metadata = getMetadata();
Boolean mergeKeys = false;
if (metadata != null) {
mergeKeys = metadata.field(OIndex.MERGE_KEYS);
}
final boolean mergeSameKey = mergeKeys != null && mergeKeys;
if (mergeSameKey) {
return (ODocument) previousRecord.getRecord();
} else
throw new ORecordDuplicatedException(String.format("Cannot index record %s: found duplicated key '%s' in index '%s' previously assigned to the record %s", iRecord, iKey, getName(), previousRecord), getName(), previousRecord.getIdentity());
}
return super.checkEntry(iRecord, iKey);
}
return null;
}
Aggregations