protected override void SetupRelationAllValue(RelationRowCreationResource res)
 {
     System.Collections.Generic.IDictionary <String, IPropertyType> propertyCacheElement = res.ExtractPropertyCacheElement();
     System.Collections.Generic.ICollection <String> columnNameCacheElementKeySet        = propertyCacheElement.Keys;
     foreach (String columnName in columnNameCacheElementKeySet)
     {
         IPropertyType pt = propertyCacheElement[columnName];
         res.CurrentPropertyType = pt;
         if (!IsValidRelationPerPropertyLoop(res))
         {
             res.ClearRowInstance();
             return;
         }
         SetupRelationProperty(res);
     }
     if (!IsValidRelationAfterPropertyLoop(res))
     {
         res.ClearRowInstance();
         return;
     }
     res.ClearValidValueCount();
     if (res.HasNextRelationProperty() && (HasConditionBean(res) || res.HasNextRelationLevel()))
     {
         SetupNextRelationRow(res);
     }
 }
        protected bool HasSelectedForeignInfo(RelationRowCreationResource res)
        {
            ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread();

            if (cb.SqlClause.hasSelectedForeignInfo(res.RelationNoSuffix))
            {
                return(true);
            }
            return(false);
        }
        protected override bool IsTargetProperty(RelationRowCreationResource res)
        {
            IPropertyType pt = res.CurrentPropertyType;

            if (!pt.PropertyInfo.CanWrite)
            {
                return(false);
            }
            if (typeof(System.Collections.Generic.IList <>).IsAssignableFrom(pt.PropertyInfo.GetType()))
            {
                return(false);
            }
            return(true);
        }
        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 override void SetupPropertyCache(RelationRowCreationResource res)
        {
            // - - - - - - - - - - -
            // Recursive Call Point!
            // - - - - - - - - - - -
            res.InitializePropertyCacheElement();

            // Do only selected foreign property for performance if condition-bean exists.
            if (HasConditionBean(res) && !HasSelectedForeignInfo(res))
            {
                return;
            }

            // Set up property cache about current beanMetaData.
            IBeanMetaData nextBmd = res.GetRelationBeanMetaData();

            for (int i = 0; i < nextBmd.PropertyTypeSize; ++i)
            {
                IPropertyType pt = nextBmd.GetPropertyType(i);
                res.CurrentPropertyType = pt;
                if (!IsTargetProperty(res))
                {
                    continue;
                }
                SetupPropertyCacheElement(res);
            }

            // Set up next relation.
            if (res.HasNextRelationProperty() && (HasConditionBean(res) || res.HasNextRelationLevel()))
            {
                res.BackupRelationPropertyType();
                res.IncrementCurrentRelationNestLevel();
                try {
                    SetupNextPropertyCache(res, nextBmd);
                } finally {
                    res.RestoreRelationPropertyType();
                    res.DecrementCurrentRelationNestLevel();
                }
            }
        }
        protected override void RegisterRelationValue(RelationRowCreationResource res, String columnName)
        {
            IPropertyType pt    = res.CurrentPropertyType;
            Object        value = null;

            if (res.ContainsRelKeyValueIfExists(columnName))
            {
                // if this column is relation key, it gets the value from relation key values
                // for performance and avoiding twice getting same column value
                value = res.ExtractRelKeyValue(columnName);
            }
            else
            {
                IValueType         valueType      = pt.ValueType;
                Map <String, int?> selectIndexMap = GetSelectIndexMap();
                if (selectIndexMap != null)
                {
                    value = GetValue(res.DataReader, columnName, valueType, selectIndexMap);
                }
                else
                {
                    value = valueType.GetValue(res.DataReader, columnName);
                }
            }
            if (value != null)
            {
                res.IncrementValidValueCount();
                DBMeta dbmeta       = FindDBMeta(res.Row);
                String propertyName = pt.PropertyName;
                if (dbmeta != null && dbmeta.HasEntityPropertySetupper(propertyName))
                {
                    dbmeta.SetupEntityProperty(propertyName, res.Row, value);
                }
                else
                {
                    PropertyInfo pd = pt.PropertyInfo;
                    pd.SetValue(res.Row, value, null);
                }
            }
        }
 protected bool HasConditionBean(RelationRowCreationResource res)
 {
     return(ConditionBeanContext.IsExistConditionBeanOnThread());
 }