Пример #1
0
  public boolean createTable() {
    List<String> databaseCreationSqlStatements = new ArrayList<>();

    if (DatabaseConfiguration.getType() == DatabaseConfiguration.MYSQL) {
      databaseCreationSqlStatements.add(NotificationGroupsSql.CreateTable_NotificationGroups_MySQL);
    } else {
      databaseCreationSqlStatements.add(NotificationGroupsSql.CreateTable_NotificationGroups_Derby);
      databaseCreationSqlStatements.add(
          NotificationGroupsSql.CreateIndex_NotificationGroups_PrimaryKey);
    }

    databaseCreationSqlStatements.add(
        NotificationGroupsSql.CreateIndex_NotificationGroups_Unique_Name);
    databaseCreationSqlStatements.add(
        NotificationGroupsSql.CreateIndex_NotificationGroups_Unique_UppercaseName);

    return createTable(databaseCreationSqlStatements);
  }
Пример #2
0
  public JSONObject getNotificationGroups(int offset, int pageSize) {
    logger.debug("getNotificationGroups");
    List<Object> parametersList = new ArrayList<>(2);

    JSONArray notificationGroupsList = new JSONArray();
    JSONObject notificationGroupsJson = new JSONObject();
    int alertsCount = 0;

    try {
      if (!isConnectionValid()) {
        return null;
      }

      if ((offset == 0) && (pageSize == 0)) {
        notificationGroupsJson.put("notificationgroups", notificationGroupsList);
        notificationGroupsJson.put("count", alertsCount);
        return notificationGroupsJson;
      }

      parametersList.add(offset);
      parametersList.add(pageSize);

      if (DatabaseConfiguration.getType() == DatabaseConfiguration.MYSQL) {
        databaseInterface_.createPreparedStatement(
            NotificationGroupsSql.Select_NotificationGroups_ByPageNumberAndPageSize_MySQL,
            pageSize);
      } else {
        databaseInterface_.createPreparedStatement(
            NotificationGroupsSql.Select_NotificationGroups_ByPageNumberAndPageSize_Derby,
            pageSize);
      }
      databaseInterface_.addPreparedStatementParameters(parametersList);

      databaseInterface_.executePreparedStatement();

      if (!databaseInterface_.isResultSetValid()) {
        logger.debug("Invalid resultset");
        return null;
      }

      ResultSet resultSet = databaseInterface_.getResults();

      while (resultSet.next()) {
        JSONObject alert = new JSONObject();
        alert.put("name", resultSet.getString("NAME"));
        alert.put("id", resultSet.getString("ID"));
        notificationGroupsList.add(alert);
        alertsCount++;
      }

      notificationGroupsJson.put("notificationgroups", notificationGroupsList);
      notificationGroupsJson.put("count", alertsCount);

      return notificationGroupsJson;
    } catch (Exception e) {
      logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
      return null;
    } finally {
      databaseInterface_.cleanupAutomatic();
    }
  }