in reply to Avoiding too many DB queries
In regard to your update question of re-querying for the newly created ids, if the id fields are auto_increment, which i think they must be by the context of your question, use the query 'SELECT LAST_INSERT_ID()'
Its still querying the DB, but it has almost no overhead, beacuse MySQL stores the most recently created auto_increment value for each connection. So after you do each insert, just do that query, instead of whatever your getRID(), get AID(), etc methods do.