-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test App: Add Java code for transaction retries #987
Conversation
fa6cc52
to
3e91e90
Compare
Reviewed 3 of 3 files at r1. _includes/app/TxnSample.java, line 19 at r1 (raw file):
Won't this only throw SQLException and InsufficientBalanceException? Why not just list only those two? _includes/app/TxnSample.java, line 21 at r1 (raw file):
Why do you need the next here? Shouldn't you already be at the first result? _includes/app/TxnSample.java, line 32 at r1 (raw file):
Again here, list only the exceptions that you're going to throw. _includes/app/TxnSample.java, line 66 at r1 (raw file):
So this assumes there's already a db with a table, with two accounts setup. Perhaps add a comment about the initial setup above. _includes/app/TxnSample.java, line 72 at r1 (raw file):
From what I've seen, these are all usually named just e. Unless you're got nested try catches. And above, you just use e. Comments from Reviewable |
3e91e90
to
206623d
Compare
Thank you for the review! Review status: 2 of 3 files reviewed at latest revision, 5 unresolved discussions. _includes/app/TxnSample.java, line 19 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Done. _includes/app/TxnSample.java, line 21 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
The Java _includes/app/TxnSample.java, line 32 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Done. _includes/app/TxnSample.java, line 66 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Added. _includes/app/TxnSample.java, line 72 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
Done. Comments from Reviewable |
A few final nits, but looks good.
Reviewed 1 of 1 files at r2. _includes/app/TxnSample.java, line 21 at r1 (raw file): Previously, arjunravinarayan (Arjun Narayan) wrote…
If you want the first element, why not use Comments from Reviewable |
206623d
to
640411a
Compare
Thank you! Review status: 2 of 3 files reviewed at latest revision, 1 unresolved discussion. _includes/app/TxnSample.java, line 21 at r1 (raw file): Previously, BramGruneir (Bram Gruneir) wrote…
The previous example program in the docs uses Added the other exception. Even added a constructor for it and everything, just for MAXIMUM JAVANESS. Let me know if you would like an Comments from Reviewable |
@jseldess happy to make stylistic changes as you would like, or add/improve the comments. I'll wait for your approval before merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just some suggestions to add comments similar to our other samples. Our commenting eventually needs to be made more consistent across samples, but this should be good for now.
</div> | ||
~~~ java | ||
{% include app/TxnSample.java %} | ||
~~~ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to put the closing </div>
back in. Otherwise, the other transaction samples don't show up.
if(balance < from) { | ||
throw new InsufficientBalanceException(); | ||
} | ||
conn.createStatement().executeUpdate("UPDATE accounts SET balance = balance - " + amount + " where id = " + from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add comment before line 28: # Perform the transfer.
public static RetryableTransaction transferFunds(int from, int to, int amount) { | ||
return new RetryableTransaction() { | ||
public void run(Connection conn) throws SQLException, InsufficientBalanceException { | ||
ResultSet res = conn.createStatement().executeQuery("SELECT balance FROM accounts WHERE id = " + from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add comment before line 20: # Check the current balance.
// This assumes the table has already been set up as in the "Build a Test App" tutorial. | ||
RetryableTransaction transfer = transferFunds(1, 2, 100); | ||
retryTransaction(db, transfer); | ||
ResultSet res = db.createStatement().executeQuery("SELECT id, balance FROM accounts"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add comment before line 70: # Check balances after transfer.
Reviewed 1 of 1 files at r3. _includes/app/TxnSample.java, line 21 at r1 (raw file): Previously, arjunravinarayan (Arjun Narayan) wrote…
For MAXIMUM JAVANESS, you need to add an abstract factory for that factory and use dependency injection to inform it at runtime as to what type of factory to make. Comments from Reviewable |
Add example code for transaction retry logic. Compilation and execution instructions are in a comment in the main code file. Fixes cockroachdb#757.
640411a
to
d0573ef
Compare
Review status: 1 of 3 files reviewed at latest revision, 4 unresolved discussions. build-a-test-app.md, line 219 at r2 (raw file): Previously, jseldess wrote…
Done. _includes/app/TxnSample.java, line 20 at r2 (raw file): Previously, jseldess wrote…
Done. _includes/app/TxnSample.java, line 28 at r2 (raw file): Previously, jseldess wrote…
Done. _includes/app/TxnSample.java, line 70 at r2 (raw file): Previously, jseldess wrote…
Done. Comments from Reviewable |
Add example code for transaction retry logic. Compilation and
execution instructions are in a comment in the main code file.
This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)