2 * Copyright © 2020 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.async;
20 import android.database.sqlite.SQLiteDatabase;
22 import net.ktnx.mobileledger.App;
23 import net.ktnx.mobileledger.BuildConfig;
25 import java.util.concurrent.BlockingQueue;
27 import static net.ktnx.mobileledger.utils.Logger.debug;
29 class DbOpRunner extends Thread {
30 private final BlockingQueue<DbOpItem> queue;
31 public DbOpRunner(BlockingQueue<DbOpItem> queue) {
36 while (!interrupted()) {
38 DbOpItem item = queue.take();
39 debug("opQrunner", "Got " + item.sql);
41 SQLiteDatabase db = App.getDatabase();
42 if (BuildConfig.DEBUG) {
43 StringBuilder b = new StringBuilder("Executing ");
45 if (item.params.length > 0) {
48 for (Object p : item.params) {
53 b.append(p.toString());
57 debug("opQrunner", b.toString());
59 db.execSQL(item.sql, item.params);
61 if (item.onReady != null)
64 catch (InterruptedException e) {