public static MobileLedgerProfile loadAllFromDB(String currentProfileUUID) {
MobileLedgerProfile result = null;
List<MobileLedgerProfile> list = new ArrayList<>();
public static MobileLedgerProfile loadAllFromDB(String currentProfileUUID) {
MobileLedgerProfile result = null;
List<MobileLedgerProfile> list = new ArrayList<>();
try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " +
"auth_password, permit_posting, theme, order_no FROM " +
"profiles order by order_no", null))
try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " +
"auth_password, permit_posting, theme, order_no FROM " +
"profiles order by order_no", null))
- for (MobileLedgerProfile p : Data.profiles.getList()) {
- db.execSQL("update profiles set order_no=? where uuid=?",
- new Object[]{orderNo, p.getUuid()});
- p.orderNo = orderNo;
- orderNo++;
+ try (LockHolder lh = Data.profiles.lockForReading()) {
+ for (int i = 0; i < Data.profiles.size(); i++) {
+ MobileLedgerProfile p = Data.profiles.get(i);
+ db.execSQL("update profiles set order_no=? where uuid=?",
+ new Object[]{orderNo, p.getUuid()});
+ p.orderNo = orderNo;
+ orderNo++;
+ }
db.beginTransaction();
try {
// Log.d("profiles", String.format("Storing profile in DB: uuid=%s, name=%s, " +
db.beginTransaction();
try {
// Log.d("profiles", String.format("Storing profile in DB: uuid=%s, name=%s, " +
Log.d("profile", String.format("Transaction %d stored", tr.getId()));
}
public String getOption(String name, String default_value) {
Log.d("profile", String.format("Transaction %d stored", tr.getId()));
}
public String getOption(String name, String default_value) {
try (Cursor cursor = db.rawQuery("select value from options where profile = ? and name=?",
new String[]{uuid, name}))
{
try (Cursor cursor = db.rawQuery("select value from options where profile = ? and name=?",
new String[]{uuid, name}))
{
}
public void setOption(String name, String value) {
Log.d("profile", String.format("setting option %s=%s", name, value));
}
public void setOption(String name, String value) {
Log.d("profile", String.format("setting option %s=%s", name, value));
- SQLiteDatabase db = MLDB.getWritableDatabase();
- db.execSQL("insert or replace into options(profile, name, value) values(?, ?, ?);",
+ DbOpQueue.add("insert or replace into options(profile, name, value) values(?, ?, ?);",
new String[]{uuid, name, value});
}
public void setLongOption(String name, long value) {
setOption(name, String.valueOf(value));
}
public void removeFromDB() {
new String[]{uuid, name, value});
}
public void setLongOption(String name, long value) {
setOption(name, String.valueOf(value));
}
public void removeFromDB() {
db.execSQL("delete from profiles where uuid=?", new Object[]{uuid});
db.execSQL("delete from accounts where profile=?", new Object[]{uuid});
db.execSQL("delete from account_values where profile=?", new Object[]{uuid});
db.execSQL("delete from profiles where uuid=?", new Object[]{uuid});
db.execSQL("delete from accounts where profile=?", new Object[]{uuid});
db.execSQL("delete from account_values where profile=?", new Object[]{uuid});
return loadAccount(db, name);
}
@Nullable
public LedgerAccount tryLoadAccount(String acct_name) {
return loadAccount(db, name);
}
@Nullable
public LedgerAccount tryLoadAccount(String acct_name) {
- SQLiteDatabase db = MLDB.getReadableDatabase();
- return loadAccount(acct_name);
+ SQLiteDatabase db = MLDB.getDatabase();
+ return tryLoadAccount(db, acct_name);
}
public LedgerTransaction loadTransaction(int transactionId) {
LedgerTransaction tr = new LedgerTransaction(transactionId, this.uuid);
}
public LedgerTransaction loadTransaction(int transactionId) {
LedgerTransaction tr = new LedgerTransaction(transactionId, this.uuid);
public void setThemeId(int themeId) {
// Log.d("profile", String.format("Profile.setThemeId(%d) called", themeId));
this.themeId = themeId;
}
public void setThemeId(int themeId) {
// Log.d("profile", String.format("Profile.setThemeId(%d) called", themeId));
this.themeId = themeId;
}
public void markTransactionsAsNotPresent(SQLiteDatabase db) {
db.execSQL("UPDATE transactions set keep=0 where profile=?", new String[]{uuid});
public void markTransactionsAsNotPresent(SQLiteDatabase db) {
db.execSQL("UPDATE transactions set keep=0 where profile=?", new String[]{uuid});
}
public List<LedgerAccount> loadChildAccountsOf(LedgerAccount acc) {
List<LedgerAccount> result = new ArrayList<>();
}
public List<LedgerAccount> loadChildAccountsOf(LedgerAccount acc) {
List<LedgerAccount> result = new ArrayList<>();
try (Cursor c = db.rawQuery(
"SELECT a.name FROM accounts a WHERE a.profile = ? and a.name like ?||':%'",
new String[]{uuid, acc.getName()}))
try (Cursor c = db.rawQuery(
"SELECT a.name FROM accounts a WHERE a.profile = ? and a.name like ?||':%'",
new String[]{uuid, acc.getName()}))
try (Cursor c = db.rawQuery(
"SELECT a.name FROM accounts a WHERE a.profile = ? and a.name like ?||':%'",
new String[]{uuid, acc.getName()}))
try (Cursor c = db.rawQuery(
"SELECT a.name FROM accounts a WHERE a.profile = ? and a.name like ?||':%'",
new String[]{uuid, acc.getName()}))