private object SqlExecute(SqlResultHandler handler)
        {
            object result = null;

            try
            {
                sqlconnection.Open();
                result = handler.Invoke();
            }
            catch (SqlException sqlex)
            {
                ThrowException(sqlex);
            }
            catch (Exception ex)
            {
                ThrowException(ex);
            }
            finally
            {
                if (sqlconnection.State != ConnectionState.Closed)
                {
                    sqlconnection.Close();
                }
            }
            return(result);
        }
        protected virtual object DispatchInvoking(IMethodInvocation invocation)
        {
            MethodBase method = invocation.Method;

            if (!method.IsAbstract)
            {
                return(invocation.Proceed());
            }
            bool logEnabled = IsLogEnabled();

            // - - - - - - - - - - - - -
            // Initialize DAO meta data
            // - - - - - - - - - - - - -
            if (method.Name.Equals("InitializeDaoMetaData"))
            {
                InitializeSqlCommand(invocation);
                return(null); // The end! (Initilization Only)
            }

            // - - - - - - - - - - -
            // Preprocess outsideSql
            // - - - - - - - - - - -
            PreprocessOutsideSql(invocation);

            // - - - - - - - - - - - - -
            // Preprocess conditionBean
            // - - - - - - - - - - - - -
            ConditionBean cb = PreprocessConditionBean(invocation);

            // - - - - - - - - -
            // Set up sqlCommand
            // - - - - - - - - -
            ISqlCommand cmd = null;

            try {
                DateTime?beforeCmd = null;
                if (logEnabled)
                {
                    beforeCmd = DateTime.Now;
                }
                cmd = FindSqlCommand(invocation);
                if (logEnabled)
                {
                    DateTime afterCmd = DateTime.Now;
                    if (!afterCmd.Equals(beforeCmd.Value))
                    {
                        LogSqlCommand(invocation, cmd, beforeCmd.Value, afterCmd);
                    }
                }
            } finally {
                if (IsLogEnabled())
                {
                    LogInvocation(invocation);
                }
            }

            SqlResultHandler sqlResultHandler       = GetSqlResultHander();
            bool             existsSqlResultHandler = sqlResultHandler != null;
            DateTime?        before = null;

            if (logEnabled || existsSqlResultHandler)
            {
                before = DateTime.Now; // for performance view
            }

            // - - - - - - - - - -
            // Execute sqlCommand!
            // - - - - - - - - - -
            object ret = null;

            try {
                ret = cmd.Execute(invocation.Arguments);
            } catch (Exception e) {
                if (e.GetType().Equals(typeof(NotSingleRowUpdatedRuntimeException)))
                {
                    throw new EntityAlreadyUpdatedException((NotSingleRowUpdatedRuntimeException)e);
                }
                throw;
            } finally {
                PostprocessConditionBean(invocation, cb);
            }

            // - - - - - - - - - -
            // Convert and Return!
            // - - - - - - - - - -
            Type retType = ((MethodInfo)method).ReturnType;

            ret = Seasar.Framework.Util.ConversionUtil.ConvertTargetType(ret, retType);

            if (logEnabled || existsSqlResultHandler)
            {
                DateTime after = DateTime.Now; // for performance view
                if (logEnabled)
                {
                    LogReturn(invocation, retType, ret, before.Value, after);
                }
                if (existsSqlResultHandler)
                {
                    SqlResultInfo info = new SqlResultInfo();
                    info.Result         = ret;
                    info.CommandName    = method.Name;
                    info.DisplaySql     = (String)InternalMapContext.GetObject("df:DisplaySql");
                    info.BeforeDateTime = before.Value;
                    info.AfterDateTime  = after;
                    sqlResultHandler.Invoke(info);
                }
            }
            return(ret);
        }