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:edu.htl3r.schoolplanner.backend.database.AutoSelectDatabase.java

@Override
public void setAutoSelect(AutoSelectSet autoSelectSet) {
    final String TABLE = DatabaseAutoSelectConstants.TABLE_AUTO_SELECT_NAME;

    SQLiteDatabase database = this.database.openDatabase(true);

    this.database.deleteAllRowsWithLoginSetKey(database, TABLE);

    ContentValues values = new ContentValues();
    values.put(DatabaseCreateConstants.TABLE_LOGINSET_KEY, this.database.getLoginSetKeyForTable());
    values.put(DatabaseAutoSelectConstants.ENABLED, autoSelectSet.isEnabled());
    values.put(DatabaseAutoSelectConstants.TYPE, autoSelectSet.getAutoSelectType());
    values.put(DatabaseAutoSelectConstants.VALUE, autoSelectSet.getAutoSelectValue());

    database.beginTransaction();/*from www.j a  v a2 s .c  o  m*/

    this.database.insert(database, TABLE, values);

    database.setTransactionSuccessful();
    database.endTransaction();
    this.database.closeDatabase(database);
}

From source file:au.org.ala.fielddata.mobile.dao.DatabaseHelper.java

@Override
public void onCreate(SQLiteDatabase db) {
    try {/*from  ww w  .ja va2 s. c  o  m*/
        db.beginTransaction();

        for (String table : TABLES) {
            db.execSQL("CREATE TABLE " + table + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, server_id INTEGER, "
                    + "created INTEGER, updated INTEGER, last_sync INTEGER" + "name TEXT, json TEXT)");

            createServerIdIndex(db, table);
        }

        createRecordTable(db);
        createSpeciesTables(db);
        createAttributeRowTable(db);

        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }

}

From source file:syncthing.android.settings.AppSettings.java

public void setDefaultCredentials(Credentials creds) {
    SQLiteDatabase _db = db.getWritableDatabase();
    try {/*w  w  w .ja v a 2  s .  c o m*/
        _db.beginTransaction();
        ContentValues cv = new ContentValues();
        cv.put(CredentialsDB.SCHEMA.DEFAULT, 0);
        //first unset default for everyone
        _db.update(CredentialsDB.SCHEMA.TABLE, cv, null, null);
        cv.put(CredentialsDB.SCHEMA.DEFAULT, 1);
        String[] sel = new String[] { creds.id };
        //set default for specified device
        _db.update(CredentialsDB.SCHEMA.TABLE, cv, credentialsDeviceIdSel, sel);
        _db.setTransactionSuccessful();
    } finally {
        _db.endTransaction();
    }
}

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

public void addCategories(List<WallpaperJson> categories) {
    String query = "INSERT INTO " + TABLE_CATEGORIES + " (" + KEY_NAME + "," + KEY_THUMB_URL
            + ") VALUES (?,?);";
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement statement = db.compileStatement(query);
    db.beginTransaction();/*ww w .j ava2 s .c  o m*/

    for (int i = 0; i < categories.size(); i++) {
        statement.clearBindings();
        statement.bindString(1, categories.get(i).name);
        statement.bindString(2, categories.get(i).thumbUrl == null ? "" : categories.get(i).thumbUrl);
        statement.execute();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    db.close();
}

From source file:ru.orangesoftware.financisto2.db.MyEntityManager.java

public long saveOrUpdate(Currency currency) {
    SQLiteDatabase db = db();
    db.beginTransaction();/*  w ww. jav  a  2s.  c om*/
    try {
        if (currency.isDefault) {
            db.execSQL(UPDATE_DEFAULT_FLAG);
        }
        long id = super.saveOrUpdate(currency);
        db.setTransactionSuccessful();
        return id;
    } finally {
        db.endTransaction();
    }
}

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

@Override
public void addAll(final Groups groups) {
    new Thread() {
        @Override//from ww w. j a  va 2  s  . c om
        public void run() {
            SQLiteDatabase writableDatabase = getWritableDatabase();

            writableDatabase.beginTransaction();
            try {
                for (Group group : groups) {
                    String query = "INSERT OR REPLACE INTO " + groups.getTableName() + " VALUES (\""
                            + group.getId() + "\", \"" + group.getName() + "\", \"" + group.getMenuId()
                            + "\");";
                    getWritableDatabase().execSQL(query);
                }
                writableDatabase.setTransactionSuccessful();
            } catch (JSONException e) {
                System.out.println("Malformed json in groups");
                e.printStackTrace();
            } finally {
                writableDatabase.endTransaction();
            }
        }
    }.start();
}

From source file:com.cloudmine.api.db.RequestDBOpenHelper.java

public void insertRequest(ContentValues requestValues, ContentValues[] headerValues) {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();/* ww w. ja va2 s.  com*/
    try {
        long requestId = db.insertOrThrow(REQUEST_DATABASE_TABLE, null, requestValues);
        throwIfFailed(requestId);
        for (ContentValues headerValue : headerValues) {
            headerValue.put(KEY_HEADER_REQUEST_FK, requestId);
            long result = db.insertOrThrow(HEADER_DATABASE_TABLE, null, headerValue);
            throwIfFailed(result);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}

From source file:github.popeen.dsub.util.SongDBHandler.java

protected synchronized void addSongsImpl(SQLiteDatabase db, int serverKey, List<Pair<String, String>> entries) {
    db.beginTransaction();/* w  w  w.  j  a  v a2s.c o  m*/
    try {
        for (Pair<String, String> entry : entries) {
            ContentValues values = new ContentValues();
            values.put(SONGS_SERVER_KEY, serverKey);
            values.put(SONGS_SERVER_ID, entry.getFirst());
            values.put(SONGS_COMPLETE_PATH, entry.getSecond());

            db.insertWithOnConflict(TABLE_SONGS, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        }

        db.setTransactionSuccessful();
    } catch (Exception e) {
    }

    db.endTransaction();
}

From source file:org.mariotaku.twidere.util.content.DatabaseUpgradeHelper.java

public static void safeUpgrade(final SQLiteDatabase db, final String table, final String[] newColNames,
        final String[] newColTypes, final boolean dropDirectly, final boolean strictMode,
        final Map<String, String> colAliases, final OnConflict onConflict) {

    if (newColNames == null || newColTypes == null || newColNames.length != newColTypes.length)
        throw new IllegalArgumentException(
                "Invalid parameters for upgrading table " + table + ", length of columns and types not match.");

    // First, create the table if not exists.
    final NewColumn[] newCols = NewColumn.createNewColumns(newColNames, newColTypes);
    final String createQuery = createTable(true, table).columns(newCols).buildSQL();
    db.execSQL(createQuery);/*from  w  w  w.j  a  va2 s  . c  o  m*/

    // We need to get all data from old table.
    final String[] oldCols = getColumnNames(db, table);
    if (strictMode) {
        final String oldCreate = getCreateSQL(db, table);
        final Map<String, String> map = getTypeMapByCreateQuery(oldCreate);
        boolean different = false;
        for (final NewColumn newCol : newCols) {
            if (!newCol.getType().equalsIgnoreCase(map.get(newCol.getName()))) {
                different = true;
            }
        }
        if (!different)
            return;
    } else if (oldCols == null || TwidereArrayUtils.contentMatch(newColNames, oldCols))
        return;
    if (dropDirectly) {
        db.beginTransaction();
        db.execSQL(dropTable(true, table).getSQL());
        db.execSQL(createQuery);
        db.setTransactionSuccessful();
        db.endTransaction();
        return;
    }
    final String tempTable = String.format(Locale.US, "temp_%s_%d", table, System.currentTimeMillis());
    db.beginTransaction();
    db.execSQL(alterTable(table).renameTo(tempTable).buildSQL());
    db.execSQL(createQuery);
    final String[] notNullCols = getNotNullColumns(newCols);
    final String insertQuery = createInsertDataQuery(table, tempTable, newColNames, oldCols, colAliases,
            notNullCols, onConflict);
    if (insertQuery != null) {
        db.execSQL(insertQuery);
    }
    db.execSQL(dropTable(true, tempTable).getSQL());
    db.setTransactionSuccessful();
    db.endTransaction();
}

From source file:org.getlantern.firetweet.util.content.DatabaseUpgradeHelper.java

public static void safeUpgrade(final SQLiteDatabase db, final String table, final String[] newColNames,
        final String[] newColTypes, final boolean dropDirectly, final boolean strictMode,
        final Map<String, String> colAliases, final OnConflict onConflict) {

    if (newColNames == null || newColTypes == null || newColNames.length != newColTypes.length)
        throw new IllegalArgumentException(
                "Invalid parameters for upgrading table " + table + ", length of columns and types not match.");

    // First, create the table if not exists.
    final NewColumn[] newCols = NewColumn.createNewColumns(newColNames, newColTypes);
    final String createQuery = createTable(true, table).columns(newCols).buildSQL();
    db.execSQL(createQuery);/*from w  w  w  .ja va2s.c o m*/

    // We need to get all data from old table.
    final String[] oldCols = getColumnNames(db, table);
    if (strictMode) {
        final String oldCreate = getCreateSQL(db, table);
        final Map<String, String> map = getTypeMapByCreateQuery(oldCreate);
        boolean differenct = false;
        for (final NewColumn newCol : newCols) {
            if (!newCol.getType().equalsIgnoreCase(map.get(newCol.getName()))) {
                differenct = true;
            }
        }
        if (!differenct)
            return;
    } else if (oldCols == null || FiretweetArrayUtils.contentMatch(newColNames, oldCols))
        return;
    if (dropDirectly) {
        db.beginTransaction();
        db.execSQL(dropTable(true, table).getSQL());
        db.execSQL(createQuery);
        db.setTransactionSuccessful();
        db.endTransaction();
        return;
    }
    final String tempTable = String.format(Locale.US, "temp_%s_%d", table, System.currentTimeMillis());
    db.beginTransaction();
    db.execSQL(alterTable(table).renameTo(tempTable).buildSQL());
    db.execSQL(createQuery);
    final String[] notNullCols = getNotNullColumns(newCols);
    final String insertQuery = createInsertDataQuery(table, tempTable, newColNames, oldCols, colAliases,
            notNullCols, onConflict);
    if (insertQuery != null) {
        db.execSQL(insertQuery);
    }
    db.execSQL(dropTable(true, tempTable).getSQL());
    db.setTransactionSuccessful();
    db.endTransaction();
}