List<DbEntityOperation> opList = new ArrayList<DbEntityOperation>(preSorted);
for (int i = 0; i < opList.size(); i++) {
DbEntityOperation currentOperation = opList.get(i);
DbEntity currentEntity = currentOperation.getEntity();
// 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();
if(currentOperation.getOperationType() == INSERT) {
// if we reference the other entity, we need to be inserted after that entity
if(((HasDbReferences) currentEntity).hasReferenceTo(otherEntity)) {
moveTo = k;