X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FCurrency.java;h=28e6d03e9fe6c2007c1b4ece489472c027ab030b;hb=7526e4b8588361e218b5215f77bc7445e02ba970;hp=596cdf1c493c50c5b308a5b3f63c717ece831b5b;hpb=0ce370cea3c5c980b6eeb14acf965188ae951f51;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Currency.java b/app/src/main/java/net/ktnx/mobileledger/model/Currency.java index 596cdf1c..28e6d03e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Currency.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Currency.java @@ -60,21 +60,13 @@ public class Currency { } public Currency(MobileLedgerProfile profile, String name, Position position, boolean hasGap) { SQLiteDatabase db = App.getDatabase(); - int attempts = 0; - while (true) { - if (++attempts > 10) - throw new RuntimeException("Giving up getting next ID after 10 attempts"); - try (Cursor c = db.rawQuery("select max(rowid) from currencies", null)) { - c.moveToNext(); - int nextId = c.getInt(0) + 1; - db.execSQL("insert into currencies(id, name, position, has_gap) values(?, ?, ?, ?)", - new Object[]{nextId, name, position.toString(), hasGap}); - - this.id = nextId; - break; - } + try (Cursor c = db.rawQuery("select max(rowid) from currencies", null)) { + c.moveToNext(); + this.id = c.getInt(0) + 1; } + db.execSQL("insert into currencies(id, name, position, has_gap) values(?, ?, ?, ?)", + new Object[]{this.id, name, position.toString(), hasGap}); this.name = name; this.position = position; @@ -84,27 +76,6 @@ public class Currency { MobileLedgerProfile profile = Data.getProfile(); return profile.loadCurrencyByName(name); } - public int getId() { - return id; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public Position getPosition() { - return position; - } - public void setPosition(Position position) { - this.position = position; - } - public boolean hasGap() { - return hasGap; - } - public void setHasGap(boolean hasGap) { - this.hasGap = hasGap; - } static public boolean equal(Currency left, Currency right) { if (left == null) { return right == null; @@ -126,6 +97,27 @@ public class Currency { return leftName.equals(right); } } + public int getId() { + return id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Position getPosition() { + return position; + } + public void setPosition(Position position) { + this.position = position; + } + public boolean hasGap() { + return hasGap; + } + public void setHasGap(boolean hasGap) { + this.hasGap = hasGap; + } public enum Position { before(-1), after(1), unknown(0), none(-2); private int value;