}
@Override
public void executeBatch(OperationsQueue queue) {
if ( !queue.isClosed() ) {
Operation operation = queue.poll();
Map<DBCollection, Map<DBObject, DBObject>> inserts = new HashMap<DBCollection, Map<DBObject, DBObject>>();
while ( operation != null ) {
if ( operation instanceof UpdateTupleOperation ) {
UpdateTupleOperation update = (UpdateTupleOperation) operation;
executeBatchUpdate( inserts, update );
}
else if ( operation instanceof RemoveTupleOperation ) {
RemoveTupleOperation tupleOp = (RemoveTupleOperation) operation;
executeBatchRemove( inserts, tupleOp );
}
else if ( operation instanceof UpdateAssociationOperation ) {
UpdateAssociationOperation update = (UpdateAssociationOperation) operation;
updateAssociation( update.getAssociation(), update.getAssociationKey(), update.getContext() );
}
else if ( operation instanceof RemoveAssociationOperation ) {
RemoveAssociationOperation remove = (RemoveAssociationOperation) operation;
removeAssociation( remove.getAssociationKey(), remove.getContext() );
}
else {
throw new UnsupportedOperationException( "Operation not supported on MongoDB: " + operation.getClass().getName() );
}
operation = queue.poll();
}
flushInserts( inserts );
queue.close();