use of org.camunda.bpm.engine.impl.db.DbEntity in project camunda-bpm-platform by camunda.
the class JobQueryTest method deleteJobInDatabase.
private void deleteJobInDatabase() {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
timerEntity.delete();
commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(timerEntity.getId());
List<HistoricIncident> historicIncidents = Context.getProcessEngineConfiguration().getHistoryService().createHistoricIncidentQuery().list();
for (HistoricIncident historicIncident : historicIncidents) {
commandContext.getDbEntityManager().delete((DbEntity) historicIncident);
}
return null;
}
});
}
use of org.camunda.bpm.engine.impl.db.DbEntity in project camunda-bpm-platform by camunda.
the class DbSqlSession method deleteEntity.
// delete ///////////////////////////////////////////
@Override
protected void deleteEntity(DbEntityOperation operation) {
final DbEntity dbEntity = operation.getEntity();
// get statement
String deleteStatement = dbSqlSessionFactory.getDeleteStatement(dbEntity.getClass());
ensureNotNull("no delete statement for " + dbEntity.getClass() + " in the ibatis mapping files", "deleteStatement", deleteStatement);
LOG.executeDatabaseOperation("DELETE", dbEntity);
// execute the delete
int nrOfRowsDeleted = executeDelete(deleteStatement, dbEntity);
// It only makes sense to check for optimistic locking exceptions for objects that actually have a revision
if (dbEntity instanceof HasDbRevision && nrOfRowsDeleted == 0) {
operation.setFailed(true);
return;
}
// perform post delete action
entityDeleted(dbEntity);
}
use of org.camunda.bpm.engine.impl.db.DbEntity in project camunda-bpm-platform by camunda.
the class DbSqlSession method updateEntity.
// update ////////////////////////////////////////
@Override
protected void updateEntity(DbEntityOperation operation) {
final DbEntity dbEntity = operation.getEntity();
String updateStatement = dbSqlSessionFactory.getUpdateStatement(dbEntity);
ensureNotNull("no update statement for " + dbEntity.getClass() + " in the ibatis mapping files", "updateStatement", updateStatement);
LOG.executeDatabaseOperation("UPDATE", dbEntity);
if (Context.getProcessEngineConfiguration().isJdbcBatchProcessing()) {
// execute update
executeUpdate(updateStatement, dbEntity);
} else {
// execute update
int numOfRowsUpdated = executeUpdate(updateStatement, dbEntity);
if (dbEntity instanceof HasDbRevision) {
if (numOfRowsUpdated != 1) {
// failed with optimistic locking
operation.setFailed(true);
return;
} else {
// increment revision of our copy
HasDbRevision versionedObject = (HasDbRevision) dbEntity;
versionedObject.setRevision(versionedObject.getRevisionNext());
}
}
}
// perform post update action
entityUpdated(dbEntity);
}
use of org.camunda.bpm.engine.impl.db.DbEntity in project camunda-bpm-platform by camunda.
the class DbOperationManager method sortByReferences.
/**
* Assumptions:
* a) all operations in the set work on entities such that the entities implement {@link HasDbReferences}.
* b) all operations in the set work on the same type (ie. all operations are INSERTs or DELETEs).
*/
protected List<DbEntityOperation> sortByReferences(SortedSet<DbEntityOperation> preSorted) {
// copy the pre-sorted set and apply final sorting to list
List<DbEntityOperation> opList = new ArrayList<DbEntityOperation>(preSorted);
for (int i = 0; i < opList.size(); i++) {
DbEntityOperation currentOperation = opList.get(i);
DbEntity currentEntity = currentOperation.getEntity();
Set<String> currentReferences = currentOperation.getFlushRelevantEntityReferences();
// check whether this operation must be placed after another operation
int moveTo = i;
for (int k = i + 1; k < opList.size(); k++) {
DbEntityOperation otherOperation = opList.get(k);
DbEntity otherEntity = otherOperation.getEntity();
Set<String> otherReferences = otherOperation.getFlushRelevantEntityReferences();
if (currentOperation.getOperationType() == INSERT) {
// if we reference the other entity, we need to be inserted after that entity
if (currentReferences != null && currentReferences.contains(otherEntity.getId())) {
moveTo = k;
// we can only reference a single entity
break;
}
} else {
// if the other entity has a reference to us, we must be placed after the other entity
if (otherReferences != null && otherReferences.contains(currentEntity.getId())) {
moveTo = k;
// cannot break, there may be another entity further to the right which also references us
}
}
}
if (moveTo > i) {
opList.remove(i);
opList.add(moveTo, currentOperation);
i--;
}
}
return opList;
}
use of org.camunda.bpm.engine.impl.db.DbEntity in project camunda-bpm-platform by camunda.
the class DbEntityManager method selectOne.
public Object selectOne(String statement, Object parameter) {
Object result = persistenceSession.selectOne(statement, parameter);
if (result instanceof DbEntity) {
DbEntity loadedObject = (DbEntity) result;
result = cacheFilter(loadedObject);
}
return result;
}
Aggregations