// @CRS - This is only called from AS400JDBCPreparedStatement in one place. public void convertToRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter) throws SQLException { BinaryConverter.intToByteArray(locator_.getHandle(), rawBytes, offset); // Now we write our saved data to the system, because the prepared statement is being executed. // We used to write the data to the system on the call to set(), but this messed up // batch executes, since the host server only reserves temporary space for locator handles one // row at a time. // See the toObject() method in this class for more details. if (savedObject_ != null) writeToServer(); }
// Calls QGYGTLE to get the current "list information" on the progress of list-building. private static byte[] refreshListInformation(byte[] listHandle, ProgramCall pgmCall) throws AS400SecurityException, ErrorCompletingRequestException, InterruptedException, IOException, ObjectDoesNotExistException { if (pgmCall.getParameterList().length == 0) { ProgramParameter[] parameters = new ProgramParameter[] { // Receiver variable, output, char(*). new ProgramParameter(8), // minimum length is 8 bytes // Length of receiver variable, input, binary(4). new ProgramParameter(BinaryConverter.intToByteArray(8)), // 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). // '0' indicates: "Only the list information is returned and no actual list entries are // returned." new ProgramParameter(new byte[] {0x00, 0x00, 0x00, 0x00}), // Starting record, input, binary(4). // '0' indicates: "The list information should be returned to the caller immediately." // '-1' indicates: "The whole list should be built before the list information is // returned to the caller." // new ProgramParameter(new byte[] { 0x00, 0x00, 0x00, 0x00} ), new ProgramParameter(new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}), // Error code, I/0, char(*). new ErrorCodeParameter() }; try { pgmCall.setProgram("/QSYS.LIB/QGY.LIB/QGYGTLE.PGM", parameters); } catch (java.beans.PropertyVetoException pve) { } // will never happen } if (!pgmCall.run()) { throw new AS400Exception(pgmCall.getMessageList()); } return pgmCall.getParameterList()[3].getOutputData(); // the "List Information" structure }
public void convertToRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter) // @P0C throws SQLException { BinaryConverter.intToByteArray(value_, rawBytes, offset); // @D0C }
/** * 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 }
public void setConsistencyToken(int consistencyToken) { BinaryConverter.intToByteArray(consistencyToken, rawBytes_, offset_); }