Created
November 28, 2011 22:08
-
-
Save sebersole/1402311 to your computer and use it in GitHub Desktop.
HHH-6780 - Wrong Query timeout calculation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface JdbcCoordinator extends Serializable { | |
/** | |
* Set the effective transaction timeout period for the current transaction, in seconds. | |
* | |
* NOTE : Same signature, just added javadocs... | |
*/ | |
public void setTransactionTimeOut(int seconds); | |
/** | |
* Retrieve the amount of time, in seconds, still remaining before transaction timeout occurs. | |
* | |
* NOTE : New method! | |
*/ | |
public int getRemainingTransactionTimeOutPeriod(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JdbcCoordinatorImpl implements JdbcCoordinator { | |
private long transactionTimeOutInstant = -1; | |
public void setTransactionTimeOut(int seconds) { | |
// new body! | |
transactionTimeOutInstant = System.currentTimeMillis() + ( seconds * 1000 ); | |
} | |
// completely new method, see new StatementPreparerImpl | |
public int getRemainingTransactionTimeOutPeriod() { | |
if ( transactionTimeOutInstant < 0 ) { | |
return -1; | |
} | |
final int secondsRemaining = transactionTimeOutInstant - ( System.currentTimeMillis() / 1000 ); | |
if ( secondsRemaining <= 0 ) { | |
throw new TransactionException( "transaction timeout expired" ); | |
} | |
return secondsRemaining; | |
} | |
public void afterTransaction() { | |
logicalConnection.afterTransaction(); | |
// changed functionality | |
transactionTimeOutInstant = -1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface StatementPreparer { | |
... | |
// remove these 2 methods... | |
- public void setTransactionTimeOut(int timeout); | |
- public void unsetTransactionTimeOut(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StatementPreparerImpl implements StatementPreparer { | |
// remove references to local 'transactionTimeOut' variable | |
private abstract class StatementPreparationTemplate { | |
... | |
private void setStatementTimeout(PreparedStatement preparedStatement) throws SQLException { | |
final int remainingTransactionTimeOutPeriod = jdbcCoordinator.getRemainingTransactionTimeOutPeriod(); | |
if ( remainingTransactionTimeOutPeriod > 0 ) { | |
preparedStatement.setQueryTimeout( timeout ); | |
} | |
} | |
} | |
} |
Looks good. This seems much clearer than what is in CR6 and looks like it will solve my issues.
I applied this change to master. Let me know if you need help trying it out
[email protected]
http://hibernate.org
…On Nov 28, 2011 4:37 PM, "Donnchadh Donnabhin" < ***@***.***> wrote:
Looks good. This seems much clearer than what is in CR6 and looks like it
will solve my issues.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1402311
Just downloaded the zip of master and kicked off a gradle build. I'll run our integration tests against it as soon as I can today.
I'm no longer seeing any errors related to the transaction timeout when running our integration tests against master from this morning, so this seems fine.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like calculateRemainingTransactionTimeOutPeriod() instead of getRemainingTransactionTimeOutPeriod()...