protected override void SetupRelationKeyValue(RelationRowCreationResource res) { IRelationPropertyType rpt = res.RelationPropertyType; IBeanMetaData bmd = rpt.BeanMetaData; DBMeta dbmeta = FindDBMeta(bmd.BeanType, bmd.TableName); for (int i = 0; i < rpt.KeySize; ++i) { String columnName = rpt.GetMyKey(i) + res.BaseSuffix; if (!res.ContainsColumnName(columnName)) { continue; } if (!res.HasRowInstance()) { Object row; if (dbmeta != null) { row = dbmeta.NewEntity(); } else { row = NewRelationRow(rpt); } res.Row = row; } if (!res.ContainsRelKeyValueIfExists(columnName)) { continue; } Object value = res.ExtractRelKeyValue(columnName); if (value == null) { // basically no way // because this is not called if the referred value // is null (then it must be no relation key) // @see InternalBeanListMetaDataResultSetHandler continue; } String yourKey = rpt.GetYourKey(i); IPropertyType pt = bmd.GetPropertyTypeByColumnName(yourKey); PropertyInfo pi = pt.PropertyInfo; pi.SetValue(res.Row, value, null); continue; } }
protected RelationKey CreateRelationKey(IDataReader reader, IRelationPropertyType rpt , System.Collections.IList columnNames, System.Collections.Hashtable relKeyValues , Map <String, int?> selectIndexMap) { System.Collections.ArrayList keyList = new System.Collections.ArrayList(); IBeanMetaData bmd = rpt.BeanMetaData; for (int i = 0; i < rpt.KeySize; ++i) { IValueType valueType = null; IPropertyType pt = rpt.BeanMetaData.GetPropertyTypeByColumnName(rpt.GetYourKey(i)); String relationNoSuffix = BuildRelationNoSuffix(rpt); String columnName = RemoveQuoteIfExists(pt.ColumnName) + relationNoSuffix; if (columnNames.Contains(columnName)) { valueType = pt.ValueType; } else { // basically unreachable // because the referred column (basically PK or FK) must exist // if the relation's select clause is specified return(null); } Object value; if (selectIndexMap != null) { value = GetValue(reader, columnName, valueType, selectIndexMap); } else { value = valueType.GetValue(reader, columnName); } if (value == null) { // reachable when the referred column data is null // (treated as no relation data) return(null); } relKeyValues[columnName] = value; keyList.Add(value); } if (keyList.Count > 0) { object[] keys = keyList.ToArray(); return(new RelationKey(keys)); } else { return(null); } }