public static void MapNestedArray(this LightDBDefinitionSet defs, IDataField dataField, IDataFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields) { NestedArrayFieldDefinition arrayFieldDefinition = (NestedArrayFieldDefinition)fieldDef; NestedArrayDataField nestedArrayDataField = (NestedArrayDataField)dataField; TableDefinition[] defaultTables = defs.EnsureTables(arrayFieldDefinition.Table, dataField.DataHolderDefinition); foreach (FlatArrayFieldDefinition segment in arrayFieldDefinition.Segments) { SimpleFlatFieldDefinition[] columns = segment.GetColumns(nestedArrayDataField.Length); for (int index = 0; index < columns.Length; ++index) { SimpleFlatFieldDefinition fieldDef1 = columns[index]; IDataField dataField1; if (!((NestedArrayAccessor)nestedArrayDataField.ArrayAccessors[index]).InnerFields.TryGetValue( segment.Name, out dataField1)) { throw new DataHolderException("NestedArray definition {0} refered to non-existing field {1}", new object[2] { (object)nestedArrayDataField, (object)segment }); } LightDBMgr.AddMapping(defs, defaultTables, fieldDef1, mappedFields, (IFlatDataFieldAccessor)dataField1, dataField1.MappedMember); } } }
public static void MapFlatSimple(this LightDBDefinitionSet defs, IDataField dataField, IDataFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields) { SimpleFlatFieldDefinition fieldDef1 = (SimpleFlatFieldDefinition)fieldDef; LightDBMgr.AddMapping(defs, defs.GetDefaultTables(dataField.DataHolderDefinition), fieldDef1, mappedFields, (IFlatDataFieldAccessor)dataField, dataField.MappedMember); }
private static DataFieldDefinition CreateFlatSimple(IDataField dataField) { SimpleFlatFieldDefinition flatFieldDefinition = new SimpleFlatFieldDefinition(); flatFieldDefinition.Name = dataField.Name; flatFieldDefinition.Column = ""; return((DataFieldDefinition)flatFieldDefinition); }
public static void MapFlatArray(this LightDBDefinitionSet defs, IDataField dataField, IDataFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields) { FlatArrayFieldDefinition arrayFieldDefinition = (FlatArrayFieldDefinition)fieldDef; FlatArrayDataField flatArrayDataField = (FlatArrayDataField)dataField; TableDefinition[] defaultTables = defs.EnsureTables(arrayFieldDefinition.Table, dataField.DataHolderDefinition); SimpleFlatFieldDefinition[] columns = arrayFieldDefinition.GetColumns(flatArrayDataField.Length); IDataFieldAccessor[] arrayAccessors = flatArrayDataField.ArrayAccessors; for (int index = 0; index < columns.Length; ++index) { SimpleFlatFieldDefinition fieldDef1 = columns[index]; LightDBMgr.AddMapping(defs, defaultTables, fieldDef1, mappedFields, (IFlatDataFieldAccessor)arrayAccessors[index], dataField.MappedMember); } }
private static void AddMapping(LightDBDefinitionSet defs, TableDefinition[] defaultTables, SimpleFlatFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields, IFlatDataFieldAccessor accessor, MemberInfo member) { string column = fieldDef.Column; TableDefinition[] tableDefinitionArray = defs.EnsureTables(fieldDef.Table, defaultTables); object defaultValue; if (!string.IsNullOrEmpty(fieldDef.DefaultStringValue)) { defaultValue = StringParser.Parse(fieldDef.DefaultStringValue, member.GetVariableType()); } else { if (string.IsNullOrEmpty(column)) { return; } defaultValue = (object)null; } foreach (TableDefinition key in tableDefinitionArray) { List <DataHolderDefinition> holderDefinitionList = defs.m_tableDataHolderMap.GetOrCreate <TableDefinition, DataHolderDefinition>(key); if (!holderDefinitionList.Contains(accessor.DataHolderDefinition)) { holderDefinitionList.Add(accessor.DataHolderDefinition); } List <SimpleDataColumn> simpleDataColumnList = mappedFields.GetOrCreate <string, SimpleDataColumn>(key.Name); PersistentAttribute persistentAttribute = ((IEnumerable <DBAttribute>)member.GetCustomAttributes <DBAttribute>()) .Where <DBAttribute>((Func <DBAttribute, bool>)(attribute => attribute is PersistentAttribute)) .FirstOrDefault <DBAttribute>() as PersistentAttribute; SimpleDataColumn simpleDataColumn; if (string.IsNullOrEmpty(column)) { simpleDataColumnList.Add(simpleDataColumn = new SimpleDataColumn(fieldDef.Name, defaultValue)); } else { simpleDataColumn = simpleDataColumnList.Find( (Predicate <SimpleDataColumn>)(cmpField => cmpField.ColumnName == column)); if (simpleDataColumn == null) { Type type1 = member.GetActualType(); if (persistentAttribute != null) { Type type2 = persistentAttribute.ReadType; if ((object)type2 == null) { type2 = type1; } type1 = type2; } IFieldReader reader = Converters.GetReader(type1); simpleDataColumnList.Add(simpleDataColumn = new SimpleDataColumn(column, reader)); } } simpleDataColumn.FieldList.Add(accessor); } }
static void AddMapping(LightDBDefinitionSet defs, TableDefinition[] defaultTables, SimpleFlatFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields, IFlatDataFieldAccessor accessor, MemberInfo member) { var column = fieldDef.Column; var tables = defs.EnsureTables(fieldDef.Table, defaultTables); object defaultValue; if (!String.IsNullOrEmpty(fieldDef.DefaultStringValue)) { defaultValue = StringParser.Parse(fieldDef.DefaultStringValue, member.GetVariableType()); } else { if (String.IsNullOrEmpty(column)) { return; } defaultValue = null; } foreach (var table in tables) { var dataHolders = defs.m_tableDataHolderMap.GetOrCreate(table); if (!dataHolders.Contains(accessor.DataHolderDefinition)) { dataHolders.Add(accessor.DataHolderDefinition); } var mappedFieldMap = mappedFields.GetOrCreate(table.Name); SimpleDataColumn dataColumn; var dbAttrs = member.GetCustomAttributes <DBAttribute>(); var attr = dbAttrs.Where(attribute => attribute is PersistentAttribute).FirstOrDefault() as PersistentAttribute; if (String.IsNullOrEmpty(column)) { // use default value mappedFieldMap.Add(dataColumn = new SimpleDataColumn(fieldDef.Name, defaultValue)); } else { dataColumn = mappedFieldMap.Find((cmpField) => cmpField.ColumnName == column); if (dataColumn == null) { var type = member.GetActualType(); if (attr != null) { type = attr.ReadType ?? type; } var reader = Converters.GetReader(type); mappedFieldMap.Add(dataColumn = new SimpleDataColumn(column, reader)); } } dataColumn.FieldList.Add(accessor); } }