// delete /////////////////////////////////////////// protected internal override void deleteEntity(DbEntityOperation operation) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.camunda.bpm.engine.impl.db.DbEntity dbEntity = operation.getEntity(); DbEntity dbEntity = operation.Entity; // get statement string deleteStatement = dbSqlSessionFactory.getDeleteStatement(dbEntity.GetType()); ensureNotNull("no delete statement for " + dbEntity.GetType() + " in the ibatis mapping files", "deleteStatement", deleteStatement); LOG.executeDatabaseOperation("DELETE", dbEntity); // execute the delete int nrOfRowsDeleted = executeDelete(deleteStatement, dbEntity); operation.RowsAffected = nrOfRowsDeleted; // It only makes sense to check for optimistic locking exceptions for objects that actually have a revision if (dbEntity is HasDbRevision && nrOfRowsDeleted == 0) { operation.Failed = true; return; } // perform post delete action entityDeleted(dbEntity); }
public void failedOperation(DbOperation operation) { if (operation is DbEntityOperation) { DbEntityOperation dbEntityOperation = (DbEntityOperation)operation; DbEntity dbEntity = dbEntityOperation.Entity; bool failedOperationEntityInList = false; IEnumerator <LockedExternalTask> it = tasks.GetEnumerator(); while (it.MoveNext()) { LockedExternalTask resultTask = it.Current; if (resultTask.Id.Equals(dbEntity.Id)) { //JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only: it.remove(); failedOperationEntityInList = true; break; } } if (!failedOperationEntityInList) { throw LOG.concurrentUpdateDbEntityException(operation); } } }
protected internal virtual void performEntityOperation(CachedDbEntity cachedDbEntity, DbOperationType type) { DbEntityOperation dbOperation = new DbEntityOperation(); dbOperation.Entity = cachedDbEntity.Entity; dbOperation.FlushRelevantEntityReferences = cachedDbEntity.FlushRelevantEntityReferences; dbOperation.OperationType = type; dbOperationManager.addOperation(dbOperation); }
public virtual void failedOperation(DbOperation operation) { if (operation is DbEntityOperation) { DbEntityOperation entityOperation = (DbEntityOperation)operation; if (entityOperation.EntityType.IsAssignableFrom(typeof(JobEntity))) { // could not lock the job -> remove it from list of acquired jobs acquiredJobs.removeJobId(entityOperation.Entity.Id); } } }
// insert ////////////////////////////////////////// protected internal override void insertEntity(DbEntityOperation operation) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.camunda.bpm.engine.impl.db.DbEntity dbEntity = operation.getEntity(); DbEntity dbEntity = operation.Entity; // get statement string insertStatement = dbSqlSessionFactory.getInsertStatement(dbEntity); insertStatement = dbSqlSessionFactory.mapStatement(insertStatement); ensureNotNull("no insert statement for " + dbEntity.GetType() + " in the ibatis mapping files", "insertStatement", insertStatement); // execute the insert executeInsertEntity(insertStatement, dbEntity); // perform post insert actions on entity entityInserted(dbEntity); }
// update //////////////////////////////////////// protected internal override void updateEntity(DbEntityOperation operation) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.camunda.bpm.engine.impl.db.DbEntity dbEntity = operation.getEntity(); DbEntity dbEntity = operation.Entity; string updateStatement = dbSqlSessionFactory.getUpdateStatement(dbEntity); ensureNotNull("no update statement for " + dbEntity.GetType() + " in the ibatis mapping files", "updateStatement", updateStatement); LOG.executeDatabaseOperation("UPDATE", dbEntity); if (Context.ProcessEngineConfiguration.JdbcBatchProcessing) { // execute update executeUpdate(updateStatement, dbEntity); } else { // execute update int numOfRowsUpdated = executeUpdate(updateStatement, dbEntity); if (dbEntity is HasDbRevision) { if (numOfRowsUpdated != 1) { // failed with optimistic locking operation.Failed = true; return; } else { // increment revision of our copy HasDbRevision versionedObject = (HasDbRevision)dbEntity; versionedObject.Revision = versionedObject.RevisionNext; } } } // perform post update action entityUpdated(dbEntity); }
public virtual void Execute(IBaseDelegateExecution execution) { throw new NotImplementedException("C#与java之间db操作机制不一样,java在这里的逻辑会引发外键约束异常"); var existingId = execution.Id; // insert an execution referencing the current execution var newExecution = new ExecutionEntity(); newExecution.Id = "someId"; newExecution.SetParentId(existingId); var insertOperation = new DbEntityOperation(); insertOperation.OperationType = DbOperationType.Insert; insertOperation.Entity = newExecution; newExecution.Insert(); //Context.CommandContext.DbSqlSession.ExecuteDbOperation(insertOperation); }
protected internal abstract void UpdateEntity(DbEntityOperation operation);
protected internal abstract void InsertEntity(DbEntityOperation operation);
public virtual void Close(CommandInvocationContext commandInvocationContext) { // the intention of this method is that all resources are closed properly, // even // if exceptions occur in close or flush methods of the sessions or the // transaction context. //try //{ // try // { // try // { if (commandInvocationContext.Throwable == null) { FireCommandContextClose(); FlushSessions(); //清理缓存 Context.CommandContext.DbEntityCache.Clear(); } //} //catch (System.Exception exception) //{ // commandInvocationContext.TrySetThrowable(exception); //} //finally //{ //try //{ if (commandInvocationContext.Throwable == null) { FlushTransactions();//外部代码事务 try { transactionContext.Commit(); //系统数据库事务 } catch (DbUpdateConcurrencyException ex) { EntityEntry entry = ex.Entries.ElementAt(0); var dbOp = new DbEntityOperation(); dbOp.SetFailed(false); dbOp.EntityType = entry.Entity.GetType(); dbOp.Entity = entry.Entity as IDbEntity; HandleOptimisticLockingException(dbOp); } } //} //catch (System.Exception exception) //{ // commandInvocationContext.TrySetThrowable(exception); //} //if (commandInvocationContext.Throwable != null) //{ // // fire command failed (must not fail itself) // FireCommandFailed(commandInvocationContext.Throwable); // if (ShouldLogInfo(commandInvocationContext.Throwable)) // Log.InfoException(commandInvocationContext.Throwable); // else if (ShouldLogFine(commandInvocationContext.Throwable)) // Log.DebugException(commandInvocationContext.Throwable); // else // Log.ErrorException(commandInvocationContext.Throwable); // transactionContext.Rollback(); //} //} //} //catch (System.Exception exception) //{ // commandInvocationContext.TrySetThrowable(exception); //} //finally //{ CloseSessions(commandInvocationContext); //} //} //catch (System.Exception exception) //{ // commandInvocationContext.TrySetThrowable(exception); //} // rethrow the original exception if there was one //commandInvocationContext.Rethrow(); }