GetRelationList() public method

public GetRelationList ( DatabaseTable dbObject ) : IRelationList
dbObject Cornerstone.Database.Tables.DatabaseTable
return IRelationList
Esempio n. 1
0
        private void updateRelationTable(DatabaseTable dbObject, DBRelation currRelation)
        {
            if (!currRelation.GetRelationList(dbObject).CommitNeeded)
            {
                return;
            }

            // clear out old values then insert the new
            deleteRelationData(dbObject, currRelation);

            // insert all relations to the database
            foreach (object currObj in (IList)currRelation.GetRelationList(dbObject))
            {
                DatabaseTable currDBObj = (DatabaseTable)currObj;
                Commit(currDBObj);
                string insertQuery = "insert into " + currRelation.TableName + "(" +
                                     currRelation.PrimaryColumnName + ", " +
                                     currRelation.SecondaryColumnName + ") values (" +
                                     dbObject.ID + ", " + currDBObj.ID + ")";

                lock (lockObject) dbClient.Execute(insertQuery);
            }

            currRelation.GetRelationList(dbObject).CommitNeeded = false;
        }
Esempio n. 2
0
        public HashSet <string> GetAllValues <T>(DBField field, DBRelation relation, ICollection <T> items) where T : DatabaseTable
        {
            // loop through all items in the DB and grab all existing values for this field
            HashSet <string> uniqueStrings = new HashSet <string>(StringComparer.CurrentCultureIgnoreCase);

            foreach (T currItem in items)
            {
                if (relation == null)
                {
                    List <string> values = getValues(field.GetValue(currItem));
                    foreach (string currStr in values)
                    {
                        uniqueStrings.Add(currStr);
                    }
                }
                else
                {
                    foreach (DatabaseTable currSubItem in relation.GetRelationList(currItem))
                    {
                        List <string> values = getValues(field.GetValue(currSubItem));
                        foreach (string currStr in values)
                        {
                            uniqueStrings.Add(currStr);
                        }
                    }
                }
            }

            return(uniqueStrings);
        }
Esempio n. 3
0
        private void getRelationData(DatabaseTable dbObject, DBRelation relation)
        {
            IRelationList list = relation.GetRelationList(dbObject);

            if (list.Populated)
            {
                return;
            }

            bool oldCommitNeededFlag = dbObject.CommitNeeded;

            list.Populated = true;

            // build query
            string selectQuery = "select " + relation.SecondaryColumnName + " from " +
                                 relation.TableName + " where " + relation.PrimaryColumnName + "=" + dbObject.ID;

            // and retireve relations
            SQLiteResultSet resultSet;

            lock (lockObject) resultSet = dbClient.Execute(selectQuery);

            // parse results and add them to the list
            list.Clear();
            foreach (SQLiteResultSet.Row currRow in resultSet.Rows)
            {
                int           objID  = int.Parse(currRow.fields[0]);
                DatabaseTable newObj = Get(relation.SecondaryType, objID);
                list.AddIgnoreSisterList(newObj);
            }

            // update flags as needed
            list.CommitNeeded     = false;
            dbObject.CommitNeeded = oldCommitNeededFlag;
        }