public void resolve(DatabaseContents db, string tableName, Row row)
        {
            Key index = createValueOfKey(row);

            if (index != null)
            {
                TableContents referencedTable = db.GetTable(referencedTableName);
                try
                {
                    Row referencedRow = referencedTable.GetRow(index);

                    string referenceName = getReferenceName();
                    if (referenceName != null)
                    {
                        row.addRef(referenceName, referencedRow);
                    }

                    string reverseReferenceName = getReverseReferenceName();
                    if (reverseReferenceName != null)
                    {
                        referencedRow.addReverseRef(reverseReferenceName, row);
                    }
                }
                catch (KeyNotFoundException e)
                {
                    Global.Log.Append("warn",
                                      "could not resolve reference " + this.ToString(), e);
                }
            }
        }
        /// <summary>
        /// Gets a table or creates it.
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public TableContents GetTable(string tableName)
        {
            TableContents table;
            bool          exists = tables.TryGetValue(tableName, out table);

            if (!exists)
            {
                table             = new TableContents(DatabaseDefinition.getTableDefinition(tableName));
                tables[tableName] = table;
            }

            return(table);
        }
        public void ResolveReferences()
        {
            foreach (KeyValuePair <string, TableContents> kv in tables)
            {
                string        tableName = kv.Key;
                TableContents table     = kv.Value;

                foreach (Row row in table.GetRows())
                {
                    foreach (ForeignKey reference in DatabaseDefinition.getTableDefinition(tableName).ForeignKeys)
                    {
                        reference.resolve(this, tableName, row);
                    }
                }
            }
        }