@Override public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Map<String, ?> args) { checkOpenness(); checkIfActive(); OLiveQueryListenerV2 queryListener = new LiveQueryListenerImpl(listener, query, this, (Map) args); ODatabaseDocumentInternal dbCopy = this.copy(); this.activateOnCurrentThread(); OLiveQueryMonitor monitor = new OLiveQueryMonitorEmbedded(queryListener.getToken(), dbCopy); return monitor; }
@Override public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Object... args) { checkOpenness(); checkIfActive(); OLiveQueryListenerV2 queryListener = new LiveQueryListenerImpl(listener, query, this, args); ODatabaseDocumentInternal dbCopy = this.copy(); this.activateOnCurrentThread(); OLiveQueryMonitor monitor = new OLiveQueryMonitorEmbedded(queryListener.getToken(), dbCopy); return monitor; }
@Override public OResultSet execute(String language, String script, Map<String, ?> args) { checkOpenness(); checkIfActive(); OScriptExecutor executor = OCommandManager.instance().getScriptExecutor(language); OResultSet original = executor.execute(this, script, args); OLocalResultSetLifecycleDecorator result = new OLocalResultSetLifecycleDecorator(original); this.queryStarted(result.getQueryId(), result); result.addLifecycleListener(this); return result; }
@Override public OResultSet execute(String language, String script, Object... args) { checkOpenness(); checkIfActive(); OScriptExecutor executor = OCommandManager.instance().getScriptExecutor(language); OResultSet original = executor.execute(this, script, args); OLocalResultSetLifecycleDecorator result = new OLocalResultSetLifecycleDecorator(original); this.queryStarted(result.getQueryId(), result); result.addLifecycleListener(this); return result; }
@Override public OResultSet query(String query, Object[] args) { checkOpenness(); checkIfActive(); OStatement statement = OSQLEngine.parse(query, this); if (!statement.isIdempotent()) { throw new OCommandExecutionException("Cannot execute query on non idempotent statement: " + query); } OResultSet original = statement.execute(this, args); OLocalResultSetLifecycleDecorator result = new OLocalResultSetLifecycleDecorator(original); this.queryStarted(result.getQueryId(), result); result.addLifecycleListener(this); return result; }
public OLocalResultSetLifecycleDecorator query(OExecutionPlan plan, Map<Object, Object> params) { checkOpenness(); checkIfActive(); OBasicCommandContext ctx = new OBasicCommandContext(); ctx.setDatabase(this); ctx.setInputParameters(params); OLocalResultSet result = new OLocalResultSet((OInternalExecutionPlan) plan); OLocalResultSetLifecycleDecorator decorator = new OLocalResultSetLifecycleDecorator(result); this.queryStarted(decorator.getQueryId(), decorator); decorator.addLifecycleListener(this); return decorator; }
@Override public OResultSet query(String query, Map args) { checkOpenness(); checkIfActive(); OStatement statement = OSQLEngine.parse(query, this); if (!statement.isIdempotent()) { throw new OCommandExecutionException("Cannot execute query on non idempotent statement: " + query); } OResultSet original = statement.execute(this, args); OLocalResultSetLifecycleDecorator result = new OLocalResultSetLifecycleDecorator(original); this.queryStarted(result.getQueryId(), result); result.addLifecycleListener(this); return result; }
/** * This method is internal, it can be subject to signature change or be removed, do not use. * * @Internal */ public <RET extends ORecord> RET executeSaveRecord(final ORecord record, String clusterName, final int ver, final OPERATION_MODE mode, boolean forceCreate, final ORecordCallback<? extends Number> recordCreatedCallback, ORecordCallback<Integer> recordUpdatedCallback) { checkOpenness(); checkIfActive(); if (!record.isDirty()) return (RET) record; final ORecordId rid = (ORecordId) record.getIdentity(); if (rid == null) throw new ODatabaseException( "Cannot create record because it has no identity. Probably is not a regular record or contains projections of fields rather than a full record"); final OMicroTransaction microTx = beginMicroTransaction(); try { microTx.saveRecord(record, clusterName, mode, forceCreate, recordCreatedCallback, recordUpdatedCallback); } catch (Exception e) { endMicroTransaction(false); throw e; } endMicroTransaction(true); return (RET) record; }
/** * This method is internal, it can be subject to signature change or be removed, do not use. * * @Internal */ public void executeDeleteRecord(OIdentifiable record, final int iVersion, final boolean iRequired, final OPERATION_MODE iMode, boolean prohibitTombstones) { checkOpenness(); checkIfActive(); final ORecordId rid = (ORecordId) record.getIdentity(); if (rid == null) throw new ODatabaseException( "Cannot delete record because it has no identity. Probably was created from scratch or contains projections of fields rather than a full record"); if (!rid.isValid()) return; record = record.getRecord(); if (record == null) return; final OMicroTransaction microTx = beginMicroTransaction(); try { microTx.deleteRecord(record.getRecord(), iMode); } catch (Exception e) { endMicroTransaction(false); throw e; } endMicroTransaction(true); return; }
@Override public OResultSet command(String query, Map args) { checkOpenness(); checkIfActive(); OStatement statement = OSQLEngine.parse(query, this); OResultSet original = statement.execute(this, args); OLocalResultSetLifecycleDecorator result; if (!statement.isIdempotent()) { //fetch all, close and detach OInternalResultSet prefetched = new OInternalResultSet(); original.forEachRemaining(x -> prefetched.add(x)); original.close(); result = new OLocalResultSetLifecycleDecorator(prefetched); } else { //stream, keep open and attach to the current DB result = new OLocalResultSetLifecycleDecorator(original); this.queryStarted(result.getQueryId(), result); result.addLifecycleListener(this); } return result; }
@Override public OResultSet command(String query, Object[] args) { checkOpenness(); checkIfActive(); OStatement statement = OSQLEngine.parse(query, this); OResultSet original = statement.execute(this, args); OLocalResultSetLifecycleDecorator result; if (!statement.isIdempotent()) { //fetch all, close and detach OInternalResultSet prefetched = new OInternalResultSet(); original.forEachRemaining(x -> prefetched.add(x)); original.close(); result = new OLocalResultSetLifecycleDecorator(prefetched); } else { //stream, keep open and attach to the current DB result = new OLocalResultSetLifecycleDecorator(original); this.queryStarted(result.getQueryId(), result); result.addLifecycleListener(this); } return result; }