我对使用 IBM i(AS/400)很陌生。我想通过 JTOpen/JT400 编写一个 DDM 文件。这是我已经做的,使用 jtopenlite.jar 中的类从这里http://sourceforge.net/projects/jt400/files/JTOpen-full/8.5/
final String HELLO_WORLD = "Hello World";
final String LOREM_IPSUM_DOLORES = "lorem ipsum dolores";
String library = "KEKRU1";
String file = "QRPGLESRC3";
String member = "DDSTEST2";
DDMConnection connection = DDMConnection.getConnection("myas400.de", "username", "password");
DDMRecordFormat recordFormat = connection.getRecordFormat(library, file);
DDMWriteCallback writeCallback = new DDMWriteCallback() {
@Override
public int getRecordDataOffset(DDMCallbackEvent event, int recordIndex) {
System.out.println(recordIndex);
return 0;
}
@Override
public byte[] getRecordData(DDMCallbackEvent event, int recordIndex) {
byte[] result = new byte[120]; //120 is the ddmfile.getRecordLength()
byte[] src;
if (recordIndex == 0){
src = HELLO_WORLD.getBytes();
}else{
src = LOREM_IPSUM_DOLORES.getBytes();
}
System.arraycopy(src, 0, result, 0, src.length); //Copy from src to result
return result;
}
@Override
public int getNumberOfRecords(DDMCallbackEvent event) {
return 2;
}
@Override
public boolean[] getNullFieldValues(DDMCallbackEvent event, int recordIndex) {
return null;
}
};
DDMFile ddmFile = connection.open(library, file, member, recordFormat.getName(), DDMFile.WRITE_ONLY, false, 10, 1);
System.out.println(ddmFile.getRecordLength()); //prints 120
connection.write(ddmFile, writeCallback);
connection.close();
程序进入connection.write(ddmFile, writeCallback); 将数据写入流并最终到达 handleReply(file, "ddmS38PUTM", null); (在 connection.write 内)等待服务器的回答。
这是库中的 write 方法
public class DDMConnection extends HostServerConnection
{
...
public void write(DDMFile file, DDMWriteCallback listener) throws IOException
{
final DDMCallbackEvent event = file.getEventBuffer();
event.setEventType(DDMCallbackEvent.EVENT_WRITE);
int blockingFactor = file.getBatchSize();
int numRecords = listener.getNumberOfRecords(event);
int startingRecordNumber = 0;
int batchSize = numRecords > blockingFactor ? blockingFactor : numRecords;
int id = newCorrelationID();
while (startingRecordNumber < numRecords)
{
if (startingRecordNumber+batchSize >= numRecords) batchSize = numRecords-startingRecordNumber;
sendS38PUTMRequest(out_, file.getDCLNAM(), id);
sendS38BUFRequest(file, out_, id, file.getRecordIncrement(), listener, file.getRecordLength(), startingRecordNumber, batchSize);
out_.flush();
handleReply(file, "ddmS38PUTM", null); //here the program waits for the server
startingRecordNumber += batchSize;
}
}
}
但是服务器不发送任何东西。
您对编写 DDM 文件有什么建议或其他方式吗?