2

Given a DecimalDataArea from JTOpen, when reading and writing to the data area, does the object on the AS400 get locked, preventing simultaneous writes to it from other applications that are on the AS400?

This is the sample code from the javadoc on how to read/write, etc.

// Prepare to work with the system named "My400".
AS400 system = new AS400("My400");

// Create a DecimalDataArea object.
QSYSObjectPathName path = new QSYSObjectPathName("MYLIB", "MYDATA", "DTAARA");
DecimalDataArea dataArea = new DecimalDataArea(system, path.getPath());

// Create the decimal data area on the system using default values.
dataArea.create();

// Clear the data area.
dataArea.clear();

// Write to the data area.
dataArea.write(new BigDecimal("1.2"));

// Read from the data area.
BigDecimal data = dataArea.read();

// Delete the data area from the system.
dataArea.delete();

http://javadoc.midrange.com/jtopen/com/ibm/as400/access/DecimalDataArea.html

Patrick Grimard
  • 7,033
  • 8
  • 51
  • 68
  • If you need the ability to lock a data area you could write a simple RPG program that would lock the data area, update it and then unlock it - passing the updated value back to your Java program (or whatever you're trying to do). – Benny Hill Apr 05 '13 at 21:16
  • I don't know RPG, I usually leavce that to my RPG programmers, lol. I'm writing an application in Java which will integrate with an existing RPG application that uses data areas for storing the last used ID for a record. The way my RPG programmers do it when they need to get the next value, is they lock the data area from RPG, write the new value to it, then unlock it. – Patrick Grimard Apr 06 '13 at 20:18

2 Answers2

3

No ... the data area operations are atomic, so no locking occurs unless you do it yourself.

Internally, the implementation actually uses CHGDTAARA to update the data area.

Wouldn't be a bad enhancement though.

David G
  • 3,940
  • 1
  • 22
  • 30
  • 1
    Terminology clarification: Normally *atomic* is used to refer to a transaction (that may involve multiple lower-level operations) that is guaranteed to occur completely or not at all; therefore no (explicit) locking is required. I understand what you are trying to say here, but it's probably not meaningful to use the term *atomic* in this context, and it might even be a little misleading. – John Y Apr 06 '13 at 16:18
0

If you create the data are with an SQL CREATE SEQUENCE statement, then you can use a NEXT VALUE via JDBC. You can use a NEXT VALUE expression in SQL statements such as SELECT, INSERT, UPDATE, etc. It will read the value, increment it, update the SEQUENCE, and return the new value to you, and can be done under commitment control. The PREVIOUS VALUE expression will return the last value generated by a NEXT VALUE expression for that SEQUENCE during your current session.

Generally a numeric data area is used to manage generating a series of numbers. If that is the case here, then you'll be better off using a SEQUENCE.

WarrenT
  • 4,502
  • 19
  • 27