diff options
Diffstat (limited to 'src/main/java/com/google/gwtorm/jdbc/JdbcAccess.java')
-rw-r--r-- | src/main/java/com/google/gwtorm/jdbc/JdbcAccess.java | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/main/java/com/google/gwtorm/jdbc/JdbcAccess.java b/src/main/java/com/google/gwtorm/jdbc/JdbcAccess.java index e54df99..351e825 100644 --- a/src/main/java/com/google/gwtorm/jdbc/JdbcAccess.java +++ b/src/main/java/com/google/gwtorm/jdbc/JdbcAccess.java @@ -19,8 +19,6 @@ import com.google.gwtorm.client.AtomicUpdate; import com.google.gwtorm.client.Key; import com.google.gwtorm.client.OrmConcurrencyException; import com.google.gwtorm.client.OrmException; -import com.google.gwtorm.client.OrmRunnable; -import com.google.gwtorm.client.Transaction; import com.google.gwtorm.client.impl.AbstractAccess; import com.google.gwtorm.client.impl.ListResultSet; @@ -33,7 +31,9 @@ import java.util.Collections; /** Internal base class for implementations of {@link Access}. */ public abstract class JdbcAccess<T, K extends Key<?>> extends - AbstractAccess<T, K, JdbcTransaction> { + AbstractAccess<T, K> { + private static final int MAX_TRIES = 10; + private final JdbcSchema schema; protected JdbcAccess(final JdbcSchema s) { @@ -154,8 +154,7 @@ public abstract class JdbcAccess<T, K extends Key<?>> extends } @Override - protected void doInsert(final Iterable<T> instances, final JdbcTransaction txn) - throws OrmException { + protected void doInsert(final Iterable<T> instances) throws OrmException { try { PreparedStatement ps = null; try { @@ -180,8 +179,7 @@ public abstract class JdbcAccess<T, K extends Key<?>> extends } @Override - protected void doUpdate(final Iterable<T> instances, final JdbcTransaction txn) - throws OrmException { + protected void doUpdate(final Iterable<T> instances) throws OrmException { try { PreparedStatement ps = null; try { @@ -206,8 +204,7 @@ public abstract class JdbcAccess<T, K extends Key<?>> extends } @Override - protected void doUpsert(final Iterable<T> instances, final JdbcTransaction txn) - throws OrmException { + protected void doUpsert(final Iterable<T> instances) throws OrmException { // Assume update first, it will cheaply tell us if the row is missing. // Collection<T> inserts = null; @@ -254,13 +251,12 @@ public abstract class JdbcAccess<T, K extends Key<?>> extends } if (inserts != null) { - doInsert(inserts, txn); + doInsert(inserts); } } @Override - protected void doDelete(final Iterable<T> instances, final JdbcTransaction txn) - throws OrmException { + protected void doDelete(final Iterable<T> instances) throws OrmException { try { PreparedStatement ps = null; try { @@ -304,19 +300,24 @@ public abstract class JdbcAccess<T, K extends Key<?>> extends @Override public T atomicUpdate(final K key, final AtomicUpdate<T> update) throws OrmException { - return schema.run(new OrmRunnable<T, JdbcSchema>() { - @Override - public T run(JdbcSchema db, Transaction txn, boolean retry) - throws OrmException { + + for (int attempts = 1;; attempts++) { + try { final T obj = get(key); if (obj == null) { return null; } final T res = update.update(obj); - update(Collections.singleton(obj), txn); + update(Collections.singleton(obj)); return res; + } catch (OrmConcurrencyException err) { + if (attempts < MAX_TRIES) { + continue; + } + throw err; } - }); + } + } @Override |