148 lines
7.0 KiB
HTML
148 lines
7.0 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="reference" />
|
|
<meta name="DC.Title" content="Using record blocking" />
|
|
<meta name="abstract" content="" />
|
|
<meta name="description" content="" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="rlablock" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Using record blocking</title>
|
|
</head>
|
|
<body id="rlablock"><a name="rlablock"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Using record blocking</h1>
|
|
<div><p></p>
|
|
<div class="section"><p>The <a href="javadoc/com/ibm/as400/access/AS400File.html#NAVBAR_TOP"> AS400File</a> class uses record blocking to improve performance:</p>
|
|
</div>
|
|
<div class="section"><ul><li>If the file is opened for read-only access, a block of records is read
|
|
when the Java™ program reads a record. Blocking improves performance
|
|
because subsequent read requests may be be handled without accessing the server.
|
|
Little performance difference exists between reading a single record and reading
|
|
several records. Performance improves significantly if records can be served
|
|
out of the block of records cached on the client. <p>The number of records
|
|
to read in each block can be set when the file is opened. For example:</p>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section"><div class="p"><pre> // Create an AS400 object, the file exists on this
|
|
// server.
|
|
AS400 sys = new AS400("mySystem.myCompany.com");
|
|
|
|
// Create a file object that represents the file
|
|
SequentialFile myFile = new SequentialFile(sys, "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/%FILE%.MBR");
|
|
|
|
// Assume that the AS400FileRecordDescription class
|
|
// was used to generate the code for a subclass of
|
|
// RecordFormat that represents the record format
|
|
// of file MYFILE in library MYLIB. The code was
|
|
// compiled and is available for use by the Java
|
|
// program.
|
|
RecordFormat recordFormat = new MYFILEFormat();
|
|
|
|
// Set the record format for myFile. This must
|
|
// be done before invoking open()
|
|
myFile.setRecordFormat(recordFormat);
|
|
|
|
// Open the file. Specify a blocking factor of 50.
|
|
int blockingFactor = 50;
|
|
myFile.open(AS400File.READ_ONLY, blockingFactor, AS400File.COMMIT_LOCK_LEVEL_NONE);
|
|
|
|
// Read the first record of the file. Because
|
|
// a blocking factor was specified, 50 records
|
|
// are retrieved during this read() invocation.
|
|
Record record = myFile.readFirst();
|
|
for (int i = 1; i < 50 && record != null; i++)
|
|
{
|
|
|
|
// The records read in this loop will be served out of the block of
|
|
// records cached on the client.
|
|
record = myFile.readNext();
|
|
}
|
|
....
|
|
|
|
// Close the file since I am done using it
|
|
myFile.close();
|
|
|
|
// Disconnect since I am done using
|
|
// record-level access
|
|
sys.disconnectService(AS400.RECORDACCESS);</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section"><ul><li>If the file is opened for write-only access, the blocking factor indicates
|
|
how many records are written to the file at one time when the <a href="javadoc/com/ibm/as400/access/AS400File.html#WRITE(COM.IBM.AS400.ACCESS.RECORD[])"> write(Record[])</a> method is invoked. <p>For example:</p>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section"><div class="p"><pre> // Create an AS400 object, the file exists on this
|
|
// server.
|
|
AS400 sys = new AS400("mySystem.myCompany.com");
|
|
|
|
// Create a file object that represents the file
|
|
SequentialFile myFile = new SequentialFile(sys, "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/%FILE%.MBR");
|
|
|
|
// Assume that the AS400FileRecordDescription class
|
|
// was used to generate the code for a subclass of
|
|
// RecordFormat that represents the record format
|
|
// of file MYFILE in library MYLIB. The code was
|
|
// compiled and is available for use by the Java
|
|
// program.
|
|
RecordFormat recordFormat = new MYFILEFormat();
|
|
|
|
// Set the record format for myFile. This must
|
|
// be done prior to invoking open()
|
|
myFile.setRecordFormat(recordFormat);
|
|
|
|
// Open the file. Specify a blocking factor of 50.
|
|
int blockingFactor = 50;
|
|
myFile.open(AS400File.WRITE_ONLY, blockingFactor, AS400File.COMMIT_LOCK_LEVEL_NONE);
|
|
|
|
// Create an array of records to write to the file
|
|
Record[] records = new Record[100];
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
// Assume the file has two fields,
|
|
// CUSTNAME and CUSTNUM
|
|
records[i] = recordFormat.getNewRecord();
|
|
records[i].setField("CUSTNAME", "Customer " + String.valueOf(i));
|
|
records[i].setField("CUSTNUM", new Integer(i));
|
|
}
|
|
|
|
// Write the records to the file. Because the
|
|
// blocking factor is 50, only two trips to the
|
|
// server are made with each trip writing 50 records
|
|
myFile.write(records);
|
|
|
|
....
|
|
|
|
// Close the file since I am done using it
|
|
myFile.close();
|
|
|
|
// Disconnect since I am done using
|
|
// record-level access
|
|
sys.disconnectService(AS400.RECORDACCESS);</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section"><ul><li>If the file is opened for read-write access, no blocking is done. Any
|
|
blocking factor specified on open() is ignored.</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |