コード例 #1
0
  /** Load the data from the defined Data Source DB */
  @Override
  public void loadDataFromDB() throws InitializationException {
    int custId;
    String orderId;
    String orderLineId;
    String alias;
    String description;
    String prodName;
    String service;
    String subscription;
    int custLoaded = 0;
    String tmpStartDate;
    String tmpEndDate;
    long startDate = 0;
    long endDate = 0;
    String tmpQuantity;
    int quantity;

    // Log that we are starting the loading
    OpenRate.getOpenRateFrameworkLog()
        .info("Starting Customer Cache Loading from DB for <" + getSymbolicName() + ">");

    // Try to open the DS
    JDBCcon = DBUtil.getConnection(cacheDataSourceName);

    // Now prepare the statements
    prepareStatements();

    // Execute the query
    try {
      mrs = StmtCustomerDataSelectQuery.executeQuery();
    } catch (SQLException ex) {
      message =
          "Error performing SQL for retieving Customer data. message <" + ex.getMessage() + ">";
      throw new InitializationException(message, ex, getSymbolicName());
    }

    // loop through the results for the customer alias cache
    try {
      mrs.beforeFirst();

      while (mrs.next()) {
        custLoaded++;
        orderId = mrs.getString(1);
        custId = mrs.getInt(2);
        orderLineId = mrs.getString(3);
        description = mrs.getString(4);
        tmpStartDate = mrs.getString(5);
        tmpEndDate = mrs.getString(6);
        tmpQuantity = mrs.getString(7);

        // parse the description
        prodName = getProduct(description);
        alias = getAlias(description);
        service = getService(description);
        subscription = getSubscription(description);

        if ((prodName == null) | (alias == null) | (service == null) | (subscription == null)) {
          OpenRate.getOpenRateFrameworkLog()
              .warning(
                  "Record <"
                      + description
                      + "> skipped for customer <"
                      + custId
                      + "> order <"
                      + orderId
                      + ">.");
          continue;
        }

        // parse the start date
        try {
          if (tmpStartDate == null) {
            startDate = CommonConfig.LOW_DATE;
          } else {
            startDate = conv.convertInputDateToUTC(tmpStartDate);
          }
        } catch (ParseException ex) {
          OpenRate.getOpenRateFrameworkLog()
              .error(
                  "Start Date format for record <"
                      + custLoaded
                      + "> are not correct. Date <"
                      + tmpStartDate
                      + ">, format <"
                      + conv.getInputDateFormat()
                      + "> order <"
                      + orderId
                      + ">. Data discarded.");
        }

        // parse the end date
        try {
          if (tmpEndDate == null) {
            endDate = CommonConfig.HIGH_DATE;
          } else {
            endDate = conv.convertInputDateToUTC(tmpEndDate);
          }
        } catch (ParseException ex) {
          OpenRate.getOpenRateFrameworkLog()
              .error(
                  "End Date format for record <"
                      + custLoaded
                      + "> are not correct. Date <"
                      + tmpEndDate
                      + ">, format <"
                      + conv.getInputDateFormat()
                      + "> order <"
                      + orderId
                      + ">. Data discarded.");
        }

        // parse the Quantity
        quantity = Integer.parseInt(tmpQuantity);

        // print the information to the log
        OpenRate.getOpenRateFrameworkLog()
            .info(
                "Adding service ID <"
                    + alias
                    + "> to account <"
                    + custId
                    + "> with product <"
                    + prodName
                    + "> validity <"
                    + tmpStartDate
                    + " ("
                    + startDate
                    + ") - "
                    + tmpEndDate
                    + " ("
                    + endDate
                    + ")>, Qty: <"
                    + quantity
                    + "> order <"
                    + orderId
                    + ">.");

        // Add the map
        addAlias(alias, custId, startDate, endDate);
        addCustId(custId, CommonConfig.LOW_DATE, CommonConfig.HIGH_DATE, 0);
        addCPI(
            custId,
            service,
            subscription,
            prodName,
            startDate,
            endDate,
            Integer.parseInt(orderId),
            Integer.parseInt(orderLineId),
            quantity);
      }
    } catch (SQLException ex) {
      message = "Error opening Customer Data for <" + cacheDataSourceName + ">";
      throw new InitializationException(message, ex, getSymbolicName());
    }

    // Close down stuff
    try {
      mrs.close();
      StmtCustomerDataSelectQuery.close();
      JDBCcon.close();
    } catch (SQLException ex) {
      message =
          "Error closing Result Set for Customer information from <" + cacheDataSourceName + ">";
      throw new InitializationException(message, ex, getSymbolicName());
    }

    OpenRate.getOpenRateFrameworkLog()
        .info("Customer Cache Data Loading completed from <" + cacheDataSourceName + ">");

    OpenRate.getOpenRateFrameworkLog().info("Products Loaded:  " + custLoaded);
  }
コード例 #2
0
  /**
   * Load the data from the defined Data Source
   *
   * @throws OpenRate.exception.InitializationException
   */
  @Override
  public void loadDataFromDB() throws InitializationException {
    int ColumnIdx;
    int ColumnCount;
    int ConfigsLoaded = 0;
    String Group;
    ResultSetMetaData Rsmd;
    String[] SearchMapFields;
    int ResultFormFactor = 0;
    ArrayList<String> tmpResultList;

    // Find the location of the  zone configuration file
    OpenRate.getOpenRateFrameworkLog()
        .info("Starting Regex Match Cache Loading from DB for <" + getSymbolicName() + ">");

    // Try to open the DS
    JDBCcon = DBUtil.getConnection(cacheDataSourceName);

    // Now prepare the statements
    prepareStatements();

    // Execute the query
    try {
      mrs = StmtCacheDataSelectQuery.executeQuery();
    } catch (SQLException ex) {
      message =
          "Error performing SQL for retrieving Regex Match data in module <"
              + getSymbolicName()
              + ">. message <"
              + ex.getMessage()
              + ">";
      OpenRate.getOpenRateFrameworkLog().fatal(message);
      throw new InitializationException(message, getSymbolicName());
    }

    // loop through the results for the customer login cache
    try {
      Rsmd = mrs.getMetaData();
      ColumnCount = Rsmd.getColumnCount();

      // Read the form factor from the first entry, and then make sure
      // that we always get this
      if (ResultFormFactor == 0) {
        // Check that this is a form factor we are able to use. There
        // must be at least 3 fields for us to be able to work with
        // the record:
        //  - Group identifier
        //  - Some fields to compare (min 1)
        //  - a result
        if (ColumnCount < 3) {
          // we're not going to be able to use this
          message =
              "You must define at least 3 entries in the record, you have defined  <"
                  + ColumnCount
                  + ">";
          OpenRate.getOpenRateFrameworkLog().fatal(message);
          throw new InitializationException(message, getSymbolicName());
        }

        // Do we have a defined form factor?
        if (KeyFormFactor == 0) {
          // If we have not been given a key form factor, assume the result factor is 1
          ResultFormFactor = 1;
          KeyFormFactor = ColumnCount - ResultFormFactor - 1;
          message =
              "Using default key factor for regex cache <"
                  + cacheDataSourceName
                  + ">. Assuming Key = <"
                  + Integer.toString(KeyFormFactor)
                  + "> and Result = <"
                  + Integer.toString(ResultFormFactor)
                  + ">";
          OpenRate.getOpenRateFrameworkLog().info(message);
        } else {
          // Use the given factor
          ResultFormFactor = ColumnCount - KeyFormFactor - 1;

          if (ResultFormFactor < 1) {
            // Makes no sense to start if we don't give any results
            message =
                "Error in module <"
                    + cacheDataSourceName
                    + ">. Key fields >= total columns. Got KeyFields <"
                    + KeyFormFactor
                    + "> and columns <"
                    + ColumnCount
                    + ">";
            OpenRate.getOpenRateFrameworkLog().fatal(message);
            throw new InitializationException(message, getSymbolicName());
          }

          message =
              "Using defined key factor for regex cache <"
                  + getSymbolicName()
                  + ">. Using Key = <"
                  + Integer.toString(KeyFormFactor)
                  + "> and Result = <"
                  + Integer.toString(ResultFormFactor)
                  + ">";
          OpenRate.getOpenRateFrameworkLog().info(message);
        }
      }

      // Start the loading
      mrs.beforeFirst();
      while (mrs.next()) {
        ConfigsLoaded++;
        Group = mrs.getString(1);

        SearchMapFields = new String[KeyFormFactor];

        // create the array to transfer the columns into the map
        for (ColumnIdx = 1; ColumnIdx < KeyFormFactor + 1; ColumnIdx++) {
          SearchMapFields[ColumnIdx - 1] = mrs.getString(ColumnIdx + 1);
        }

        tmpResultList = new ArrayList<>();
        for (ColumnIdx = KeyFormFactor + 1;
            ColumnIdx < (ResultFormFactor + KeyFormFactor + 1);
            ColumnIdx++) {
          tmpResultList.add(mrs.getString(ColumnIdx + 1));
        }

        // Add the map
        addEntry(Group.intern(), SearchMapFields, tmpResultList);

        // Update to the log file
        if ((ConfigsLoaded % loadingLogNotificationStep) == 0) {
          message =
              "Regex Map Data Loading: <"
                  + ConfigsLoaded
                  + "> configurations loaded for <"
                  + getSymbolicName()
                  + "> from <"
                  + cacheDataSourceName
                  + ">";
          OpenRate.getOpenRateFrameworkLog().info(message);
        }
      }
    } catch (SQLException ex) {
      message = "Error opening Search Map Data for <" + getSymbolicName() + ">";
      OpenRate.getOpenRateFrameworkLog().fatal(message);
      throw new InitializationException(message, ex, getSymbolicName());
    } catch (NullPointerException ex) {
      message =
          "Error opening Search Map Data for <"
              + getSymbolicName()
              + "> in config <"
              + ConfigsLoaded
              + ">";
      OpenRate.getOpenRateFrameworkLog().fatal(message);
      throw new InitializationException(message, ex, getSymbolicName());
    }

    // Close down stuff
    try {
      mrs.close();
      StmtCacheDataSelectQuery.close();
      JDBCcon.close();
    } catch (SQLException ex) {
      message = "Error closing Search Map Data connection for <" + cacheDataSourceName + ">";
      OpenRate.getOpenRateFrameworkLog().fatal(message);
      throw new InitializationException(message, getSymbolicName());
    }

    message =
        "Regex Map Data Loading completed. <"
            + ConfigsLoaded
            + "> configuration lines loaded for <"
            + getSymbolicName()
            + "> from <"
            + cacheDataSourceName
            + ">";
    OpenRate.getOpenRateFrameworkLog().info(message);
  }