HashMap positionToAction = new HashMap();
List nameList = new ArrayList();
loopInsertion: while( !insertions.isEmpty() ) {
EntityInsertAction action = ( EntityInsertAction ) insertions.remove( 0 );
String thisEntityName = action.getEntityName();
// see if we have already encountered this entity-name...
if ( ! nameList.contains( thisEntityName ) ) {
// we have not, so create the proper entries in nameList and positionToAction
ArrayList segmentedActionQueue = new ArrayList();
segmentedActionQueue.add( action );
nameList.add( thisEntityName );
positionToAction.put( new Integer( nameList.indexOf( thisEntityName ) ), segmentedActionQueue );
}
else {
// we have seen it before, so we need to determine if this insert action is
// is depenedent upon a previously processed action in terms of FK
// relationships (this FK checking is done against the entity's property-state
// associated with the action...)
int lastPos = nameList.lastIndexOf( thisEntityName );
Object[] states = action.getState();
for ( int i = 0; i < states.length; i++ ) {
for ( int j = 0; j < nameList.size(); j++ ) {
ArrayList tmpList = ( ArrayList ) positionToAction.get( new Integer( j ) );
for ( int k = 0; k < tmpList.size(); k++ ) {
final EntityInsertAction checkAction = ( EntityInsertAction ) tmpList.get( k );
if ( checkAction.getInstance() == states[i] && j > lastPos ) {
// 'checkAction' is inserting an entity upon which 'action'
// depends...
// note: this is an assumption and may not be correct in the case of one-to-one
ArrayList segmentedActionQueue = new ArrayList();
segmentedActionQueue.add( action );