Subject Re: [Firebird-Java] Re: Transaction concurrency
Author Roman Rokytskyy
> Now the API doesn't say who I am to fill the parameters array It
> just says "parameters - array of TPB parameters, see all TPB_*
> constants." I took a look at the TPB parameters but didn't get any
> wiser, so I took a look at the Interbase APIguide.pdf page 63 and
> saw that there were different(more) constants mentioned there
> :tpb_shared / exclusive / lock_read / lock_write

I have little experience with isc_tpb_consistency and the relevant
parameters, therefore I dared not to declare them at all, only those I knew
that work. If you feel that you need more, please feel free to extend that
interface and submit me a patch, I will commit it into the CVS.

> My questions (or are they documented somewhere?):
> -How do I set the parameters array?

something like this:

int[] tpb = new int[] {
FirebirdConnection.TPB_CONSISTENCY,
FirebirdConnection.TPB_WRITE,
FirebirdConnection.TPB_WAIT
};
((FirebirdConnection)connection).setTransactionParameters(
Connection.TRANSACTION_SERIALIZABLE, tpb);

> -Are the constant's meanings exactly the same as in the apiguide?

Yes.

> -Are the other tpb_ constants going to be implemented?

Sure. If you can provide a patch (easy) and examples/description (harder), I
will be more than happy to apply the changes to JayBird 1.5.5 and release
1.5.6.

> -Should I use this instead of the
> connection.setTransactionIsolation(...)?

Not instead, but in combination. With the method above you provide a mapping
between JDBC isolation level and Firebird TPB. However if you provide a
mapping for TRANSACTION_SERIALIZABLE, but your current isolation is
TRANSACTION_READ_COMMITTED, it will not change anything.

> And whilst looking at the SET TRANSACTION part in the language
> reference and combining it with the info from embedsql.pdf I found t
> hat what I need is the reserving clause:
> "
> To change the level of shared access for one or more individual
> tables in a transaction.
> For example, a READ WRITE SNAPSHOT transaction may need exclusive
> update rights for a
> single table, and could use the RESERVING clause to guarantee itself
> sole write access to
> the table.
>
> PROTECTED READ Prevents other transactions from updating rows. All
> transactions can select
> from the table.
> PROTECTED WRITE Prevents other transactions from updating rows.
> SNAPSHOT and READ COMMITTED transactions can select from the table,
> but only
> this transaction can update rows.
> SHARED READ Any transaction can select from this table. Any READ
> WRITE transaction can
> update this table. This is the most liberal reservation mode.
> SHARED WRITE Any SNAPSHOT or READ COMMITTED READ WRITE transaction
> can update this table.
> Other SNAPSHOT and READ COMMITTED transactions can also select from
> this table.
> "

Correct. And each of this modes has corresponding TPB :)

> So what best suits my needs is non-autocommit mode and setting the
> transaction in an sql statement to snapshot isolation level with
> PROTECTED WRITE reservation clause

Yes, that's what I meant.

> Phew... quite a lot of documentation jumping around. I guess this is
> what Helen's book is for

And her replies in Firebird-Support list :)

> Wouldn't have got here without your help (wouldn't have known that
> setting a transaction's isolation level is the thing I've got to
> look into)

Hopefully you get through this and will be able to help me in adding full
support for the table reservation to JayBird.

Roman