Subject Re: [Firebird-Java] Re: NPE in isc_start_transaction (db.out.writeInt(op_transaction))
Author Roman Rokytskyy
Hi Josef,

> 1) Data is inserted by a webservice, which is called from another
> application. If an exception occurs, then this exception is logged,
> but the app doesn't try to send the data again --> therefore the
> record is not in the database (lost).

Ok. But that is also application problem. So the fix is more or less
acceptable.

> 2) What would be the correct place for fix 1?
> Three lines below the NPE happens.

As I wrote:

a) you have to add method boolean isValid() and invalidate() to
isc_tr_handle interface and to the implementations.

b) in the isc_db_handle_impl.invalidate() you have to loop through all
"registered" tr handles and invalidate them before setting out to null. Also
care should be taken in regard to synchronization (I would use
synchronized(tr_handle))

c) all calls that peform something with the database should be converted
into


synchronized(currentTr) {
if (!currentTr.isValid())
throw something;

....
}

d) FBManagedConnectionFactory.getTrHandleForXid(...) should be changed to
check if tr_handle is still valid, and return null if not.

The rest should happen automatically.

Now David Jencks should confirm that this is correct solution in regard to
XA protocol. Most likely driver should throw an error in d) telling the
resource manager that transaction is marked for rollback only if found tr
handle is no longer valid.

> 3) What would be a correct method to get a new db-Handle within
> isc_StartTransaction if db.out == null?

As I wrote, should happen automatically as soon as you return null from
getTrHandleForXid (this would mean - I have no idea about the passed Xid).

Roman