/** * Commits the micro-transaction if it's a top-level micro-transaction. */ public void commit() { if (!active) throw error("Inactive micro-transaction on commit"); if (level < 1) throw error("Unbalanced micro-transaction, level = " + level); --level; if (level == 0) { active = false; doCommit(); } }
/** * Rollbacks the micro-transaction after failed commit attempt. */ public void rollbackAfterFailedCommit() { if (active) throw error("Active micro-transaction on rollback after failed commit"); if (level != 0) throw error("Unbalanced micro-transaction, level = " + level); doRollback(); }
private void doCommit() { if (!recordOperations.isEmpty() || !indexOperations.isEmpty()) getDatabase().internalCommit(this); invokeCallbacks(); reset(); }
final OIndexManager indexManager = getDatabase().getMetadata().getIndexManager(); for (Map.Entry<String, OTransactionIndexChanges> entry : indexOperations.entrySet()) { final OIndex<?> index = indexManager.getIndex(entry.getKey()); throw new OTransactionException("Cannot find index '" + entry.getValue() + "' while committing transaction"); final Dependency[] fieldRidDependencies = getIndexFieldRidDependencies(index); if (!isIndexMayDependOnRids(fieldRidDependencies)) continue; .hasNext(); ) { final OTransactionIndexChangesPerKey keyChanges = iterator.next(); if (isIndexKeyMayDependOnRid(keyChanges.key, oldRid, fieldRidDependencies)) { keyRecordsToReinsert.add(new KeyChangesUpdateRecord(keyChanges, indexChanges)); iterator.remove(); final ORecordOperation rec = resolveRecordOperation(oldRid); if (rec != null) { updatedRids.put(newRid.copy(), oldRid.copy()); final List<OTransactionRecordIndexOperation> transactionIndexOperations = recordIndexOperations.get(translateRid(oldRid)); if (transactionIndexOperations != null) { for (final OTransactionRecordIndexOperation indexOperation : transactionIndexOperations) { updateChangesIdentity(oldRid, newRid, keyChanges);
private void endMicroTransaction(boolean success) { assert microTransaction != null; try { if (success) try { microTransaction.commit(); OLiveQueryHook.notifyForTxChanges(this); OLiveQueryHookV2.notifyForTxChanges(this); } catch (Exception e) { microTransaction.rollbackAfterFailedCommit(); OLiveQueryHook.removePendingDatabaseOps(this); OLiveQueryHookV2.removePendingDatabaseOps(this); throw e; } else { microTransaction.rollback(); OLiveQueryHook.removePendingDatabaseOps(this); OLiveQueryHookV2.removePendingDatabaseOps(this); } } finally { if (!microTransaction.isActive()) microTransaction = null; } }
protected OMicroTransaction beginMicroTransaction() { final OAbstractPaginatedStorage abstractPaginatedStorage = (OAbstractPaginatedStorage) getStorage().getUnderlying(); if (microTransaction == null) microTransaction = new OMicroTransaction(abstractPaginatedStorage, this); microTransaction.begin(); return microTransaction; }
@Override public ORecord saveRecord(ORecord record, String clusterName, ODatabase.OPERATION_MODE operationMode, boolean forceCreation, ORecordCallback<? extends Number> createdCallback, ORecordCallback<Integer> updatedCallback) { if (!active) throw error("Inactive micro-transaction on record save"); if (record == null) return null; if (!record.isDirty()) return record; final ORecordOperation recordOperation; if (forceCreation || !record.getIdentity().isValid()) recordOperation = addRecordOperation(record, ORecordOperation.CREATED, clusterName); else recordOperation = addRecordOperation(record, ORecordOperation.UPDATED, clusterName); if (recordOperation != null) { if (createdCallback != null) //noinspection unchecked recordOperation.createdCallback = (ORecordCallback<Long>) createdCallback; if (updatedCallback != null) recordOperation.updatedCallback = updatedCallback; } return record; }
if (transaction.get().getMicroTransaction().getId() != microTransaction.getId()) { throw new OStorageException( "Passed in and active micro-transaction are different micro-transactions. Passed in micro-transaction cannot be " rollbackStorageTx(); microTransaction.updateRecordCacheAfterRollback();
/** * Begins the micro-transaction. Micro-transactions may be nested. */ public void begin() { if (level < 0) throw error("Unbalanced micro-transaction, level = " + level); ++level; active = true; }
@Override public void deleteRecord(ORecord record, ODatabase.OPERATION_MODE mode) { if (!record.getIdentity().isValid()) return; addRecordOperation(record, ORecordOperation.DELETED, null); }
/** * 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; }
/** * Rollbacks the micro-transaction if it's a top-level micro-transaction. */ public void rollback() { if (!active) throw error("Inactive micro-transaction on rollback"); if (level < 1) throw error("Unbalanced micro-transaction, level = " + level); --level; if (level == 0) { active = false; doRollback(); } }