use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OCommandExecutorScript method executeJsr223Script.
protected Object executeJsr223Script(final String language, final OCommandContext iContext, final Map<Object, Object> iArgs) {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
final OScriptManager scriptManager = Orient.instance().getScriptManager();
CompiledScript compiledScript = request.getCompiledScript();
final OPartitionedObjectPool.PoolEntry<ScriptEngine> entry = scriptManager.acquireDatabaseEngine(db.getName(), language);
final ScriptEngine scriptEngine = entry.object;
try {
if (compiledScript == null) {
if (!(scriptEngine instanceof Compilable))
throw new OCommandExecutionException("Language '" + language + "' does not support compilation");
final Compilable c = (Compilable) scriptEngine;
try {
compiledScript = c.compile(parserText);
} catch (ScriptException e) {
scriptManager.throwErrorMessage(e, parserText);
}
request.setCompiledScript(compiledScript);
}
final Bindings binding = scriptManager.bind(compiledScript.getEngine().getBindings(ScriptContext.ENGINE_SCOPE), (ODatabaseDocumentTx) db, iContext, iArgs);
try {
final Object ob = compiledScript.eval(binding);
return OCommandExecutorUtility.transformResult(ob);
} catch (ScriptException e) {
throw OException.wrapException(new OCommandScriptException("Error on execution of the script", request.getText(), e.getColumnNumber()), e);
} finally {
scriptManager.unbind(binding, iContext, iArgs);
}
} finally {
scriptManager.releaseDatabaseEngine(language, db.getName(), entry);
}
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OContentRecordConflictStrategy method onUpdate.
@Override
public byte[] onUpdate(OStorage storage, final byte iRecordType, final ORecordId rid, final int iRecordVersion, final byte[] iRecordContent, final AtomicInteger iDatabaseVersion) {
final boolean hasSameContent;
if (iRecordType == ODocument.RECORD_TYPE) {
// No need lock, is already inside a lock.
OStorageOperationResult<ORawBuffer> res = storage.readRecord(rid, null, false, false, null);
final ODocument storedRecord = new ODocument(rid).fromStream(res.getResult().getBuffer());
final ODocument newRecord = new ODocument().fromStream(iRecordContent);
final ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.INSTANCE.get();
hasSameContent = ODocumentHelper.hasSameContentOf(storedRecord, currentDb, newRecord, currentDb, null, false);
} else {
// CHECK BYTE PER BYTE
final ORecordAbstract storedRecord = rid.getRecord();
hasSameContent = Arrays.equals(storedRecord.toStream(), iRecordContent);
}
if (hasSameContent)
// OK
iDatabaseVersion.set(Math.max(iDatabaseVersion.get(), iRecordVersion));
else
// NO DOCUMENT, CANNOT MERGE SO RELY TO THE VERSION CHECK
checkVersions(rid, iRecordVersion, iDatabaseVersion.get());
return null;
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OGraphCommandExecutorSQLFactory method runInTx.
public static <T> T runInTx(final GraphCallBack<T> callBack) {
final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
final ODatabaseDocumentInternal curDb = ODatabaseRecordThreadLocal.INSTANCE.get();
final boolean txAlreadyBegun = curDb.getTransaction().isActive();
final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownFlag);
try {
return runInTx(graph, callBack);
} finally {
if (!txAlreadyBegun) {
graph.commit();
if (shutdownFlag.getValue())
graph.shutdown(false, false);
}
ODatabaseRecordThreadLocal.INSTANCE.set(curDb);
}
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OGraphCommandExecutorSQLFactory method runInConfiguredTxMode.
public static <T> T runInConfiguredTxMode(final GraphCallBack<T> callBack) {
final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
final ODatabaseDocumentInternal curDb = ODatabaseRecordThreadLocal.INSTANCE.get();
final boolean txAlreadyBegun = curDb.getTransaction().isActive();
OrientBaseGraph graph = null;
try {
if (isTxRequiredForSQLGraphOperations()) {
graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownFlag);
return runInTx((OrientGraph) graph, callBack);
} else {
graph = getAnyGraph(shutdownFlag);
return callBack.call(graph);
}
} finally {
if (graph != null) {
if (!txAlreadyBegun) {
graph.commit();
if (shutdownFlag.getValue())
graph.shutdown(false, false);
}
}
ODatabaseRecordThreadLocal.INSTANCE.set(curDb);
}
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OGraphCommandExecutorSQLFactory method runWithAnyGraph.
public static <T> T runWithAnyGraph(final GraphCallBack<T> callBack) {
final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
final ODatabaseDocumentInternal curDb = ODatabaseRecordThreadLocal.INSTANCE.get();
final OrientBaseGraph graph = OGraphCommandExecutorSQLFactory.getAnyGraph(shutdownFlag);
try {
return callBack.call(graph);
} finally {
if (shutdownFlag.getValue())
graph.shutdown(false, false);
ODatabaseRecordThreadLocal.INSTANCE.set(curDb);
}
}
Aggregations