use of com.orientechnologies.common.concur.ONeedRetryException in project orientdb by orientechnologies.
the class IndexConcurrencyTest method addSubTree.
public static void addSubTree(String parentName, char startLetter) {
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
for (int i = 0; ; ++i) {
try {
ODocument parent;
final List<ODocument> result = db.command(new OCommandSQL("select from Person where name = '" + parentName + "'")).execute();
parent = result.get(0);
if (parent == null) {
db.close();
return;
}
String newName = parentName;
newName += Character.toString(startLetter);
StringBuilder newIdentifier = new StringBuilder(newName);
newIdentifier.setCharAt(0, 'B');
db.begin();
PersonTree tree = new PersonTree();
tree.SetRoot(parent);
ODocument child = tree.AddChild(parent, newName, newIdentifier.toString());
buildTree(tree, child.getIdentity(), newName, subnodes, depth - 1, startLetter);
db.commit();
break;
} catch (ONeedRetryException e) {
System.out.println("Concurrency change, retry " + i);
} catch (Exception ex) {
ex.printStackTrace();
}
}
// printPersons("After addSubTree", db);
db.close();
}
use of com.orientechnologies.common.concur.ONeedRetryException in project orientdb by orientechnologies.
the class OFunction method execute.
public Object execute(final Map<Object, Object> iArgs) {
final long start = Orient.instance().getProfiler().startChrono();
Object result;
while (true) {
try {
if (callback != null)
return callback.call(iArgs);
final OCommandExecutorScript command = new OCommandExecutorScript();
command.parse(new OCommandScript(getLanguage(), getCode()));
result = command.execute(iArgs);
break;
} catch (ONeedRetryException e) {
continue;
} catch (ORetryQueryException e) {
continue;
}
}
if (Orient.instance().getProfiler().isRecording())
Orient.instance().getProfiler().stopChrono("db." + ODatabaseRecordThreadLocal.INSTANCE.get().getName() + ".function.execute", "Time to execute a function", start, "db.*.function.execute");
return result;
}
use of com.orientechnologies.common.concur.ONeedRetryException in project orientdb by orientechnologies.
the class OTransactionNoTx method saveRecord.
/**
* Update the record.
*
* @param iRecord
* @param iForceCreate
* @param iRecordCreatedCallback
* @param iRecordUpdatedCallback
*/
public ORecord saveRecord(final ORecord iRecord, final String iClusterName, final OPERATION_MODE iMode, boolean iForceCreate, final ORecordCallback<? extends Number> iRecordCreatedCallback, ORecordCallback<Integer> iRecordUpdatedCallback) {
try {
ORecord toRet = null;
ODirtyManager dirtyManager = ORecordInternal.getDirtyManager(iRecord);
Set<ORecord> newRecord = dirtyManager.getNewRecords();
Set<ORecord> updatedRecord = dirtyManager.getUpdateRecords();
dirtyManager.clearForSave();
if (newRecord != null) {
for (ORecord rec : newRecord) {
if (rec.getIdentity().isNew() && rec instanceof ODocument) {
ORecord ret = saveNew((ODocument) rec, dirtyManager, iClusterName, iRecord, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
if (ret != null)
toRet = ret;
}
}
}
if (updatedRecord != null) {
for (ORecord rec : updatedRecord) {
if (rec == iRecord) {
toRet = database.executeSaveRecord(rec, iClusterName, rec.getVersion(), iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
} else
database.executeSaveRecord(rec, getClusterName(rec), rec.getVersion(), OPERATION_MODE.SYNCHRONOUS, false, null, null);
}
}
if (toRet != null)
return toRet;
else
return database.executeSaveRecord(iRecord, iClusterName, iRecord.getVersion(), iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
} catch (Exception e) {
// REMOVE IT FROM THE CACHE TO AVOID DIRTY RECORDS
final ORecordId rid = (ORecordId) iRecord.getIdentity();
if (rid.isValid())
database.getLocalCache().freeRecord(rid);
if (e instanceof ONeedRetryException)
throw (ONeedRetryException) e;
throw OException.wrapException(new ODatabaseException("Error during saving of record" + (iRecord != null ? " with rid " + iRecord.getIdentity() : "")), e);
}
}
Aggregations