GetRelations() публичный статический Метод

public static GetRelations ( Type primaryType ) : ReadOnlyCollection
primaryType System.Type
Результат ReadOnlyCollection
Пример #1
0
 /// <summary>
 /// Inserts into the database all relation information. Dependent objects will be commited.
 /// </summary>
 /// <param name="dbObject">The primary object owning the RelationList to be populated.</param>
 /// <param name="forceRetrieval">Determines if ALL relations will be retrieved.</param>
 private void updateRelationTables(DatabaseTable dbObject)
 {
     foreach (DBRelation currRelation in DBRelation.GetRelations(dbObject.GetType()))
     {
         updateRelationTable(dbObject, currRelation);
     }
 }
Пример #2
0
        private void verifyRelationTables(Type primaryType)
        {
            foreach (DBRelation currRelation in DBRelation.GetRelations(primaryType))
            {
                try {
                    // check if the table exists in the database, if not, create it
                    SQLiteResultSet resultSet = dbClient.Execute("select * from sqlite_master where type='table' and name = '" + currRelation.TableName + "'");
                    if (resultSet.Rows.Count == 0)
                    {
                        // create table
                        string createQuery =
                            "create table " + currRelation.TableName + " (id INTEGER primary key, " +
                            currRelation.PrimaryColumnName + " INTEGER, " +
                            currRelation.SecondaryColumnName + " INTEGER)";

                        resultSet = dbClient.Execute(createQuery);

                        // create index1
                        resultSet = dbClient.Execute("create index " + currRelation.TableName + "__index1 on " +
                                                     currRelation.TableName + " (" + currRelation.PrimaryColumnName + ")");

                        // create index2
                        resultSet = dbClient.Execute("create index " + currRelation.TableName + "__index2 on " +
                                                     currRelation.TableName + " (" + currRelation.SecondaryColumnName + ")");

                        logger.Debug("Created " + currRelation.TableName + " sub-table.");
                    }
                }
                catch (SQLiteException e) {
                    logger.FatalException("Error verifying " + currRelation.TableName + " subtable.", e);
                }
            }
        }
Пример #3
0
        public void CommitRelations(DatabaseTable dbObject)
        {
            if (dbObject == null)
            {
                return;
            }

            foreach (DBRelation currRelation in DBRelation.GetRelations(dbObject.GetType()))
            {
                if (currRelation.AutoRetrieve)
                {
                    foreach (DatabaseTable subObj in currRelation.GetRelationList(dbObject))
                    {
                        Commit(subObj);
                    }

                    updateRelationTable(dbObject, currRelation);
                }
            }

            foreach (DBField currField in DBField.GetFieldList(dbObject.GetType()))
            {
                if (currField.DBType == DBField.DBDataType.DB_OBJECT)
                {
                    Commit((DatabaseTable)currField.GetValue(dbObject));
                }
            }
        }
Пример #4
0
 // deletes all subtable data for the given object.
 private void deleteAllRelationData(DatabaseTable dbObject)
 {
     foreach (DBRelation currRelation in DBRelation.GetRelations(dbObject.GetType()))
     {
         deleteRelationData(dbObject, currRelation);
     }
 }
Пример #5
0
        public void Revert(DatabaseTable dbObject)
        {
            if (dbObject == null || dbObject.RevertInProcess)
            {
                return;
            }

            dbObject.RevertInProcess = true;

            // recursively revert any child objects
            foreach (DBRelation currRelation in DBRelation.GetRelations(dbObject.GetType()))
            {
                foreach (DatabaseTable subObj in currRelation.GetRelationList(dbObject))
                {
                    Revert(subObj);
                }
            }

            // revert any objects directly linked to
            foreach (DBField currField in DBField.GetFieldList(dbObject.GetType()))
            {
                if (currField.DBType == DBField.DBDataType.DB_OBJECT)
                {
                    Commit((DatabaseTable)currField.GetValue(dbObject));
                }
            }

            // revert any modified relationships
            foreach (DBRelation currRelation in DBRelation.GetRelations(dbObject.GetType()))
            {
                if (currRelation.GetRelationList(dbObject).CommitNeeded)
                {
                    currRelation.GetRelationList(dbObject).Populated = false;
                    getRelationData(dbObject, currRelation);
                }
            }

            dbObject.RevertInProcess = false;

            // if this object has never been committed or has not been changed, just quit
            if (dbObject.ID == null || !dbObject.CommitNeeded)
            {
                return;
            }

            // regrab, copy values and reupdate cache
            cache.Remove(dbObject);
            DatabaseTable oldVersion = Get(dbObject.GetType(), (int)dbObject.ID);

            dbObject.Copy(oldVersion);
            cache.Replace(dbObject);
        }
Пример #6
0
        private void getAllRelationData(DatabaseTable dbObject)
        {
            if (preloading.Contains(dbObject.GetType()))
            {
                return;
            }

            foreach (DBRelation currRelation in DBRelation.GetRelations(dbObject.GetType()))
            {
                if (currRelation.AutoRetrieve)
                {
                    getRelationData(dbObject, currRelation);
                }
            }
        }