Ejemplo n.º 1
0
        public static DataHolderTableMapping[] CreateDataHolderTableMappings(
            Dictionary <TableDefinition, List <DataHolderDefinition> > tableDataHolderMap,
            DataHolderDefinition[] dataHolderDefinitions)
        {
            Dictionary <DataHolderDefinition, List <TableDefinition> > dictionary =
                new Dictionary <DataHolderDefinition, List <TableDefinition> >();

            foreach (KeyValuePair <TableDefinition, List <DataHolderDefinition> > tableDataHolder in tableDataHolderMap)
            {
                if (tableDataHolder.Value == null)
                {
                    log.Warn(
                        "Table-definition \"{0}\" has no used columns (and can possibly be removed from the config).");
                }
                else
                {
                    tableDataHolder.Key.DataHolderDefinitions = tableDataHolder.Value.ToArray();
                    foreach (DataHolderDefinition holderDefinition in tableDataHolder.Key.DataHolderDefinitions)
                    {
                        dictionary.GetOrCreate(holderDefinition)
                        .Add(tableDataHolder.Key);
                    }
                }
            }

            List <DataHolderTableMapping>  holderTableMappingList = new List <DataHolderTableMapping>();
            HashSet <DataHolderDefinition> holderDefinitionSet1   =
                new HashSet <DataHolderDefinition>(
                    dictionary.Keys.ToArray());
            HashSet <DataHolderDefinition> holderDefinitionSet2 = new HashSet <DataHolderDefinition>();
            HashSet <TableDefinition>      tableDefinitionSet   = new HashSet <TableDefinition>();

            foreach (DataHolderDefinition key in dictionary.Keys)
            {
                if (AddTables(holderDefinitionSet1, key,
                              dictionary, holderDefinitionSet2, tableDefinitionSet))
                {
                    DataHolderTableMapping holderTableMapping = new DataHolderTableMapping(
                        holderDefinitionSet2.ToArray(),
                        tableDefinitionSet.ToArray());
                    holderTableMappingList.Add(holderTableMapping);
                    holderDefinitionSet2.Clear();
                    tableDefinitionSet.Clear();
                }
            }

            foreach (TableDefinition key in tableDataHolderMap.Keys)
            {
                TableDefinition table = key;
                foreach (SimpleDataColumn columnDefinition in table.ColumnDefinitions)
                {
                    if (columnDefinition is IDataFieldBase)
                    {
                        DataHolderDefinition holderDefinition =
                            ((IDataFieldBase)columnDefinition).DataHolderDefinition;
                        if (!holderDefinitionSet2.Contains(holderDefinition))
                        {
                            DataHolderTableMapping holderTableMapping =
                                holderTableMappingList.Find(map =>
                                                            map.TableDefinitions.Contains(
                                                                table));
                            DataHolderDefinition[] holderDefinitions = holderTableMapping.DataHolderDefinitions;
                            holderTableMapping.DataHolderDefinitions =
                                new DataHolderDefinition[holderDefinitions.Length + 1];
                            Array.Copy(holderDefinitions, holderTableMapping.TableDefinitions,
                                       holderDefinitions.Length);
                            holderTableMapping.DataHolderDefinitions[holderDefinitions.Length] = holderDefinition;
                        }
                    }
                }
            }

            return(holderTableMappingList.ToArray());
        }
Ejemplo n.º 2
0
 public LightDBMapper(DataHolderTableMapping mapping, IDbWrapper db)
 {
     m_mapping = mapping;
     m_db      = db;
     db.Prepare(this);
 }
Ejemplo n.º 3
0
        public static DataHolderTableMapping[] CreateDataHolderTableMappings(
            Dictionary <TableDefinition, List <DataHolderDefinition> > tableDataHolderMap,
            DataHolderDefinition[] dataHolderDefinitions
            )
        {
            // find exact mappings and split them up into as small parts as possible
            // this way we will only read the data from tables that is actually
            // mapped to DataHolders and we will read every cell only once

            var tablesByHolder = new Dictionary <DataHolderDefinition, List <TableDefinition> >();

            foreach (var pair in tableDataHolderMap)
            {
                if (pair.Value == null)
                {
                    log.Warn("Table-definition \"{0}\" has no used columns (and can possibly be removed from the config).");
                }
                else
                {
                    pair.Key.DataHolderDefinitions = pair.Value.ToArray();
                    foreach (var dataHolder in pair.Key.DataHolderDefinitions)
                    {
                        tablesByHolder.GetOrCreate(dataHolder).Add(pair.Key);
                    }
                }
            }

            var mappings = new List <DataHolderTableMapping>();
            var allDefs  = new HashSet <DataHolderDefinition>(tablesByHolder.Keys.ToArray());

            var dataHolders = new HashSet <DataHolderDefinition>();
            var tables      = new HashSet <TableDefinition>();

            foreach (var holder in tablesByHolder.Keys)
            {
                if (AddTables(allDefs, holder, tablesByHolder, dataHolders, tables))
                {
                    var mapping = new DataHolderTableMapping(dataHolders.ToArray(), tables.ToArray());
                    mappings.Add(mapping);
                    dataHolders.Clear();
                    tables.Clear();
                }
            }

            foreach (var table in tableDataHolderMap.Keys)
            {
                foreach (var field in table.ColumnDefinitions)
                {
                    if (field is IDataFieldBase)
                    {
                        var holderDef = ((IDataFieldBase)field).DataHolderDefinition;
                        if (!dataHolders.Contains(holderDef))
                        {
                            var mapping      = mappings.Find(map => map.TableDefinitions.Contains(table));
                            var tableHolders = mapping.DataHolderDefinitions;
                            mapping.DataHolderDefinitions = new DataHolderDefinition[tableHolders.Length + 1];
                            Array.Copy(tableHolders, mapping.TableDefinitions, tableHolders.Length);
                            mapping.DataHolderDefinitions[tableHolders.Length] = holderDef;
                        }
                    }
                }
            }

            return(mappings.ToArray());
        }