コード例 #1
0
        protected Object ExecuteOutsideSqlAsDynamic(Object[] args, OutsideSqlContext outsideSqlContext)
        {
            Object firstArg = args[0];

            PropertyInfo[] properties  = firstArg.GetType().GetProperties();
            String         filteredSql = this.Sql;

            // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            // Resolve embedded comment for parsing bind variable comment in embedded comment.
            // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            for (int i = 0; i < properties.Length; i++)
            {
                PropertyInfo propertyInfo = properties[i];
                Type         propertyType = propertyInfo.PropertyType;
                if (!propertyType.Equals(typeof(String)))
                {
                    continue;
                }
                String outsideSqlPiece = (String)propertyInfo.GetValue(firstArg, null);
                if (outsideSqlPiece == null)
                {
                    continue;
                }
                String embeddedComment = "/*$pmb." + propertyInfo.Name + "*/";
                filteredSql = filteredSql.Replace(embeddedComment, outsideSqlPiece);
            }

            S2DaoSelectDynamicCommand outsideSqlCommand = CreateMySelectDynamicCommand();

            outsideSqlCommand.ArgNames = ArgNames;
            outsideSqlCommand.ArgTypes = ArgTypes;
            outsideSqlCommand.Sql      = filteredSql;

            // - - - - - - - - - - - - - - - - -
            // Find specified resultSetHandler.
            // - - - - - - - - - - - - - - - - -
            IDataReaderHandler specifiedDataReaderHandler = FindSpecifiedDataReaderHandler(args);

            // - - - - - - - - -
            // Filter arguments.
            // - - - - - - - - -
            Object[] filteredArgs;
            if (outsideSqlContext.IsSpecifiedOutsideSql)
            {
                Object parameterBean = outsideSqlContext.ParameterBean;
                filteredArgs = new Object[] { parameterBean };
            }
            else
            {
                filteredArgs = FilterArgumentsForDataReaderHandler(args);
            }

            ICommandContext ctx = outsideSqlCommand.DoApply(filteredArgs);
            IList <Object>  bindVariableList     = new System.Collections.Generic.List <Object>();
            IList <Type>    bindVariableTypeList = new System.Collections.Generic.List <Type>();
            IList <String>  bindVariableNameList = new System.Collections.Generic.List <String>();

            AddBindVariableInfo(ctx, bindVariableList, bindVariableTypeList, bindVariableNameList);
            InternalBasicSelectHandler selectHandler = CreateBasicSelectHandler(ctx.Sql, specifiedDataReaderHandler);

            Object[] bindVariableArray = new Object[bindVariableList.Count];
            bindVariableList.CopyTo(bindVariableArray, 0);
            Type[] bindVariableTypeArray = new Type[bindVariableTypeList.Count];
            bindVariableTypeList.CopyTo(bindVariableTypeArray, 0);
            String[] bindVariableNameArray = new String[bindVariableNameList.Count];
            bindVariableNameList.CopyTo(bindVariableNameArray, 0);
            selectHandler.LoggingMessageSqlArgs = bindVariableArray;
            return(selectHandler.Execute(bindVariableArray, bindVariableTypeArray, bindVariableNameArray));
        }