Issue Details (XML | Word | Printable)

Key: JDBC-407
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Mark Rotteveel
Reporter: Vjacheslav Borisov
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Jaybird JCA/JDBC Driver

Specify isc_tpb_lock_timeout using JDBC connectionProperties property

Created: 29/Sep/15 12:29 PM   Updated: 13/Mar/16 04:03 PM
Component/s: Connection pool, JDBC driver
Affects Version/s: Jaybird 2.2.8
Fix Version/s: Jaybird 2.2.10, Jaybird 3.0.0


 Description  « Hide
FBTpbMapper class could be improved to specify isc_tpb_lock_timeout param value, like

connectionProperties="TRANSACTION_READ_COMMITTED=isc_tpb_read_committed,isc_tpb_rec_version,isc_tpb_wait,isc_tpb_lock_timeout=5"



 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Mark Rotteveel added a comment - 29/Sep/15 06:07 PM
Thanks for the suggestion, but unfortunately I can't and won't do this. The current behavior has been the default since the start of Jaybid, changing this default could break applications that depend on the existing behavior. Also isc_tpb_lock_timeout is not available on older Firebird versions (1.0 and 1.5), so at least for 2.2.x this isn't an option at all as we promised to support those versions explicitly for Jaybird 2.2.x.

If you need different behavior, then I suggest you make a copy of isc_tpb_mapping.properties, add your own defaults and explicitly specify this file using the tpbMapping connection property.

Vjacheslav Borisov added a comment - 30/Sep/15 05:49 AM
I don't understand, we do not change default behavior
default connection properties do no change, and this dont break applications
I want to specify transaction params in jdbc resource like

    <Resource name="jdbc/base"
...
            connectionProperties="TRANSACTION_READ_COMMITTED=isc_tpb_read_committed,isc_tpb_rec_version,isc_tpb_wait,isc_tpb_lock_timeout=5"
...
    />

Vjacheslav Borisov added a comment - 30/Sep/15 06:05 AM
i want to patch method FBTpbMapper.TransactionParameterBuffer

public static TransactionParameterBuffer processMapping(GDS gds, String mapping) throws FBResourceException {

Mark Rotteveel added a comment - 30/Sep/15 07:16 AM
My apologies, that is not how I read your request (especially as the FbTpbMapper is just an implementation detail). I have reopened the request. What you want is already somewhat possible if you use the Jaybird datasources directly, but as far as I know this isn't available for connection properties specified in the JDBC URL.

You have two options as a workaround:
1. Use the tpbMapping file as detailed in my previous comment (see also the Jaybird 2.1 Programmers manual)
2. If you use a Jaybird datasource, you might be able to specify the connection property nonStandardProperty=TRANSACTION_READ_COMMITTED=isc_tpb_read_committed,isc_tpb_rec_version,isc_tpb_wait,isc_tpb_lock_timeout=5

I am not entirely sure about option 2 as it contains multiple = signs, which might cause trouble in parsing.

Vjacheslav Borisov added a comment - 30/Sep/15 08:08 AM
alternatively we can use another value separator
 connectionProperties="TRANSACTION_READ_COMMITTED=isc_tpb_read_committed,isc_tpb_rec_version,isc_tpb_wait,isc_tpb_lock_timeout*5"

Vjacheslav Borisov added a comment - 30/Sep/15 08:26 AM
Currently is not possible to specify isc_tpb_lock_timeout=5,

Internal Exception: java.sql.SQLException: Cannot create PoolableConnectionFactory (Resource Exception. Keyword isc_tpb_lock_timeout=5 unknown. Please check your mapping., error code: HY000)

Vjacheslav Borisov added a comment - 30/Sep/15 08:31 AM
method
public static TransactionParameterBuffer processMapping(GDS gds, String mapping) throws FBResourceException {

could be patched to look for '=' sign in token and split if it is exists, treating second part as integer and using

TransactionParameterBuffer.addArgument(int argumentType, int value);

Vjacheslav Borisov added a comment - 30/Sep/15 11:31 AM
created pull request on guthub

Mark Rotteveel added a comment - 30/Sep/15 02:31 PM
I see what you mean; I incorrectly assumed that processing a mapping like this would already work, and that it would be a matter of better exposing that in the connection properties.

I only see the pull request you made for JDBC-408. Was this commented misplaced, or are you still working on it?

Mark Rotteveel added a comment - 30/Sep/15 02:33 PM
Never mind, I saw you added it to the same pull request as for JDBC-407.

Would you mind splitting it into two separate pull requests?

Vjacheslav Borisov added a comment - 01/Oct/15 05:18 AM

Attila Molnár added a comment - 01/Oct/15 05:43 AM
This works fine for me.

import org.firebirdsql.gds.TransactionParameterBuffer;

public void setConnection(Connection conn) {

FirebirdConnection fc = (FirebirdConnection) conn.unwrap(FirebirdConnection.class);
TransactionParameterBuffer tpb = fc.createTransactionParameterBuffer();
tpb.addArgument(TransactionParameterBuffer.READ);
tpb.addArgument(TransactionParameterBuffer.READ_COMMITTED);
tpb.addArgument(TransactionParameterBuffer.REC_VERSION);
if (getLockTimeout() == 0) {
tpb.addArgument(TransactionParameterBuffer.NOWAIT);
}
else {
tpb.addArgument(TransactionParameterBuffer.WAIT);
tpb.addArgument(TransactionParameterBuffer.LOCK_TIMEOUT, getLockTimeout());
}
fc.setTransactionParameters(tpb);
}

Mark Rotteveel added a comment - 01/Oct/15 07:38 AM
@Attila That indeed works, but this issue is about specifying the transaction configuration in connection properties (or a tpbMapping file); the parser for that string format currently doesn't take tpb properties with values into account.

Mark Rotteveel added a comment - 02/Oct/15 03:20 PM - edited
Merged pull request https://github.com/FirebirdSQL/jaybird/pull/8 and added basic test. Also added change to master.

Mark Rotteveel added a comment - 29/Nov/15 12:49 PM
This is already in 2.2.9 but wasn't documented as such in the release notes. Add note in 2.2.10 release notes.