// -------------------------------------------------
        //                                OutsideSql Execute
        //                                ------------------
        protected Object ExecuteOutsideSqlAsStatic(Object[] args, OutsideSqlContext outsideSqlContext)
        {
            // - - - - - - - - - - - - - - - - -
            // 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           = Apply(filteredArgs);
            InternalBasicSelectHandler selectHandler = CreateBasicSelectHandler(ctx.Sql, specifiedDataReaderHandler);

            Object[] bindVariableArray = ctx.BindVariables;
            selectHandler.LoggingMessageSqlArgs = bindVariableArray;
            return(selectHandler.Execute(bindVariableArray, ctx.BindVariableTypes));
        }
        // ===============================================================================
        //                                                                         Execute
        //                                                                         =======
        public override object Execute(object[] args)
        {
            // - - - - - - - - - - - -
            // This is top execution.
            // - - - - - - - - - - - -

            if (!ConditionBeanContext.IsExistConditionBeanOnThread())
            {
                // - - - - - - - - - -
                // Execute outsideSql.
                // - - - - - - - - - -
                if (OutsideSqlContext.IsExistOutsideSqlContextOnThread())
                {
                    OutsideSqlContext outsideSqlContext = OutsideSqlContext.GetOutsideSqlContextOnThread();
                    if (outsideSqlContext.IsDynamicBinding)
                    {
                        return(ExecuteOutsideSqlAsDynamic(args, outsideSqlContext));
                    }
                    else
                    {
                        return(ExecuteOutsideSqlAsStatic(args, outsideSqlContext));
                    }
                }

                // - - - - - - - - -
                // Execute default.
                // - - - - - - - - -
                return(ExecuteDefault(args));
            }

            // - - - - - - - - - - - -
            // Execute conditionBean.
            // - - - - - - - - - - - -
            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>();

            ConditionBean cb          = ConditionBeanContext.GetConditionBeanOnThread();
            String        finalClause = SetupRealClause(args, bindVariableList, bindVariableTypeList, bindVariableNameList);

            InternalBasicSelectHandler selectHandler = CreateBasicSelectHandler(finalClause, this.dataReaderHandler);

            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));
        }
        // -------------------------------------------------
        //                                   Default Execute
        //                                   ---------------
        protected virtual object ExecuteDefault(object[] args)
        {
            // - - - - - - - - - - - - - - - - -
            // Find specified resultSetHandler.
            // - - - - - - - - - - - - - - - - -
            IDataReaderHandler specifiedDataReaderHandler = FindSpecifiedDataReaderHandler(args);

            // - - - - - - - - -
            // Filter arguments.
            // - - - - - - - - -
            Object[] filteredArgs = FilterArgumentsForDataReaderHandler(args);

            ICommandContext            ctx           = Apply(filteredArgs);
            InternalBasicSelectHandler selectHandler = CreateBasicSelectHandler(ctx.Sql, specifiedDataReaderHandler);

            Object[] bindVariableArray = ctx.BindVariables;
            selectHandler.LoggingMessageSqlArgs = bindVariableArray;
            return(selectHandler.Execute(bindVariableArray, ctx.BindVariableTypes));
        }
        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));
        }