Example usage for android.database.sqlite SQLiteDatabase setTransactionSuccessful

List of usage examples for android.database.sqlite SQLiteDatabase setTransactionSuccessful

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase setTransactionSuccessful.

Prototype

public void setTransactionSuccessful() 

Source Link

Document

Marks the current transaction as successful.

Usage

From source file:ch.sebastienzurfluh.swissmuseumguides.contentprovider.model.io.connectors.LocalConnector.java

@Override
public void addAll(final Resources resources) {
    new Thread() {
        @Override/*  w  w  w . j a va 2 s  .co m*/
        public void run() {
            SQLiteDatabase writableDatabase = getWritableDatabase();

            writableDatabase.beginTransaction();
            try {
                for (Resource resource : resources) {
                    String query = "INSERT OR REPLACE INTO " + resources.getTableName() + " VALUES (\""
                            + resource.getId() + "\", \"" + resource.getTitle() + "\", \"" + resource.getURL()
                            + "\", \"" + resource.getDescription() + "\", \"" + resource.getType() + "\");";
                    getWritableDatabase().execSQL(query);
                }
                writableDatabase.setTransactionSuccessful();
            } catch (JSONException e) {
                System.out.println("Malformed json in resources");
                e.printStackTrace();
            } finally {
                writableDatabase.endTransaction();
            }
        }
    }.start();
}

From source file:net.zionsoft.obadiah.model.Bible.java

private boolean removeTranslation(String translationShortName) {
    SQLiteDatabase db = null;
    try {/*from w  ww  . ja  va2 s  . c om*/
        db = mDatabaseHelper.openDatabase();
        if (db == null) {
            Analytics.trackException("Failed to open database.");
            return false;
        }
        db.beginTransaction();
        TranslationHelper.removeTranslation(db, translationShortName);
        db.setTransactionSuccessful();

        return true;
    } finally {
        if (db != null) {
            if (db.inTransaction()) {
                db.endTransaction();
            }
            mDatabaseHelper.closeDatabase();
        }
    }
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void update(T item, int conflictAlgorithm) {
    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {//w  ww  . ja  va 2  s .  c om
        db.beginTransaction();
        db.updateWithOnConflict(mTableName, itemToRow(item), "id = ?", new String[] { String.valueOf(item.id) },
                conflictAlgorithm);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}

From source file:com.alchemiasoft.common.content.BookDBOpenHelper.java

@Override
public void onCreate(SQLiteDatabase db) {
    try {/*from  w w  w.  ja va2s  .c om*/
        db.beginTransaction();

        db.execSQL(BookDB.Book.CREATE_TABLE);

        String input = null;
        try {
            input = ResUtil.assetAsString(mContext, Constants.BOOKS_PATH);
        } catch (Exception e) {
            Log.e(TAG_LOG, "Cannot read the input at assets/" + Constants.BOOKS_PATH);
        }
        // Adding the default entries
        if (!TextUtils.isEmpty(input)) {
            Log.d(TAG_LOG, "Adding into the DB: " + input);
            final JSONArray arr = new JSONArray(input);
            final List<Book> books = Book.allFrom(arr);
            // Adding the all the books as a batch
            for (final Book book : books) {
                db.insert(BookDB.Book.TABLE, null, book.toValues());
            }
        }

        db.setTransactionSuccessful();
        Log.i(TAG_LOG, "Successfully created " + BookDB.NAME);
    } catch (Exception e) {
        Log.e(TAG_LOG, "Error creating " + BookDB.NAME + ": ", e);
    } finally {
        db.endTransaction();
    }
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void update(List<T> items, int conflictAlgorithm) {
    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {/*w ww. ja v  a 2  s .c  om*/
        db.beginTransaction();
        for (T item : items)
            db.updateWithOnConflict(mTableName, itemToRow(item), "id = ?",
                    new String[] { String.valueOf(item.id) }, conflictAlgorithm);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void deleteById(List<Integer> ids) {
    if (ids.isEmpty())
        return;//from w  w w .j ava 2  s .com

    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {
        db.beginTransaction();

        String args[] = DbHelper.makeArguments(ids.toArray(new Integer[ids.size()]));
        String params = DbHelper.makePlaceholders(args.length);
        db.delete(mTableName, "id IN (" + params + ")", args);

        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}

From source file:net.smart_json_database.JSONDatabase.java

public boolean deleteTag(String name) {
    boolean returnValue = false;
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    try {// w w  w  .j  a  v a 2 s. c om
        db.beginTransaction();
        returnValue = deleteTag(name, db);
        db.setTransactionSuccessful();
        notifyListenersOnTagChange(name, IDatabaseChangeListener.CHANGETYPE_DELETE);
    } catch (Exception e) {
    } finally {
        db.endTransaction();
        db.close();
    }
    return returnValue;
}

From source file:net.smart_json_database.JSONDatabase.java

public int insertTag(String name) {
    int returnValue = -1;
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    try {/*  w w w.  ja va  2  s. c om*/
        db.beginTransaction();
        returnValue = insertTag(name, db);
        db.setTransactionSuccessful();
        notifyListenersOnTagChange(name, IDatabaseChangeListener.CHANGETYPE_INSERT);
    } catch (Exception e) {
    } finally {
        db.endTransaction();
        db.close();
    }
    return returnValue;
}

From source file:com.dm.wallpaper.board.databases.Database.java

public void addWallpapers(@NonNull List<Wallpaper> wallpapers) {
    String query = "INSERT INTO " + TABLE_WALLPAPERS + " (" + KEY_NAME + "," + KEY_AUTHOR + "," + KEY_URL + ","
            + KEY_THUMB_URL + "," + KEY_CATEGORY + "," + KEY_ADDED_ON + ") VALUES (?,?,?,?,?,?);";
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement statement = db.compileStatement(query);
    db.beginTransaction();/*ww w. j  a v a2 s. c o  m*/

    for (int i = 0; i < wallpapers.size(); i++) {
        statement.clearBindings();
        statement.bindString(1, wallpapers.get(i).getName());
        statement.bindString(2, wallpapers.get(i).getAuthor());
        statement.bindString(3, wallpapers.get(i).getUrl());
        statement.bindString(4, wallpapers.get(i).getThumbUrl());
        statement.bindString(5, wallpapers.get(i).getCategory());
        statement.bindString(6, TimeHelper.getLongDateTime());
        statement.execute();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    db.close();
}

From source file:com.flowzr.activity.MainActivity.java

private void initialLoad() {
    long t3, t2, t1, t0 = System.currentTimeMillis();
    DatabaseAdapter db = new DatabaseAdapter(this);
    db.open();/*w w w. j  a  v a 2 s . c  o  m*/
    try {
        SQLiteDatabase x = db.db();
        x.beginTransaction();
        t1 = System.currentTimeMillis();
        try {
            updateFieldInTable(x, DatabaseHelper.CATEGORY_TABLE, 0, "title", getString(R.string.no_category));
            updateFieldInTable(x, DatabaseHelper.CATEGORY_TABLE, -1, "title", getString(R.string.split));
            updateFieldInTable(x, DatabaseHelper.PROJECT_TABLE, 0, "title", getString(R.string.no_project));
            updateFieldInTable(x, DatabaseHelper.LOCATIONS_TABLE, 0, "name",
                    getString(R.string.current_location));
            x.setTransactionSuccessful();
        } finally {
            x.endTransaction();
        }
        t2 = System.currentTimeMillis();
        if (MyPreferences.shouldUpdateHomeCurrency(this)) {
            db.setDefaultHomeCurrency();
        }
        CurrencyCache.initialize(db.em());
        t3 = System.currentTimeMillis();
        if (MyPreferences.shouldRebuildRunningBalance(this)) {
            db.rebuildRunningBalances();
        }
        if (MyPreferences.shouldUpdateAccountsLastTransactionDate(this)) {
            db.updateAccountsLastTransactionDate();
        }
    } finally {
        db.close();
    }
    long t4 = System.currentTimeMillis();
    Log.d("Financisto",
            "Load time = " + (t4 - t0) + "ms = " + (t2 - t1) + "ms+" + (t3 - t2) + "ms+" + (t4 - t3) + "ms");
}