public void updateOperation(final ODatabase database, final OIdentifiable rec) { ODatabaseDocumentAbstract.executeWithRetries(new OCallable<Object, Integer>() { @Override public Object call(Integer iArgument) { final ODocument doc = rec.getRecord(); doc.field("updated", true); doc.save(); return doc; } }, 10); }
/** * Use #activateOnCurrentThread instead. */ @Deprecated public void setCurrentDatabaseInThreadLocal() { activateOnCurrentThread(); }
@Override public OEdge newEdge(OVertex from, OVertex to, String type) { OClass cl = getClass(type); if (cl == null || !cl.isEdgeType()) { throw new IllegalArgumentException("" + type + " is not an edge class"); } return addEdgeInternal(from, to, type, false); }
final String fetchPlan, final boolean ignoreCache, final boolean iUpdateCache, final boolean loadTombstones, final OStorage.LOCKING_STRATEGY lockingStrategy, RecordReader recordReader) { checkOpenness(); checkIfActive(); getMetadata().makeThreadLocalSchemaSnapshot(); ORecordSerializationContext.pushContext(); try { checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_READ, getClusterNameById(rid.getClusterId())); assert !(getTransaction().isActive() && (microTransaction != null && microTransaction.isActive())); ORecord record = getTransaction().getRecord(rid); if (record == OBasicTransaction.DELETED_RECORD) record = getLocalCache().findRecord(rid); if (beforeReadOperations(record)) return null; afterReadOperations(record); if (record instanceof ODocument) ODocumentInternal.checkClass((ODocument) record, this); recordBuffer = recordReader.readRecord(getStorage(), rid, fetchPlan, ignoreCache, version); if (beforeReadOperations(iRecord)) return null;
@Override public ODatabaseDocument commit(boolean force) throws OTransactionException { checkOpenness(); checkIfActive(); beforeCommitOperations(); } catch (OException e) { try { rollback(force); } catch (Exception re) { OLogManager.instance().error(this, "Exception during rollback `%08X`", re, System.identityHashCode(re)); beforeRollbackOperations(); getLocalCache().clear(); afterRollbackOperations(); throw e; afterCommitOperations();
public <RET extends ORecord> RET executeSaveEmptyRecord(ORecord record, String clusterName) { ORecordId rid = (ORecordId) record.getIdentity(); assert rid.isNew(); ORecordInternal.onBeforeIdentityChanged(record); int id = assignAndCheckCluster(record, clusterName); clusterName = getClusterNameById(id); checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_CREATE, clusterName); byte[] content = getSerializer().writeClassOnly(record); final OStorageOperationResult<OPhysicalPosition> ppos = getStorage() .createRecord(rid, content, record.getVersion(), recordType, OPERATION_MODE.SYNCHRONOUS.ordinal(), null); ORecordInternal.setVersion(record, ppos.getResult().recordVersion); ((ORecordId) record.getIdentity()).copyFrom(rid); ORecordInternal.onAfterIdentityChanged(record); return (RET) record; }
@Override public ODatabaseDocument rollback(boolean force) throws OTransactionException { checkOpenness(); if (currentTx.isActive()) { if (!force && currentTx.amountOfNestedTxs() > 1) { //This just decrement the counter no real rollback here currentTx.rollback(); return this; } // WAKE UP LISTENERS beforeRollbackOperations(); currentTx.rollback(force, -1); // WAKE UP LISTENERS afterRollbackOperations(); } getLocalCache().clear(); return this; }
public void callOnDropListeners() { // WAKE UP LISTENERS for (ODatabaseListener listener : getListenersCopy()) try { activateOnCurrentThread(); listener.onDelete(getDatabaseOwner()); } catch (Exception e) { OLogManager.instance().error(this, "Error during call of database listener", e); } }
private <RET extends ORecord> RET saveInternal(ORecord iRecord, String iClusterName, OPERATION_MODE iMode, boolean iForceCreate, ORecordCallback<? extends Number> iRecordCreatedCallback, ORecordCallback<Integer> iRecordUpdatedCallback) { if (!(iRecord instanceof ODocument)) { assignAndCheckCluster(iRecord, iClusterName); return (RET) currentTx.saveRecord(iRecord, iClusterName, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback); } ODocument doc = (ODocument) iRecord; ODocumentInternal.checkClass(doc, this); // IN TX THE VALIDATION MAY BE RUN TWICE BUT IS CORRECT BECAUSE OF DIFFERENT RECORD STATUS try { doc.validate(); } catch (OValidationException e) { doc.undo(); throw e; } ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc); if (iForceCreate || !doc.getIdentity().isValid()) { if (doc.getClassName() != null) checkSecurity(ORule.ResourceGeneric.CLASS, ORole.PERMISSION_CREATE, doc.getClassName()); assignAndCheckCluster(doc, iClusterName); } else { // UPDATE: CHECK ACCESS ON SCHEMA CLASS NAME (IF ANY) if (doc.getClassName() != null) checkSecurity(ORule.ResourceGeneric.CLASS, ORole.PERMISSION_UPDATE, doc.getClassName()); } doc = (ODocument) currentTx .saveRecord(iRecord, iClusterName, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback); return (RET) doc; }
public void reloadUser() { if (user != null) { activateOnCurrentThread(); if (user.checkIfAllowed(ORule.ResourceGeneric.CLASS, OUser.CLASS_NAME, ORole.PERMISSION_READ) != null) { OMetadata metadata = getMetadata(); if (metadata != null) { final OSecurity security = metadata.getSecurity(); OUser secGetUser = security.getUser(user.getName()); if (secGetUser != null) user = new OImmutableUser(security.getVersion(), secGetUser); else user = new OImmutableUser(-1, new OUser()); } else user = new OImmutableUser(-1, new OUser()); } } }
@Override protected void afterRollbackOperations() { super.afterRollbackOperations(); OLiveQueryHook.removePendingDatabaseOps(this); OLiveQueryHookV2.removePendingDatabaseOps(this); } }
@Override protected void afterCommitOperations() { super.afterCommitOperations(); OLiveQueryHook.notifyForTxChanges(this); OLiveQueryHookV2.notifyForTxChanges(this); }
public void deleteOperation(final ODatabase database, final OIdentifiable rec) { ODatabaseDocumentAbstract.executeWithRetries(new OCallable<Object, Integer>() { @Override public Object call(Integer iArgument) { database.delete(rec.getIdentity()); return null; } }, 10); }
public OEdge newRegularEdge(String iClassName, OVertex from, OVertex to) { OClass cl = getClass(iClassName); if (cl == null || !cl.isEdgeType()) { throw new IllegalArgumentException("" + iClassName + " is not an edge class"); } return addEdgeInternal(from, to, iClassName, true); }
public static Object executeWithRetries(final OCallable<Object, Integer> callback, final int maxRetry) { return executeWithRetries(callback, maxRetry, 0, null); }
public static Object executeWithRetries(final OCallable<Object, Integer> callback, final int maxRetry, final int waitBetweenRetry) { return executeWithRetries(callback, maxRetry, waitBetweenRetry, null); }
public ODocument createOperation(final long n) { return (ODocument) ODatabaseDocumentAbstract.executeWithRetries(new OCallable<Object, Integer>() { @Override public Object call(Integer iArgument) { ODocument doc = new ODocument(CLASS_NAME); doc.field("name", "value" + n); doc.save(); return doc; } }, 10); }
ODatabaseDocumentAbstract.executeWithRetries(new OCallable<Object, Integer>() { @Override public Object call(final Integer retry) {
public void removeEvent(final String eventName) { OLogManager.instance().debug(this, "Removing scheduled event '%s'...", eventName); final OScheduledEvent event = removeEventInternal(eventName); if (event != null) { try { event.getDocument().reload(); } catch (ORecordNotFoundException ignore) { // ALREADY DELETED, JUST RETURN return; } // RECORD EXISTS: DELETE THE EVENT RECORD ODatabaseDocumentAbstract.executeWithRetries(new OCallable<Object, Integer>() { @Override public Object call(Integer iArgument) { OLogManager.instance().debug(this, "Deleting scheduled event '%s' rid=%s...", event, event.getDocument().getIdentity()); event.getDocument().delete(); return null; } }, 10, 0, new ORecord[] { event.getDocument() }); } }