示例#1
0
  /**
   * Static method to setup the execution order. This method essentially looks up in to the setup
   * table BATCH_COLUMN_MAP to get the details.Using the details it would setup the execution order
   * for the batch Once the execution order is set, it sets the order into the {@link
   * BatchInfo#setOrderedMap(TreeMap)} for all other objects to derive knowledge from. Note: The
   * batch could be run for -
   *
   * <OL>
   *   <LI>For a date i.e. all entities and all values for those entities.
   *   <LI>For an entity i.e. batch for only policy records and all its values i.e. P1, P2 ... Pn
   *   <LI>For a single object identified as GENERAL type of job with a sequence number i.e.
   *       JOB_SCHEDULE.job_seq
   *   <LI>For only Meta events like ALL PRE and ALL POST
   *   <LI>For any combination of above, a few given -
   *       <UL>
   *         <LI>Policy P1 and ALL PRE
   *         <LI>ALL Agency records and Policy P1
   *         <LI>Policy P1 and Agency A1
   *       </UL>
   * </OL>
   *
   * Every step has inline comments associated with it.
   *
   * @param batchContext The context for the batch
   * @return true If the setup is done successfully
   * @throws BatchException Any database I/O exception
   */
  public static synchronized Boolean setExecutionOrder(BatchContext batchContext)
      throws BatchException {

    // Get request parameters
    HashMap<String, Object> params = batchContext.getRequestParams().getProcessRequestParams();

    // Check whether it is a date batch run or specific batch run
    if (params.size() < 1) {
      batchContext.getBatchInfo().setDateRun(true);
    }
    Connection con = batchContext.getBATCHConnection();
    IBatchDao bDao = DaoFactory.getBatchDao();
    try {
      // Query the setup table to get the setup values
      LookupTable lookupTable = bDao.getLookupTable(con);
      Map<String, String> orderByLookupTable = bDao.getOrderByLookupTable(con);

      TreeMap<Integer, EntityParams> orderedMap = new TreeMap<Integer, EntityParams>();

      // If it is date batch run, then for all entities, populate "ALL"
      if (batchContext.getBatchInfo().isDateRun()) {
        Iterator<String> lTableIter = lookupTable.keySet().iterator();
        while (lTableIter.hasNext()) {
          String entity = lTableIter.next();
          params.put(entity + "_1", "ALL");
        }
      }

      // Iterate over each parameters set
      for (Entry<String, Object> entry : params.entrySet()) {
        String paramName = entry.getKey();
        Object paramValue = entry.getValue();
        if (logger.isDebugEnabled()) {
          logger.debug("In ExecutionOrder >>>> paramName  ==>" + paramName);
        }

        String entity = null;

        // Strip the last occurrence of _ and get the entity name
        entity = paramName.substring(0, paramName.lastIndexOf("_"));
        if (logger.isDebugEnabled()) {
          logger.debug("In ExecutionOrder >>>> Entity  ==>" + entity);
        }
        // Validate whether the entity is setup appropriately in
        // the BATCH_COLUMN_MAP table
        if (!lookupTable.containsKey(entity)) {
          // If the entity is not set, raise an exception and exit
          throw new BatchException(
              "The entity " + entity + " is not set up in the COLUMN_MAP table.");
        } else {

          // Get the lookup record
          // Once found, get the details and set it against the entity
          List<ColumnLookup> lookupColumns = lookupTable.get(entity);
          Integer order = lookupColumns.get(0).getPrecedenceOrder();
          if (!orderedMap.containsKey(order)) {
            EntityParams entityParams = new EntityParams(entity);
            orderedMap.put(order, entityParams);
          }
          EntityParams entityParams = orderedMap.get(order);
          entityParams.setLookupColumns(lookupColumns);
          entityParams.setOrderByMap(orderByLookupTable); // Added on 01-OCT-2013 - Mandar

          // Check 'ALL' or for specific entity values.
          // Note: Batch could be run for a date i.e. all entities (and all values)
          // or for any combination of entity and values
          if (!paramValue.equals("ALL")) {
            List<GroupInfo> list = entityParams.getValues();
            // check if all exists. If exists do not write the new value
            if (list.size() == 0 || !list.get(0).getEntityValue().equals("ALL"))
              entityParams.getValues().add(new GroupInfo((String) paramValue));
          } else {
            entityParams.setAll(new GroupInfo((String) paramValue));
          }
        }
      }

      batchContext.getBatchInfo().setOrderedMap(orderedMap);
    } finally {
      bDao.releaseResources(null, null, con);
    }

    return true;
  }