identitiesForTable.add(identity);
_identityMap.put(origIdentity, newIdentity);
    public void addBean(DynaBean bean) throws DataSinkException    {        Table table = _model.getDynaClassFor(bean).getTable();        if (_ensureFkOrder && (table.getForeignKeyCount() > 0))        {            WaitingObject waitingObj = new WaitingObject(bean);            for (int idx = 0; idx < table.getForeignKeyCount(); idx++)            {                ForeignKey fk         = table.getForeignKey(idx);                Identity   fkIdentity = buildIdentityFromFK(table, fk, bean);                if (fkIdentity != null)                {                    HashSet identitiesForTable = (HashSet)_processedIdentities.get(fk.getForeignTableName());                        if (!identitiesForTable.contains(fkIdentity))                    {                        waitingObj.addPendingFK(fkIdentity);                    }                }            }            if (waitingObj.hasPendingFKs())            {                if (_log.isDebugEnabled())                {                    StringBuffer msg = new StringBuffer();                    msg.append("Defering insertion of bean ");                    msg.append(buildIdentityFromPKs(table, bean).toString());                    msg.append(" because it is waiting for:");                    for (Iterator it = waitingObj.getPendingFKs(); it.hasNext();)                    {                        msg.append("\n  ");                        msg.append(it.next().toString());                    }                    _log.debug(msg.toString());                }                _waitingObjects.add(waitingObj);                return;            }        }        insertBeanIntoDatabase(table, bean);        if (_ensureFkOrder && _processedIdentities.containsKey(table.getName()))        {            Identity  identity           = buildIdentityFromPKs(table, bean);            HashSet   identitiesForTable = (HashSet)_processedIdentities.get(table.getName());            ArrayList finishedObjs       = new ArrayList();            identitiesForTable.add(identity);            for (Iterator waitingObjIt = _waitingObjects.iterator(); waitingObjIt.hasNext();)            {                WaitingObject waitingObj = (WaitingObject)waitingObjIt.next();                Identity      fkIdentity = waitingObj.removePendingFK(identity);                if (!waitingObj.hasPendingFKs())                {                    waitingObjIt.remove();                    // the object was only waiting for this one, so store it now                    // prior to that we also update the fk fields in case one of the pk                    // columns of the target object is auto-incremented by the database                    updateFKColumns(waitingObj.getObject(), bean, fkIdentity.getForeignKeyName());                    // we defer handling of the finished objects to avoid concurrent modification exceptions                    finishedObjs.add(waitingObj.getObject());                }            }            for (Iterator finishedObjIt = finishedObjs.iterator(); finishedObjIt.hasNext();)            {                DynaBean finishedObj = (DynaBean)finishedObjIt.next();                addBean(finishedObj);                if (_log.isDebugEnabled())                {                    Table waitingObjTable = ((SqlDynaClass)finishedObj.getDynaClass()).getTable();                    _log.debug("Inserted deferred bean "+buildIdentityFromPKs(waitingObjTable, finishedObj));                }            }        }    }