Ejemplo n.º 1
0
        List <T> GetKeyValuePairs <T>(IDataHolder obj, Func <TableDefinition, T> listCreator)
            where T : KeyValueListBase
        {
            var dataHolderDef = m_mapping.GetDataHolderDefinition(obj.GetType());
            var lists         = new List <T>(m_mapping.TableDefinitions.Length);

            for (var i = 0; i < m_mapping.TableDefinitions.Length; i++)
            {
                var table = m_mapping.TableDefinitions[i];
                for (var j = 0; j < table.ColumnDefinitions.Length; j++)
                {
                    var col = table.ColumnDefinitions[j];
                    for (var k = 0; k < col.FieldList.Count; k++)
                    {
                        var field = col.FieldList[k];
                        var def   = field.DataHolderDefinition;
                        if (def == dataHolderDef)
                        {
                            var list = lists.FirstOrDefault(l => l.TableName == table.Name);
                            if (list == null)
                            {
                                lists.Add(list = listCreator(table));
                            }

                            var value = field.Get(obj);
                            list.AddPair(col.ColumnName, value.ToString());
                        }
                    }
                }
            }
            return(lists);
        }
Ejemplo n.º 2
0
        private List <KeyValueListBase> GetWherePairs(IDataHolder obj)
        {
            var type  = obj.GetType();
            var lists = new List <KeyValueListBase>(3);

            for (var i = 0; i < m_mapping.TableDefinitions.Length; i++)
            {
                var table = m_mapping.TableDefinitions[i];
                if (table.DataHolderDefinitions.Contains(def => def.Type == type))
                {
                    lists.Add(new KeyValueListBase(table, GetWherePairs(table, obj)));
                }
            }
            return(lists);
        }
Ejemplo n.º 3
0
        private List <KeyValueListBase> GetWherePairs(IDataHolder obj)
        {
            Type type = obj.GetType();
            List <KeyValueListBase> keyValueListBaseList = new List <KeyValueListBase>(3);

            for (int index = 0; index < this.m_mapping.TableDefinitions.Length; ++index)
            {
                TableDefinition tableDefinition = this.m_mapping.TableDefinitions[index];
                if (((IEnumerable <DataHolderDefinition>)tableDefinition.DataHolderDefinitions)
                    .Contains <DataHolderDefinition>((Func <DataHolderDefinition, bool>)(def => def.Type == type)))
                {
                    keyValueListBaseList.Add(new KeyValueListBase(tableDefinition,
                                                                  this.GetWherePairs(tableDefinition, obj)));
                }
            }

            return(keyValueListBaseList);
        }
Ejemplo n.º 4
0
        private List <KeyValueListBase> GetWherePairs(IDataHolder obj)
        {
            Type type = obj.GetType();
            List <KeyValueListBase> keyValueListBaseList = new List <KeyValueListBase>(3);

            for (int index = 0; index < m_mapping.TableDefinitions.Length; ++index)
            {
                TableDefinition tableDefinition = m_mapping.TableDefinitions[index];
                if (tableDefinition.DataHolderDefinitions
                    .Contains(def => def.Type == type))
                {
                    keyValueListBaseList.Add(new KeyValueListBase(tableDefinition,
                                                                  GetWherePairs(tableDefinition, obj)));
                }
            }

            return(keyValueListBaseList);
        }
Ejemplo n.º 5
0
        private List <KeyValuePair <string, object> > GetWherePairs(TableDefinition table, IDataHolder obj)
        {
            var dataHolderDef = m_mapping.GetDataHolderDefinition(obj.GetType());
            var pairs         = new List <KeyValuePair <string, object> >(2);

            foreach (var col in table.PrimaryColumns)
            {
                foreach (var field in col.DataColumn.FieldList)
                {
                    var def = field.DataHolderDefinition;
                    if (def == dataHolderDef)
                    {
                        var value = field.Get(obj);
                        pairs.Add(new KeyValuePair <string, object>(col.Name, value.ToString()));
                    }
                }
            }
            return(pairs);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Deletes the Object from the underlying Database.
 /// FlushCommit() needs to be called to persist the operation.
 /// </summary>
 public static void CommitDeleteAndFlush(this IDataHolder obj)
 {
     obj.CommitDelete();
     ContentMgr.FlushCommit(obj.GetType());
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Deletes the Object from the underlying Database.
 /// FlushCommit() needs to be called to persist the operation.
 /// </summary>
 public static void CommitDelete(this IDataHolder obj)
 {
     ContentMgr.GetMapper(obj.GetType()).Delete(obj);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Inserts the Object into the underlying Database.
 /// FlushCommit() needs to be called to persist the operation.
 /// </summary>
 public static void CommitInsert(this IDataHolder obj)
 {
     ContentMgr.GetMapper(obj.GetType()).Insert(obj);
 }
Ejemplo n.º 9
0
        private List <KeyValuePair <string, object> > GetWherePairs(TableDefinition table, IDataHolder obj)
        {
            DataHolderDefinition holderDefinition = this.m_mapping.GetDataHolderDefinition(obj.GetType());
            List <KeyValuePair <string, object> > keyValuePairList = new List <KeyValuePair <string, object> >(2);

            foreach (PrimaryColumn primaryColumn in table.PrimaryColumns)
            {
                foreach (IFlatDataFieldAccessor field in primaryColumn.DataColumn.FieldList)
                {
                    if (field.DataHolderDefinition == holderDefinition)
                    {
                        object obj1 = field.Get(obj);
                        if (obj1 != null)
                        {
                            keyValuePairList.Add(
                                new KeyValuePair <string, object>(primaryColumn.Name, (object)obj1.ToString()));
                        }
                    }
                }
            }

            return(keyValuePairList);
        }
Ejemplo n.º 10
0
        private List <T> GetKeyValuePairs <T>(IDataHolder obj, Func <TableDefinition, T> listCreator)
            where T : KeyValueListBase
        {
            DataHolderDefinition holderDefinition = this.m_mapping.GetDataHolderDefinition(obj.GetType());
            List <T>             source           = new List <T>(this.m_mapping.TableDefinitions.Length);

            for (int index1 = 0; index1 < this.m_mapping.TableDefinitions.Length; ++index1)
            {
                TableDefinition table = this.m_mapping.TableDefinitions[index1];
                for (int index2 = 0; index2 < table.ColumnDefinitions.Length; ++index2)
                {
                    SimpleDataColumn columnDefinition = table.ColumnDefinitions[index2];
                    for (int index3 = 0; index3 < columnDefinition.FieldList.Count; ++index3)
                    {
                        IFlatDataFieldAccessor field = columnDefinition.FieldList[index3];
                        if (field.DataHolderDefinition == holderDefinition)
                        {
                            T obj1 = source.FirstOrDefault <T>((Func <T, bool>)(l => l.TableName == table.Name));
                            if ((object)obj1 == null)
                            {
                                source.Add(obj1 = listCreator(table));
                            }
                            object obj2 = field.Get(obj);
                            obj1.AddPair(columnDefinition.ColumnName, (object)obj2.ToString());
                        }
                    }
                }
            }

            return(source);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Inserts the Object into the underlying Database.
 /// FlushCommit() needs to be called to persist the operation.
 /// </summary>
 public static void CommitInsertAndFlush(this IDataHolder obj)
 {
     obj.CommitInsert();
     FlushCommit(obj.GetType());
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Updates changes to the Object in the underlying Database.
 /// </summary>
 public static void CommitUpdateAndFlush(this IDataHolder obj)
 {
     obj.CommitUpdate();
     FlushCommit(obj.GetType());
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Updates changes to the Object in the underlying Database.
 /// FlushCommit() needs to be called to persist the operation.
 /// </summary>
 public static void CommitUpdate(this IDataHolder obj)
 {
     GetMapper(obj.GetType()).Update(obj);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Deletes the Object from the underlying Database.
        /// FlushCommit() needs to be called to persist the operation.
        /// </summary>
        public static void CommitDelete(this IDataHolder obj)
        {
            var mapper = GetMapper(obj.GetType());

            mapper.Delete(obj);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Inserts the Object into the underlying Database.
        /// FlushCommit() needs to be called to persist the operation.
        /// </summary>
        public static void CommitInsert(this IDataHolder obj)
        {
            var mapper = GetMapper(obj.GetType());

            mapper.Insert(obj);
        }