Ejemplo n.º 1
0
 protected void AddRelationRowCache(RelationRowCache cache, int relno, RelationKey relKey, Object relationRow, bool canCache)
 {
     if (canCache)
     {
         cache.AddRelationRow(relno, relKey, relationRow);
     }
 }
Ejemplo n.º 2
0
        protected void Handle(IDataReader dataReader, System.Collections.IList list)
        {
            // Lazy initialization because if the result is zero, the resources are unused.
            System.Collections.IList columnNames = null;
            IColumnMetaData[]        columns     = null;
            IDictionary <String, IDictionary <String, IPropertyType> > relationPropertyCache = null;
            RelationRowCache relRowCache = null;

            int  relSize = BeanMetaData.RelationPropertyTypeSize;
            bool hasCB   = HasConditionBean();
            bool skipRelationLoop;
            {
                bool emptyRelation       = IsSelectedForeignInfoEmpty();
                bool hasOSC              = HasOutsideSqlContext();
                bool specifiedOutsideSql = IsSpecifiedOutsideSql();

                // If it has condition-bean that has no relation to get
                // or it has outside-sql context that is specified-outside-sql,
                // they are unnecessary to do relation loop!
                skipRelationLoop = (hasCB && emptyRelation) || (hasOSC && specifiedOutsideSql);
            }
            bool canCache = hasCB && CanRelationMappingCache();
            Map <String, int?> selectIndexMap = GetSelectIndexMap();

            while (dataReader.Read())
            {
                if (columnNames == null)
                {
                    columnNames = CreateColumnNames(dataReader.GetSchemaTable());
                }
                if (columns == null)
                {
                    columns = CreateColumnMetaData(columnNames);
                }

                // Create row instance of base table by row property cache.
                Object row = CreateRow(dataReader, columns);
                if (skipRelationLoop)
                {
                    PostCreateRow(row, BeanMetaData);
                    list.Add(row);
                    continue;
                }

                if (relationPropertyCache == null)
                {
                    relationPropertyCache = CreateRelationPropertyCache(columnNames);
                }
                if (relRowCache == null)
                {
                    relRowCache = new RelationRowCache(relSize);
                }
                for (int i = 0; i < relSize; ++i)
                {
                    IRelationPropertyType rpt = BeanMetaData.GetRelationPropertyType(i);
                    if (rpt == null)
                    {
                        continue;
                    }

                    // Do only selected foreign property for performance if condition-bean exists.
                    if (hasCB && !HasSelectedForeignInfo(BuildRelationNoSuffix(rpt)))
                    {
                        continue;
                    }

                    Object relationRow = null;
                    System.Collections.Hashtable relKeyValues = new System.Collections.Hashtable();
                    RelationKey relKey = CreateRelationKey(dataReader, rpt, columnNames, relKeyValues, selectIndexMap);
                    if (relKey != null)
                    {
                        relationRow = GetCachedRelationRow(relRowCache, i, relKey, canCache);
                        if (relationRow == null)
                        {
                            relationRow = CreateRelationRow(dataReader, rpt, columnNames, relKeyValues, relationPropertyCache);
                            if (relationRow != null)
                            {
                                AddRelationRowCache(relRowCache, i, relKey, relationRow, canCache);
                                PostCreateRow(relationRow, rpt.BeanMetaData);
                            }
                        }
                    }
                    if (relationRow != null)
                    {
                        PropertyInfo pi = rpt.PropertyInfo;
                        pi.SetValue(row, relationRow, null);
                    }
                }
                PostCreateRow(row, BeanMetaData);
                list.Add(row);
            }
        }
Ejemplo n.º 3
0
 protected Object GetCachedRelationRow(RelationRowCache cache, int relno, RelationKey relKey, bool canCache)
 {
     return(canCache ? cache.GetRelationRow(relno, relKey) : null);
 }