Exemple #1
0
  /**
   * Save all parameters in the properties added by ronnie for insert Parameter into
   * database(20090122) updated by Lue 20090916
   */
  public boolean saveParams(String merchantName, String loginId, Properties prop) {
    boolean success = true;
    Connection connection = null;
    SystemLogManager sysLogMgr = SystemLogManager.getInstance();
    ;
    DBAccessHome dba = DBAccessHome.getInstance();

    StringBuffer querySql = new StringBuffer("");
    StringBuffer insertSql = new StringBuffer("");
    StringBuffer updateSql = new StringBuffer("");

    PreparedStatement pstmtInsert = null;
    PreparedStatement pstmtQuery = null;
    PreparedStatement pstmtUpdate = null;
    PreparedStatement pstmtInsertMQ = null;

    ResultSet rs = null;
    int noUpdated = 0;
    String paramName = "", paramValue = "", paramType = "";

    try {

      connection = dba.getDBConnection();

      if (loginId == null
          || merchantName == null
          || prop == null
          || loginId.trim().equals("")
          || merchantName.trim().equals("")) {
        throw new Exception("Merchant Name, User logon ID or properties is null or blank");
      }

      if (connection == null) {
        System.err.println("ParamHome.saveParams(): DB Connection is null");
        throw new Exception("DB Connection is null");
      }

      Enumeration en = prop.propertyNames();
      java.util.Date now = new java.util.Date();

      // loop thru the properties
      while (en.hasMoreElements()) {
        paramName = (String) en.nextElement();

        if (paramName.equals(SEC_ALLOW_SAME_USER_ID_PW)
            || paramName.equals(SEC_PW_EXPIRY_DAY)
            || paramName.equals(SEC_BAD_PW_ATTEMPTS)
            || paramName.equals(SEC_CHG_PW_FIR_LOGON)
            || paramName.equals(SEC_UID_MIN_LEN)
            || paramName.equals(SEC_UID_MAX_LEN)
            || paramName.equals(SEC_UserPwdMinLen)
            || paramName.equals(SEC_UserPwdMaxLen)
            || paramName.equals(SEC_LOGOUT_TIME)
            || paramName.equals(SEC_USER_DOR_DAYS)
            || paramName.equals(SEC_USER_INACTIVE)
            || paramName.equals(SEC_MAX_WEB_CON)
            || paramName.equals(SEC_DAY_LIMIT)) {
          paramType = PARAM_TYPE_SEC;
          paramValue = prop.getProperty(paramName);
          System.out.println("ParamName=" + paramName + ", paramValue=" + paramValue);
        } else if (paramName.equals(TECH_PARAM_PASSWORD_REG_EXPR)
            || paramName.equals(TECH_PARAM_TOTAL_PASSWORD_HIST)
            || paramName.equals(TECH_PASSWORD_RESET_FLAG)
            || paramName.equals(TECH_MQ_TIMEOUT)
            || paramName.equals(TECH_MQ_LOOP)) {
          paramType = PARAM_TYPE_TECH;
          paramValue = prop.getProperty(paramName);
          System.out.println("ParamName=" + paramName + ", paramValue=" + paramValue);
        } else {
          // skip the unknown param so that it is not inserted into the table
          System.out.println("SKIP ParamName=" + paramName);
          continue;
        }

        boolean found = false;
        querySql.delete(0, querySql.length());
        querySql.append("select PARAM_VALUE from ").append(Constants.DB_TBL_PARAMETERS);
        querySql.append(" Where PARAM_TYPE = ? and PARAM_NAME = ? ");

        pstmtQuery = connection.prepareStatement(querySql.toString());
        pstmtQuery.setString(1, paramType);
        pstmtQuery.setString(2, paramName);
        System.out.println("QUERY=" + querySql.toString());
        System.out.println("paramType=" + paramType + ", paramName=" + paramName);

        rs = pstmtQuery.executeQuery();

        if (rs.next()) {
          found = true;
        }

        rs.close();
        pstmtQuery.close();

        if (!found) {

          insertSql.delete(0, insertSql.length());
          insertSql.append("INSERT INTO ").append(Constants.DB_TBL_PARAMETERS);
          insertSql.append(
              " (MER_NAME, PARAM_TYPE, PARAM_CODE, PARAM_NAME, PARAM_VALUE, PARAM_1, PARAM_2, PARAM_3, PARAM_4, CREATED_BY, CREATED_DATE) ");
          insertSql.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ");

          pstmtInsert = connection.prepareStatement(insertSql.toString());
          pstmtInsert.setString(1, merchantName);
          pstmtInsert.setString(2, paramType);
          pstmtInsert.setString(3, "");
          pstmtInsert.setString(4, paramName);
          pstmtInsert.setString(5, paramValue);
          pstmtInsert.setString(6, "");
          pstmtInsert.setString(7, "");
          pstmtInsert.setString(8, "");
          pstmtInsert.setString(9, "");
          pstmtInsert.setString(10, loginId);
          pstmtInsert.setDate(11, new java.sql.Date(now.getTime()));

          System.out.println("...INSERT");
          noUpdated = pstmtInsert.executeUpdate();
          System.out.println("...INSERT OK");
          pstmtInsert.close();

          // send MQ to host for transaction limit, create

          if (paramName.equals("dailytxnlimit")) {

            java.util.Date datenow = new java.util.Date();
            String stringNow = DateUtil.formatDateTimeDash(datenow);

            String stringDate =
                stringNow.substring(0, 4) + stringNow.substring(5, 7) + stringNow.substring(8, 10);
            String stringTime =
                stringNow.substring(11, 13)
                    + stringNow.substring(14, 16)
                    + stringNow.substring(17, 19);

            String header =
                "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
            String messageCode = "ALM";
            String translimitValue = formatMMENumber(paramValue, 15);

            /* Remark for Mandiri
            								String insertSqlMQ ="INSERT INTO TBLMQMESSAGE (ACTIONDATE, ACTIONTIME, HOST_FLAG, MESSAGE, LOG_PATH, FILE_COUNT, LOG_FILE_APPEND, LOG_FILE_PATTERN, QUEUE_NAME) VALUES (?,?,?,?,?,?,?,?,?)";

            								pstmtInsertMQ = connection.prepareStatement(insertSqlMQ.toString());

            								pstmtInsertMQ.setString(1, stringDate);
            								pstmtInsertMQ.setString(2, stringTime);
            								pstmtInsertMQ.setString(3, "0");
            								pstmtInsertMQ.setString(4, header + messageCode + translimitValue);
            								pstmtInsertMQ.setString(5, Constants.PARAMETER_LOG_PATH);
            								pstmtInsertMQ.setString(6, Constants.PARAMETER_FILE_COUNT);
            								pstmtInsertMQ.setString(7, Constants.PARAMETER_LOG_FILE_APPEND);
            								pstmtInsertMQ.setString(8, Constants.PARAMETER_LOG_FILE_PATTERN);
            								pstmtInsertMQ.setString(9, Constants.PARAMETER_QUEUE_NAME);

            */
            System.out.println(
                "**********************************************************************");

            System.out.println(paramValue);

            // pstmtInsertMQ.executeUpdate();

          }

          // end send MQ to host for transaction limit, create

        } else {
          updateSql.delete(0, updateSql.length());
          updateSql.append("Update ").append(Constants.DB_TBL_PARAMETERS);
          updateSql.append(" SET PARAM_VALUE = ?,  CREATED_BY = ?, CREATED_DATE = ? ");
          updateSql.append(" Where PARAM_TYPE = ? and PARAM_NAME = ? and MER_NAME = ? ");

          pstmtUpdate = connection.prepareStatement(updateSql.toString());
          pstmtUpdate.setString(1, paramValue);
          pstmtUpdate.setString(2, loginId);
          pstmtUpdate.setDate(3, new java.sql.Date(now.getTime()));
          pstmtUpdate.setString(4, paramType);
          pstmtUpdate.setString(5, paramName);
          pstmtUpdate.setString(6, merchantName);

          System.out.println("...UPDATE");
          noUpdated = pstmtUpdate.executeUpdate();
          pstmtUpdate.close();
          System.out.println("...UPDATE OK");

          // send MQ to host for transaction limit, update

          if (paramName.equals("dailytxnlimit")) {

            java.util.Date datenow = new java.util.Date();
            String stringNow = DateUtil.formatDateTimeDash(datenow);

            String stringDate =
                stringNow.substring(0, 4) + stringNow.substring(5, 7) + stringNow.substring(8, 10);
            String stringTime =
                stringNow.substring(11, 13)
                    + stringNow.substring(14, 16)
                    + stringNow.substring(17, 19);

            String header =
                "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
            String messageCode = "ULM";
            String translimitValue = formatMMENumber(paramValue, 15);

            String insertSqlMQ =
                "INSERT INTO TBLMQMESSAGE (ACTIONDATE, ACTIONTIME, HOST_FLAG, MESSAGE, LOG_PATH, FILE_COUNT, LOG_FILE_APPEND, LOG_FILE_PATTERN, QUEUE_NAME) VALUES (?,?,?,?,?,?,?,?,?)";
            /* 20130225-Remark for Mandiri
            								pstmtInsertMQ = connection.prepareStatement(insertSqlMQ.toString());

            								pstmtInsertMQ.setString(1, stringDate);
            								pstmtInsertMQ.setString(2, stringTime);
            								pstmtInsertMQ.setString(3, "0");
            								pstmtInsertMQ.setString(4, header + messageCode + translimitValue);
            								pstmtInsertMQ.setString(5, Constants.PARAMETER_LOG_PATH);
            								pstmtInsertMQ.setString(6, Constants.PARAMETER_FILE_COUNT);
            								pstmtInsertMQ.setString(7, Constants.PARAMETER_LOG_FILE_APPEND);
            								pstmtInsertMQ.setString(8, Constants.PARAMETER_LOG_FILE_PATTERN);
            								pstmtInsertMQ.setString(9, Constants.PARAMETER_QUEUE_NAME);
            								pstmtInsertMQ.executeUpdate();
            */
          }

          //// end send MQ to host for transaction limit, update
        }

        if (noUpdated < 1) {
          success = false;
          break;
        }
      } // end while loop

    } catch (SQLException sqle) {
      success = false;
      EnhancedException ex = new EnhancedException(sqle.toString());
      ex.setExceptionLocation("ParamHome.saveParams() ");
      ex.setExtraMessage("SQLException Encountered");
      sysLogMgr.logError(ex);
      sqle.printStackTrace();
    } catch (Exception e) {
      success = false;
      EnhancedException ex = new EnhancedException(e.toString());
      ex.setExceptionLocation("ParamHome.saveParams() ");
      ex.setExtraMessage("Exception Encountered");
      sysLogMgr.logError(ex);
      e.printStackTrace();
    } catch (Throwable t) {
      success = false;
      EnhancedException ex = new EnhancedException(t.toString());
      ex.setExceptionLocation("ParamHome.saveParams() ");
      ex.setExtraMessage("Throwable Encountered");
      sysLogMgr.logError(ex);
      t.printStackTrace();
    } finally {

      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException e1) {
        }
      }

      if (pstmtQuery != null) {
        try {
          pstmtQuery.close();
        } catch (SQLException e1) {
        }
      }

      if (pstmtInsert != null) {
        try {
          pstmtInsert.close();
        } catch (SQLException e1) {
        }
      }

      if (pstmtUpdate != null) {
        try {
          pstmtUpdate.close();
        } catch (SQLException e1) {
        }
      }

      dba.freeDBConnection(connection);
    }

    return success;
  }
Exemple #2
0
  /** added by ronnie for insert Parameter into database(20090122) updated by Lue 20090916 */
  public boolean saveParam(
      String merchantName, String loginId, String paramType, String paramKey, String paramValue) {
    boolean success = true;
    Connection connection = null;
    SystemLogManager sysLogMgr = SystemLogManager.getInstance();
    ;
    DBAccessHome dba = DBAccessHome.getInstance();

    StringBuffer querySql = new StringBuffer("");
    StringBuffer insertSql = new StringBuffer("");
    StringBuffer updateSql = new StringBuffer("");

    PreparedStatement pstmtInsert = null;
    PreparedStatement pstmtQuery = null;
    PreparedStatement pstmtUpdate = null;

    ResultSet rs = null;
    int noUpdated = 0;

    try {

      connection = dba.getDBConnection();

      if (loginId == null
          || merchantName == null
          || paramType == null
          || paramKey == null
          || paramValue == null
          || loginId.trim().equals("")
          || merchantName.trim().equals("")
          || paramType.trim().equals("")
          || paramKey.trim().equals("")
          || paramValue.trim().equals("")) {
        throw new Exception(
            "Merchant Name, User logon ID, Parameter Type, Key or Value is null or blank");
      }

      if (connection == null) {
        System.err.println("ParamHome.saveParam(): DB Connection is null");
        throw new Exception("DB Connection is null");
      }

      boolean found = false;
      querySql.append("select PARAM_VALUE from ").append(Constants.DB_TBL_PARAMETERS);
      querySql.append(" Where PARAM_TYPE = ? and PARAM_NAME = ? ");

      pstmtQuery = connection.prepareStatement(querySql.toString());
      pstmtQuery.setString(1, paramType);
      pstmtQuery.setString(2, paramKey);

      rs = pstmtQuery.executeQuery();

      if (rs.next()) {
        found = true;
      }

      rs.close();
      pstmtQuery.close();

      java.util.Date now = new java.util.Date();

      if (!found) {

        insertSql.append("INSERT INTO ").append(Constants.DB_TBL_PARAMETERS);
        insertSql.append(
            " (MER_NAME, PARAM_TYPE, PARAM_CODE, PARAM_NAME, PARAM_VALUE, PARAM_1, PARAM_2, PARAM_3, PARAM_4, CREATED_BY, CREATED_DATE) ");
        insertSql.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ");

        pstmtInsert = connection.prepareStatement(insertSql.toString());
        pstmtInsert.setString(1, merchantName);
        pstmtInsert.setString(2, paramType);
        pstmtInsert.setString(3, "");
        pstmtInsert.setString(4, paramKey);
        pstmtInsert.setString(5, paramValue);
        pstmtInsert.setString(6, "");
        pstmtInsert.setString(7, "");
        pstmtInsert.setString(8, "");
        pstmtInsert.setString(9, "");
        pstmtInsert.setString(10, loginId);
        pstmtInsert.setDate(11, new java.sql.Date(now.getTime()));

        noUpdated = pstmtInsert.executeUpdate();
        pstmtInsert.close();
      } else {
        updateSql.append("Update ").append(Constants.DB_TBL_PARAMETERS);
        updateSql.append(" SET PARAM_VALUE = ?,  CREATED_BY = ?, CREATED_DATE = ? ");
        updateSql.append(" Where PARAM_TYPE = ? and PARAM_NAME = ? and MER_NAME = ? ");

        pstmtUpdate = connection.prepareStatement(updateSql.toString());
        pstmtUpdate.setString(1, paramValue);
        pstmtUpdate.setString(2, loginId);
        pstmtUpdate.setDate(3, new java.sql.Date(now.getTime()));
        pstmtUpdate.setString(4, paramType);
        pstmtUpdate.setString(5, paramKey);
        pstmtUpdate.setString(6, merchantName);

        noUpdated = pstmtUpdate.executeUpdate();
        pstmtUpdate.close();
      }

      if (noUpdated < 1) {
        success = false;
      }

    } catch (SQLException sqle) {
      success = false;
      EnhancedException ex = new EnhancedException(sqle.toString());
      ex.setExceptionLocation("ParamHome.saveParam() ");
      ex.setExtraMessage("SQLException Encountered");
      sysLogMgr.logError(ex);
    } catch (Exception e) {
      success = false;
      EnhancedException ex = new EnhancedException(e.toString());
      ex.setExceptionLocation("ParamHome.saveParam() ");
      ex.setExtraMessage("Exception Encountered");
      sysLogMgr.logError(ex);
    } catch (Throwable t) {
      success = false;
      EnhancedException ex = new EnhancedException(t.toString());
      ex.setExceptionLocation("ParamHome.saveParam() ");
      ex.setExtraMessage("Throwable Encountered");
      sysLogMgr.logError(ex);
    } finally {

      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException e1) {
        }
      }

      if (pstmtQuery != null) {
        try {
          pstmtQuery.close();
        } catch (SQLException e1) {
        }
      }

      if (pstmtInsert != null) {
        try {
          pstmtInsert.close();
        } catch (SQLException e1) {
        }
      }

      if (pstmtUpdate != null) {
        try {
          pstmtUpdate.close();
        } catch (SQLException e1) {
        }
      }

      dba.freeDBConnection(connection);
    }

    return success;
  }