ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/rlacmt.htm

154 lines
8.4 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?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="Commitment control" />
<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="rlacmt" />
<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>Commitment control</title>
</head>
<body id="rlacmt"><a name="rlacmt"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Commitment control</h1>
<div><p></p>
<div class="section"><p>Through commitment control, your Java™ program has another level of control
over changing a file. With commitment control turned on, transactions to a
file are pending until they are either committed or rolled back. If committed,
all changes are put to the file. If rolled back, all changes are discarded.
The transaction can be changing an existing record, adding a record, deleting
a record, or even reading a record depending on the commitment control lock
level specified on the open().</p>
</div>
<div class="section"><p>The levels of commitment control are as follows:</p>
</div>
<div class="section"><ul><li><a href="javadoc/com/ibm/as400/access/AS400File.html#COMMIT_LOCK_LEVEL_ALL"> All</a> - Every record accessed in the file is locked until
the transaction is committed or rolled back.</li>
<li><a href="javadoc/com/ibm/as400/access/AS400File.html#COMMIT_LOCK_LEVEL_CHANGE"> Change</a> - Updated, added, and deleted records in the
file are locked until the transaction is committed or rolled back.</li>
<li><a href="javadoc/com/ibm/as400/access/AS400File.html#COMMIT_LOCK_LEVEL_CURSOR_STABILITY"> Cursor Stability</a> - Updated, added, and deleted records
in the file are locked until the transaction is committed or rolled back.
Records that are accessed but not changed are locked only until another record
is accessed.</li>
<li><a href="javadoc/com/ibm/as400/access/AS400File.html#COMMIT_LOCK_LEVEL_NONE"> None</a> - There is no commitment control on the file. Changes
are immediately put to the file and cannot be rolled back.</li>
</ul>
</div>
<div class="section"><p>You can use the <a href="javadoc/com/ibm/as400/access/AS400File.html#STARTCOMMITMENTCONTROL(INT)"> startCommitmentControl()</a> method to start commitment
control. Commitment control applies to the AS400 <strong>connection</strong>. Once commitment
control is started for a connection, it applies to all files opened under
that connection from the time that commitment control was started. Files opened
before commitment control is started are not under commitment control. The
level of commitment control for individual files is specified on the <a href="javadoc/com/ibm/as400/access/AS400File.html#OPEN()">open()</a> method.
Specify <a href="javadoc/com/ibm/as400/access/AS400File.html#COMMIT_LOCK_LEVEL_DEFAULT"> COMMIT_LOCK_LEVEL_DEFAULT</a> to use the same level of commitment
control as was specified on the startCommitmentControl() method.</p>
</div>
<div class="section"><p>For example:</p>
</div>
<div class="section"><div class="p"><pre> // Create an AS400 object, the files exist on this
// server.
AS400 sys = new AS400("mySystem.myCompany.com");
// Create three file objects
SequentialFile myFile = new SequentialFile(sys, "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/%FILE%.MBR");
SequentialFile yourFile = new SequentialFile(sys, "/QSYS.LIB/YOURLIB.LIB/YOURFILE.FILE/%FILE%.MBR");
SequentialFile ourFile = new SequentialFile(sys, "/QSYS.LIB/OURLIB.LIB/OURFILE.FILE/%FILE%.MBR");
// Open yourFile before starting commitment control
// No commitment control applies to this file. The
// commit lock level parameter is ignored because
// commitment control is not started for the connection.
yourFile.setRecordFormat(new YOURFILEFormat());
yourFile.open(AS400File.READ_WRITE, 0, AS400File.COMMIT_LOCK_LEVEL_DEFAULT);
// Start commitment control for the connection.
// Note: Any of the three files might be used for
// this call to startCommitmentControl().
myFile.startCommitmentControl(AS400File.COMMIT_LOCK_LEVEL_CHANGE);
// Open myFile and ourFile
myFile.setRecordFormat(new MYFILEFormat());
// Use the same commit lock level as specified
// when commitment control was started
myFile.open(AS400File.WRITE_ONLY, 0, COMMIT_LOCK_LEVEL_DEFAULT);
ourFile.setRecordFormat(new OURFILEFormat());
// Specify a different commit lock level than
// when commitment control was started
ourFile.open(AS400File.READ_WRITE, 0, COMMIT_LOCK_LEVEL_CURSOR_STABILITY);
// write and update records in all three files
....
// Commit the changes for files myFile and ourFile.
// Note that the commit commits all changes for the connection
// even though it is invoked on only one AS400File object.
myFile.commit();
// Close the files
myFile.close();
yourFile.close();
ourFile.close();
// End commitment control
// This ends commitment control for the connection.
ourFile.endCommitmentControl();
// Disconnect since I am done using record-level access
sys.disconnectService(AS400.RECORDACCESS);</pre>
</div>
</div>
<div class="section"><p>The <a href="javadoc/com/ibm/as400/access/AS400File.html#COMMIT()">commit()</a> method commits all transactions since the last
commit boundary for the <strong>connection</strong>. The <a href="javadoc/com/ibm/as400/access/AS400File.html#ROLLBACK()"> rollback()</a> method discards all transactions since the
last commit boundary for the <strong>connection</strong>. Commitment control for a connection
is ended through the <a href="javadoc/com/ibm/as400/access/AS400File.html#ENDCOMMITMENTCONTROL()"> endCommitmentControl()</a> method. If a file is closed before
invoking the commit() or rollback() method, all uncommitted transactions are
rolled back. All files opened under commitment control must be closed before
the endCommitmentControl() method is called.</p>
</div>
<div class="section"><p>The following examples shows how to start commitment control,
commit or roll back functions, and then end commitment control:</p>
</div>
<div class="section"><div class="p"><pre> // ... assume the AS400 object and file have been
// instantiated.
// Start commitment control for *CHANGE
aFile.startCommitmentControl(AS400File.COMMIT_LOCK_LEVEL_CHANGE);
// ... open the file and do several changes. For
// example, update, add or delete records.
// Based on a flag either save or discard the
// transactions.
if (saveChanges)
aFile.commit();
else
aFile.rollback();
// Close the file
aFile.close();
// End commitment control for the connection.
aFile.endCommitmentControl();</pre>
</div>
</div>
</div>
</body>
</html>