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:com.jefftharris.passwdsafe.NotificationMgr.java

/**
 * Clear all notifications after being confirmed
 *///from www  . j  a  v a  2s  . c o  m
public void handleClearAllConfirmed() {
    try {
        SQLiteDatabase db = itsDbHelper.getWritableDatabase();
        try {
            db.beginTransaction();
            db.delete(DB_TABLE_EXPIRYS, null, null);
            db.delete(DB_TABLE_URIS, null, null);
            loadEntries(db);
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } catch (SQLException e) {
        Log.e(TAG, "Database error", e);
    }
}

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

public void insert(T item, int conflictAlgorithm) {
    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {//w ww .  j  av a 2s.  c om
        db.beginTransaction();
        db.insertWithOnConflict(mTableName, null, itemToRow(item), conflictAlgorithm);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}

From source file:com.jefftharris.passwdsafe.NotificationMgr.java

public void passwdFileDataChanged(PasswdFileData fileData) {
    try {//  w ww  .j ava 2  s  . c  o  m
        SQLiteDatabase db = itsDbHelper.getWritableDatabase();
        try {
            db.beginTransaction();
            Long id = getDbUriId(fileData.getUri(), db);
            if (id != null) {
                doUpdatePasswdFileData(id, fileData, db);
            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } catch (SQLException e) {
        Log.e(TAG, "Database error", e);
    }
}

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

@Override
public void addAll(final Pages pages) {
    new Thread() {
        @Override// w w  w.  j a v a2  s . co  m
        public void run() {
            SQLiteDatabase writableDatabase = getWritableDatabase();

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

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

public void deleteProject(long id) {
    SQLiteDatabase db = db();
    db.beginTransaction();//from w  w  w  .  jav  a  2s .com
    try {
        delete(Project.class, id);
        ContentValues values = new ContentValues();
        values.put("project_id", 0);
        db.update("transactions", values, "project_id=?", new String[] { String.valueOf(id) });
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}

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

@Override
public void addAll(final Menus menus) {
    new Thread() {
        @Override/*  w  w  w  .ja v  a 2s .c  o  m*/
        public void run() {
            SQLiteDatabase writableDatabase = getWritableDatabase();

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

From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java

@Override
protected Integer doInBackground(Void... params) {

    SharedPreferences prefs = dataService.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE);

    // Connectivity receiver.
    final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    ComponentName receiver = new ComponentName(dataService, WifiReceiver.class);
    PackageManager pm = dataService.getPackageManager();
    if (activeNetwork == null || !activeNetwork.isConnected()) {
        // We've missed a scheduled update. Enable the receiver so it can launch an update when we reconnect.
        Log.d(LOG_TAG, "Missed library update: not connected. Enabling connectivity receiver.");
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
        return RESULT_CODE_FAILURE;
    } else {/* w ww  .ja va 2s .  c  om*/
        // We are connected. Disable the receiver.
        Log.d(LOG_TAG, "Library updater connected. Disabling connectivity receiver.");
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

    InputStream in = null;
    String etag = prefs.getString(SETTING_LIBRARY_ETAG, null);

    try {
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        if (etag != null && !force) {
            conn.setRequestProperty("If-None-Match", etag);
        }

        int code = conn.getResponseCode();
        switch (code) {
        case HttpStatus.SC_NOT_MODIFIED:
            // If we got a 304, we're done.
            // Use failure code to indicate there is no temp db to copy over.
            Log.d(LOG_TAG, "304 in library response.");
            return RESULT_CODE_FAILURE;
        default:
            // Odd, but on 1/3/13 I received correct json responses with a -1 for responseCode. Fall through.
            Log.w(LOG_TAG, "Error code in library response: " + code);
        case HttpStatus.SC_OK:
            // Parse response.
            in = conn.getInputStream();
            JsonFactory factory = new JsonFactory();
            final JsonParser parser = factory.createJsonParser(in);

            SQLiteDatabase tempDb = tempDbHelper.getWritableDatabase();
            tempDb.beginTransaction();
            try {
                tempDb.execSQL("delete from topic");
                tempDb.execSQL("delete from topicvideo");
                tempDb.execSQL("delete from video");

                parseObject(parser, tempDb, null, 0);
                tempDb.setTransactionSuccessful();
            } catch (Exception e) {
                e.printStackTrace();
                return RESULT_CODE_FAILURE;
            } finally {
                tempDb.endTransaction();
                tempDb.close();
            }

            // Save etag once we've successfully parsed the response.
            etag = conn.getHeaderField("ETag");
            prefs.edit().putString(SETTING_LIBRARY_ETAG, etag).apply();

            // Move this new content from the temp db into the main one.
            mergeDbs();

            return RESULT_CODE_SUCCESS;
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        tempDbHelper.close();
    }

    return RESULT_CODE_FAILURE;
}

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

@Override
public void addAll(final Affiliations affiliations) {
    new Thread() {
        @Override/*from   w  w  w .j  a v a  2 s .com*/
        public void run() {
            SQLiteDatabase writableDatabase = getWritableDatabase();

            writableDatabase.beginTransaction();
            try {
                for (Affiliation affiliation : affiliations) {
                    String query = "INSERT OR REPLACE INTO " + affiliations.getTableName() + " VALUES (\""
                            + affiliation.getId() + "\", \"" + affiliation.getPageId() + "\", \""
                            + affiliation.getGroupId() + "\", " + affiliation.getOrder() + ");";
                    getWritableDatabase().execSQL(query);
                }
                writableDatabase.setTransactionSuccessful();
            } catch (JSONException e) {
                System.out.println("Malformed json in affiliations");
                e.printStackTrace();
            } finally {
                writableDatabase.endTransaction();
            }
        }
    }.start();
}

From source file:org.jumpmind.symmetric.android.AndroidSqlTemplate.java

public int update(final boolean autoCommit, final boolean failOnError, boolean failOnDrops,
        boolean failOnSequenceCreate, final int commitRate, final ISqlResultsListener resultsListener,
        final ISqlStatementSource source) {
    int row = 0;/*from   w ww . ja v a 2  s  .c  o  m*/
    SQLiteDatabase database = this.databaseHelper.getWritableDatabase();
    String currentStatement = null;
    try {
        if (!autoCommit) {
            database.beginTransaction();
        }

        for (String statement = source.readSqlStatement(); statement != null; statement = source
                .readSqlStatement()) {
            currentStatement = statement;
            update(statement);
            row++;
            if (!autoCommit && row % commitRate == 0) {
                database.setTransactionSuccessful();
                database.endTransaction();
                database.beginTransaction();
            }

            if (resultsListener != null) {
                resultsListener.sqlApplied(statement, row, 0, row);
            }
        }

        if (!autoCommit) {
            database.setTransactionSuccessful();
        }
    } catch (RuntimeException ex) {
        if (resultsListener != null) {
            resultsListener.sqlErrored(currentStatement, translate(currentStatement, ex), row, false, false);
        }
        throw ex;
    } finally {
        if (!autoCommit) {
            database.endTransaction();
        }

        close(database);
    }

    return row;
}

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

public void insert(List<T> items, int conflictAlgorithm) {
    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {/*  ww  w.j a  v a2  s  . c o  m*/
        db.beginTransaction();
        for (T item : items)
            db.insertWithOnConflict(mTableName, null, itemToRow(item), conflictAlgorithm);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}