示例#1
0
  /**
   * Returns the value of the "list status indicator" field returned by QGY* API's.
   *
   * @param listInformation The "list information" structure returned by a QGY* API (that requested
   *     the building of a list).
   * @return The converted value of the "list status information" field. Possible values are '0',
   *     '1', '2', '3', '4', or '5'.
   * @throws ErrorCompletingRequestException if the List Status Information is other than
   *     "complete", "being built", or "pending"; or if the Information Complete Indicator is
   *     "interrupted".
   */
  private static char checkListStatus(byte[] listInformation)
      throws ErrorCompletingRequestException {
    char infoCompleteIndicator, listStatusIndicator;
    try {
      // Convert the two CHAR(1) fields from EBCDIC to Unicode.
      byte[] arry = {listInformation[16]}; // ICI is at offset 16
      infoCompleteIndicator = new CharConverter(37).byteArrayToString(arry, 0, 1).charAt(0);
      arry[0] = listInformation[30]; // LSI is at offset 30
      listStatusIndicator = new CharConverter(37).byteArrayToString(arry, 0, 1).charAt(0);
    } catch (java.io.UnsupportedEncodingException e) { // will never happen
      throw new InternalErrorException(InternalErrorException.UNEXPECTED_EXCEPTION, e.getMessage());
    }

    switch (listStatusIndicator) {
      case LIST_COMPLETE:
        break; // This is the indicator that we normally expect.

      case LIST_BEING_BUILT:
      case LIST_PENDING:
        // These status values are unusual, but aren't necessarily error conditions
        // (even if we indicated we wanted the list built synchronously).
        if (Trace.traceOn_)
          Trace.log(Trace.DIAGNOSTIC, "List status indicator:", listStatusIndicator);
        break;

      default: // any other status
        StringBuffer msg = new StringBuffer("Unable to synchronously build object list on server.");

        try {
          msg.append("\n  List status indicator: " + listStatusIndicator);
          msg.append("\n  Info complete indicator: " + infoCompleteIndicator);
          msg.append("\n  Total records:    " + BinaryConverter.byteArrayToInt(listInformation, 0));
          msg.append("\n  Records returned: " + BinaryConverter.byteArrayToInt(listInformation, 4));
        } catch (Throwable t) {
        } // will never happen
        finally {
          Trace.log(Trace.ERROR, msg.toString());
        }
        throw new ErrorCompletingRequestException(ErrorCompletingRequestException.AS400_ERROR);
    }

    if (infoCompleteIndicator == INFORMATION_INTERRUPTED) {
      Trace.log(Trace.ERROR, "Info complete indicator: " + infoCompleteIndicator);
      throw new ErrorCompletingRequestException(ErrorCompletingRequestException.AS400_ERROR);
    }

    return listStatusIndicator;
  }
示例#2
0
  public void convertFromRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter) // @P0C
      throws SQLException {
    value_ = BinaryConverter.byteArrayToInt(rawBytes, offset); // @D0C

    if (scale_ > 0) { // @C0A
      bigDecimalValue_ = (new BigDecimal(Integer.toString(value_))).movePointLeft(scale_); // @A0A
      value_ = bigDecimalValue_.intValue(); // @A0A
    } // @C0A
  }
 public void convertFromRawBytes(
     byte[] rawBytes, int offset, ConvTable ccsidConverter, boolean ignoreConversionErrors)
     throws SQLException {
   int locatorHandle = BinaryConverter.byteArrayToInt(rawBytes, offset);
   locator_.setHandle(locatorHandle);
   locator_.setColumnIndex(columnIndex_);
   // @J5A reset saved handle after setting new value
   savedObject_ = null;
 }
示例#4
0
  /**
   * Calls QGYGTLE, repeatedly if necessary, to retrieve the specified number of list entries. This
   * assumes that the list has previously been built on the system.
   *
   * @param system The system where the list has been built.
   * @param listHandle The list handle for the list.
   * @param lengthOfReceiverVariable The value of the "Length of receiver variable" field.
   * @param number The number of list entries to return.
   * @param listOffset The offset into the list (0-based).
   * @param outputListInfoContainer Container in which to receive the generated "List information"
   *     structure. Ignored if null.
   */
  static byte[] retrieveListEntries(
      AS400 system,
      byte[] listHandle,
      int lengthOfReceiverVariable,
      int number,
      int listOffset,
      Object[] outputListInfoContainer)
      throws AS400SecurityException, ErrorCompletingRequestException, InterruptedException,
          IOException, ObjectDoesNotExistException {
    ProgramParameter[] parameters =
        new ProgramParameter[] {
          // Receiver variable, output, char(*).
          new ProgramParameter(lengthOfReceiverVariable),
          // Length of receiver variable, input, binary(4).
          new ProgramParameter(BinaryConverter.intToByteArray(lengthOfReceiverVariable)),
          // Request handle, input, char(4).
          new ProgramParameter(listHandle),
          // List information, output, char(80).
          new ProgramParameter(LIST_INFO_LENGTH),
          // Number of records to return, input, binary(4).
          new ProgramParameter(BinaryConverter.intToByteArray(number)),

          // Starting record, input, binary(4).  (1-based: The first record is record number '1')
          // '0' indicates that the list information should be returned to the caller immediately.
          // The special value 0 is only allowed when the number of records to return parameter is
          // zero.
          // '-1' indicates that the whole list should be built before the list information is
          // returned to the caller.
          new ProgramParameter(
              BinaryConverter.intToByteArray(listOffset == -1 ? -1 : listOffset + 1)),

          // Error code, I/0, char(*).
          new ErrorCodeParameter()
        };

    ProgramCall pc =
        new ProgramCall(
            system, "/QSYS.LIB/QGY.LIB/QGYGTLE.PGM", parameters); // not a threadsafe API

    byte[] listInformation;
    int recordsReturned;

    // Call QGYGTLE, to retrieve the list entries.
    // If we discover that the "receiver variable" was too small, try calling again, with
    // progressively larger "receiver variable".
    do {
      if (pc.run()) {
        listInformation = parameters[3].getOutputData();
        checkListStatus(listInformation);
        recordsReturned = BinaryConverter.byteArrayToInt(listInformation, 4);
      } else // the call to QGYGTLE failed
      {
        listInformation = null;
        recordsReturned = 0;
        // See if the call failed because of a too-small receiver variable.
        AS400Message[] messages = pc.getMessageList();
        // GUI0002 means that the receiver variable was too small to hold the list.
        if (!messages[0].getID().equals("GUI0002")) {
          throw new AS400Exception(messages);
        }
      }

      if (recordsReturned < number) // we didn't get as many records as we requested
      {
        if (listInformation != null) {
          // See if we've reached the end of the list.
          int totalRecords =
              BinaryConverter.byteArrayToInt(
                  listInformation, 0); // The total number of records available in the list.
          int firstRecordInReceiverVariable = BinaryConverter.byteArrayToInt(listInformation, 36);

          // Note: The "First record in receiver variable" field is 1-based; that is, the first
          // record is record number '1' (rather than '0').
          if ((firstRecordInReceiverVariable + recordsReturned) > totalRecords) {
            // All the records in the list have been returned, so don't keep requesting more.
            break;
          }
        }

        if (Trace.traceOn_)
          Trace.log(
              Trace.DIAGNOSTIC,
              "Retrieved messages, records returned: " + recordsReturned + ", number:",
              number);
        if (recordsReturned < 0) { // This will never happen, but satisfy the static code analyzer.
          throw new InternalErrorException(
              InternalErrorException.UNKNOWN, "Records returned: " + recordsReturned);
        }
        // Try again, with a larger "receiver variable".
        lengthOfReceiverVariable *= 1 + number / (recordsReturned + 1);
        if (Trace.traceOn_)
          Trace.log(Trace.DIAGNOSTIC, "Updated length: ", lengthOfReceiverVariable);
        parameters[0] = new ProgramParameter(lengthOfReceiverVariable);
        parameters[1] =
            new ProgramParameter(BinaryConverter.intToByteArray(lengthOfReceiverVariable));
      }
    } while (recordsReturned < number);

    // If the caller specified a non-null 'outputListInfo' parameter, copy the "list information"
    // structure into it, to pass it back to the caller.
    if (outputListInfoContainer != null && listInformation != null) {
      outputListInfoContainer[0] = listInformation;
    }

    return parameters[0].getOutputData(); // the contents of the "receiver variable" field
  }
示例#5
0
 public void convertFromRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter)
     throws SQLException {
   int locatorHandle = BinaryConverter.byteArrayToInt(rawBytes, offset);
   locator_.setHandle(locatorHandle);
   locator_.setColumnIndex(columnIndex_);
 }
 public int getConsistencyToken() {
   return BinaryConverter.byteArrayToInt(rawBytes_, offset_);
 }