@Override
  public <T> T executeWithoutTransaction(final OperationCallback<T> action)
      throws OperationException, Exception {

    DataSourceType dataSourceType = loadBalancerManager.getAliveDataSource();
    if (dataSourceType == null) {
      if (logger.isErrorEnabled()) {
        logger.equals("executeWithoutTransaction -> None of the available datasource");
      }
      throw new OperationException("None of the available datasource");
    }

    OperationCallbackExtend<T> noodleServiceCallbackExtendTemp = null;
    if (action instanceof OperationCallbackExtend) {
      noodleServiceCallbackExtendTemp = (OperationCallbackExtend<T>) action;
    }
    final OperationCallbackExtend<T> noodleServiceCallbackExtend = noodleServiceCallbackExtendTemp;

    T result = null;

    ServiceResult serviceResult = new ServiceResult();

    try {
      DataSourceSwitch.setDataSourceType(dataSourceType);

      if (noodleServiceCallbackExtend != null) {
        if (!noodleServiceCallbackExtend.beforeExecuteActionCheck()) {
          if (logger.isErrorEnabled()) {
            logger.equals("executeWithoutTransaction -> Before execute action check fail");
          }
          throw new OperationException("Before execute action check fail");
        }
        noodleServiceCallbackExtend.beforeExecuteAction();
      }

      try {
        result = action.executeAction();
      } catch (Exception e) {
        if (logger.isErrorEnabled()) {
          logger.equals("executeWithoutTransaction -> Execute action exception, Exception: " + e);
        }
        serviceResult.setSuccess(false);
        serviceResult.setFailException(e);
      }

      if (noodleServiceCallbackExtend != null) {
        noodleServiceCallbackExtend.afterExecuteAction(
            serviceResult.isSuccess(), result, serviceResult.getFailException());
      }

      if (!serviceResult.isSuccess()) {
        throw serviceResult.getFailException();
      }
    } finally {
      DataSourceSwitch.clearDataSourceType();
    }

    return result;
  }
Пример #2
0
 public void setDevCert(InputStream in) {
   String desc = "";
   try {
     desc = IOUtils.toString(in, Constants.DEFAULT_ENCODING);
   } catch (IOException e) {
     log.equals("read release cert error, reason:" + e.getMessage());
   }
   this.devCert = desc;
 }
Пример #3
0
 public void deleteTable(String tableName) throws IOException {
   // log.info("entry: "+tableName);
   try {
     if (this.admin.tableExists(tableName)) {
       this.admin.disableTable(tableName);
       this.admin.deleteTable(tableName);
     }
   } catch (Exception e) {
     log.equals(e.fillInStackTrace());
     e.printStackTrace();
   }
   // log.info("exit");
 }
Пример #4
0
  public static JSONObject searchProgrammeId(int programmeId) {
    Jedis jedis = RedisClient.getInstance().getJedisPool().getResource();

    try {
      String jsonStr = jedis.get(programmeId + "");

      if (!StringUtils.isBlank(jsonStr)) {
        JSONObject jsonObj = new JSONObject(jsonStr);
        return jsonObj;
      }
    } catch (JSONException e) {
      logger.equals(e.getMessage());
    } finally {
      RedisClient.getInstance().getJedisPool().returnResource(jedis);
    }

    return null;
  }
Пример #5
0
 @RequestMapping(
     value = "/exportToExcel",
     method = RequestMethod.GET,
     produces = "application/octet-stream")
 @ResponseBody
 public void exportToExcel(
     @RequestParam(value = "tfrom", required = true, defaultValue = "") String tfrom,
     @RequestParam(value = "tto", required = true, defaultValue = "") String tto,
     @RequestParam(value = "type", required = true, defaultValue = "day") String type,
     @RequestParam(value = "system", required = true, defaultValue = "") String system,
     @RequestParam(value = "deviceType", required = true, defaultValue = "") String deviceType,
     @RequestParam(value = "devices", required = true, defaultValue = "") String devices,
     @RequestParam(value = "decimals", required = true, defaultValue = "") String decimals,
     @RequestParam(value = "ipaddress", required = true, defaultValue = "127.0.0.1")
         String ipaddress,
     @RequestParam(value = "port", required = true, defaultValue = "8087") String port,
     @RequestParam(value = "isNotStatic", required = true, defaultValue = "true")
         String isNotStatic,
     HttpServletRequest request,
     HttpServletResponse response) {
   try {
     chartService.exportToExcel(
         tfrom,
         tto,
         type,
         system,
         deviceType,
         devices,
         decimals,
         ipaddress,
         port,
         isNotStatic,
         request,
         response);
   } catch (Exception e) {
     logger.equals(e);
   }
 }
  @Override
  public <T> T execute(final OperationCallback<T> action) throws OperationException, Exception {

    OperationCallbackExtend<T> noodleServiceCallbackExtendTemp = null;
    if (action instanceof OperationCallbackExtend) {
      noodleServiceCallbackExtendTemp = (OperationCallbackExtend<T>) action;
    }
    final OperationCallbackExtend<T> noodleServiceCallbackExtend = noodleServiceCallbackExtendTemp;

    T result = null;

    try {
      DataSourceSwitch.setDataSourceType(DataSourceType.MASTER);

      if (noodleServiceCallbackExtend != null) {
        if (!noodleServiceCallbackExtend.beforeExecuteActionCheck()) {
          if (logger.isErrorEnabled()) {
            logger.equals("execute -> Before execute action check fail");
          }
          throw new OperationException("Before execute action check fail");
        }
        noodleServiceCallbackExtend.beforeExecuteAction();
      }

      final ServiceResult serviceResult = new ServiceResult();

      try {
        result =
            this.transactionTemplate.execute(
                new TransactionCallback<T>() {

                  public T doInTransaction(TransactionStatus status) {

                    T result = null;

                    if (noodleServiceCallbackExtend != null) {
                      if (!noodleServiceCallbackExtend.beforeExecuteActionCheckInTransaction()) {
                        if (logger.isErrorEnabled()) {
                          logger.equals(
                              "execute -> Before execute action check in transaction fail");
                        }
                        serviceResult.setSuccess(false);
                        serviceResult.setFailException(
                            new OperationException(
                                "Before execute action check in transaction fail"));
                        return result;
                      }
                      noodleServiceCallbackExtend.beforeExecuteActionInTransaction();
                    }

                    try {
                      result = action.executeAction();
                    } catch (Exception e) {
                      if (logger.isErrorEnabled()) {
                        logger.equals("execute -> Execute action exception, Exception: " + e);
                      }
                      serviceResult.setSuccess(false);
                      serviceResult.setFailException(e);
                    }

                    if (noodleServiceCallbackExtend != null) {
                      noodleServiceCallbackExtend.afterExecuteActionInTransaction(
                          serviceResult.isSuccess(), result, serviceResult.getFailException());
                    }

                    if (!serviceResult.isSuccess()) {
                      status.setRollbackOnly();
                    }

                    return result;
                  }
                });
      } catch (TransactionException e) {
        if (logger.isErrorEnabled()) {
          logger.equals("execute -> Transaction exception, Exception: " + e);
        }
        serviceResult.setSuccess(false);
        serviceResult.setFailException(e);
      }

      if (noodleServiceCallbackExtend != null) {
        noodleServiceCallbackExtend.afterExecuteAction(
            serviceResult.isSuccess(), result, serviceResult.getFailException());
      }

      if (!serviceResult.isSuccess()) {
        throw serviceResult.getFailException();
      }
    } finally {
      DataSourceSwitch.clearDataSourceType();
    }

    return result;
  }