Beispiel #1
0
        public object Intercept(IMethodInvocation invocation, params object[] args)
        {
            MethodInfo info = invocation.MethodInvocationTarget;

            if (info.IsDefined(typeof(NoSessionAttribute), true))
            {
                return(invocation.Proceed(args));
            }

            String key = ObtainSqlMapKeyFor(info);

            SqlMapper sqlMap = ObtainSqlMapperFor(key);

            if (sqlMap.IsSessionStarted)
            {
                return(invocation.Proceed(args));
            }

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Automatic Open connection on method :" + invocation.Method.Name);
            }

            sqlMap.OpenConnection();

            if (EnlistSessionIfHasTransactionActive(key, sqlMap))
            {
                return(invocation.Proceed(args));
            }

            try
            {
                return(invocation.Proceed(args));
            }
            finally
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Close connection on method :" + invocation.Method.Name);
                }
                sqlMap.CloseConnection();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Close connection.
 /// </summary>
 public bool CloseConnection()
 {
     logger.Start("CloseConnection");
     logger.Info("Close Connection");
     try
     {
         sqlMapEmployee.CloseConnection();
         logger.Info("CloseConnection successful");
         logger.End("CloseConnection");
         return(true);
     }
     catch (Exception ex)
     {
         logger.Error(ex.ToString());
         error = ex;
         logger.Info("CloseConnection fail.");
         logger.End("CloseConnection");
         throw (new Exception("DisConnectDB:ERR-134", new Exception("DisConnectDB:ERR-134")));
     }
 }
Beispiel #3
0
 public void AfterCompletion()
 {
     _sqlMap.CloseConnection();
 }