Beispiel #1
0
 @Override
 public void destroy(NutConfig config) {
   if (timer != null) {
     timer.cancel();
     timer = null;
     if (log.isInfoEnabled()) {
       log.info("schedule Runner 已关闭");
     }
   }
 }
Beispiel #2
0
  /** 这是最后的大招了,查一下形参的名字,作为@Param("形参名")进行处理 */
  protected ParamInjector paramNameInject(Method method, int index) {
    if (!Lang.isAndroid) {
      List<String> names = MethodParamNamesScaner.getParamNames(method);
      if (names != null)
        return new NameInjector(names.get(index), null, method.getParameterTypes()[index], null);
      else if (log.isInfoEnabled())
        log.infof(
            "Complie without debug info? can't deduce param name. fail back to PathArgInjector!! index=%d > %s",
            index, method);
    }

    return new PathArgInjector(method.getParameterTypes()[index]);
  }
Beispiel #3
0
 public AnnotationIocLoader(String... packages) {
   for (String packageZ : packages)
     for (Class<?> classZ : Scans.me().scanPackage(packageZ)) addClass(classZ);
   if (map.size() > 0) {
     if (log.isInfoEnabled())
       log.infof(
           "Scan complete ! Found %s classes in %s base-packages!\nbeans = %s",
           map.size(), packages.length, Castors.me().castToString(map.keySet()));
   } else {
     log.warn(
         "NONE Annotation-Class found!! Check your configure or report a bug!! packages="
             + Arrays.toString(packages));
   }
 }
Beispiel #4
0
 public Object eject(Object obj) {
   try {
     return null == obj ? null : getter.invoke(obj);
   } catch (InvocationTargetException e) {
     throw new FailToGetValueException("getter=" + getter, e);
   } catch (Exception e) {
     if (log.isInfoEnabled()) log.info("Fail to value by getter", e);
     throw Lang.makeThrow(
         "Fail to invoke getter %s.'%s()' because [%s]: %s",
         getter.getDeclaringClass().getName(),
         getter.getName(),
         Lang.unwrapThrow(e),
         Lang.unwrapThrow(e).getMessage());
   }
 }
Beispiel #5
0
  @Override
  public void init(NutConfig config) {
    Ioc ioc = config.getIoc();

    final Dao dao = ioc.get(null, "dao");

    timer.schedule(
        new TimerTask() {
          @Override
          public void run() {}
        },
        1000,
        INTERVAL);
    if (log.isInfoEnabled()) {
      log.info("系统初始化完毕");
    }
  }
Beispiel #6
0
  public void exec(Connection conn, DaoStatement st) {
    // 这个变量声明,后面两 case 要用到
    Object[][] paramMatrix;

    // 在这个块里执行语句
    try {
      /*
       * 语句执行前的预操作
       */
      st.onBefore(conn);
      /*
       * 开始执行语句
       */
      switch (st.getSqlType()) {
          // 查询
        case SELECT:
          _runSelect(conn, st);
          break;
          // 创建 & 删除 & 修改 & 清空
        case ALTER:
        case TRUNCATE:
        case CREATE:
        case DROP:
          _runStatement(conn, st);
          st.onAfter(conn, null);
          break;
          // 仅仅是运行回调
        case RUN:
          st.onAfter(conn, null);
          break;
          // 插入 & 删除 & 更新
          // case DELETE:
          // case UPDATE:
          // case INSERT:
          // 见鬼了,未知类型,也当作普通 SQL 运行吧,见 Issue#13
        default:
          if (st.getSqlType() == SqlType.OTHER && log.isInfoEnabled())
            log.info("Can't indentify SQL type :   " + st);
          paramMatrix = st.getParamMatrix();
          // 木有参数,直接运行
          if (null == paramMatrix || paramMatrix.length == 0) {
            _runStatement(conn, st);
          }
          // 有参数,用缓冲语句
          else {
            _runPreparedStatement(conn, st, paramMatrix);
          }
          // 运行回调
          st.onAfter(conn, null);
      }
    }
    // If any SQLException happend, throw out the SQL string
    catch (SQLException e) {
      if (log.isInfoEnabled()) log.debug("SQLException", e);
      throw new DaoException(
          format(
              "!Nutz SQL Error: '%s'\nPreparedStatement: \n'%s'",
              st.toString(), st.toPreparedStatement()),
          e);
    }
  }
Beispiel #7
0
  public Object[] adapt(
      ServletContext sc, HttpServletRequest req, HttpServletResponse resp, String[] pathArgs) {

    Object[] args = new Object[argTypes.length];

    if (args.length != injs.length)
      throw new IllegalArgumentException(
          "args.length != injs.length , You get a bug, pls report it!!");

    AdaptorErrorContext errCtx = null;
    // 也许用户有自己的AdaptorErrorContext实现哦
    if (argTypes.length > 0) {
      if (AdaptorErrorContext.class.isAssignableFrom(argTypes[argTypes.length - 1]))
        errCtx =
            (AdaptorErrorContext) Mirror.me(argTypes[argTypes.length - 1]).born(argTypes.length);
    }

    Object obj;
    try {
      obj = getReferObject(sc, req, resp, pathArgs);
    } catch (Throwable e) {
      if (errCtx != null) {
        if (log.isInfoEnabled())
          log.info(
              "Adapter Error catched , but I found AdaptorErrorContext param, so, set it to args, and continue",
              e);
        errCtx.setAdaptorError(e, this);
        args[args.length - 1] = errCtx;
        return args;
      }
      throw Lang.wrapThrow(e);
    }

    int len = Math.min(args.length, null == pathArgs ? 0 : pathArgs.length);
    for (int i = 0; i < args.length; i++) {
      Object value = null;
      if (i < len) { // 路径参数
        value = null == pathArgs ? null : pathArgs[i];
      } else { // 普通参数
        value = obj;
      }
      try {
        args[i] = injs[i].get(sc, req, resp, value);
      } catch (Throwable e) {
        if (errCtx != null) {
          log.infof("Adapter Param Error(%s) index=%d", method, i, e);
          errCtx.setError(i, e, method, value, injs[i]); // 先错误保存起来,全部转好了,再判断是否需要抛出
        } else throw Lang.wrapThrow(e);
      }
      if (args[i] == null && argTypes[i].isPrimitive()) {
        args[i] = Lang.getPrimitiveDefaultValue(argTypes[i]);
      }
    }

    // 看看是否有任何错误
    if (errCtx == null) return args;
    for (Throwable err : errCtx.getErrors()) {
      if (err == null) continue;
      int lastParam = argTypes.length - 1;
      if (AdaptorErrorContext.class.isAssignableFrom(argTypes[lastParam])) {
        if (log.isInfoEnabled())
          log.info(
              "Adapter Param Error catched , but I found AdaptorErrorContext param, so, set it to args, and continue");
        args[lastParam] = errCtx;
        return args;
      }
      // 没有AdaptorErrorContext参数? 那好吧,按之前的方式,抛出异常
      throw Lang.wrapThrow(err);
    }

    return args;
  }