当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteDatabase.setTransactionSuccessful方法代码示例

本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.setTransactionSuccessful方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.setTransactionSuccessful方法的具体用法?Java SQLiteDatabase.setTransactionSuccessful怎么用?Java SQLiteDatabase.setTransactionSuccessful使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.sqlite.SQLiteDatabase的用法示例。


在下文中一共展示了SQLiteDatabase.setTransactionSuccessful方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@SuppressWarnings("SameParameterValue")
private void upsert(@NonNull SQLiteDatabase db, @NonNull String table, @NonNull ContentValues values, @NonNull String idCol) {
	try {
		db.beginTransaction();
		String   where = idCol + " = ?";
		String[] args  = {values.getAsString(idCol)};
		int      rows  = db.update(table, values, where, args);
		if (rows == 0) {
			long inserted = db.insert(table, null, values);
			if (inserted == -1) {
				throw new SQLException("failed to insert row into '" + table + "' - see logcat.");
			}
		}
		db.setTransactionSuccessful();
	} finally {
		db.endTransaction();
	}
}
 
开发者ID:lambdasoup,项目名称:blockvote,代码行数:19,代码来源:StatsProvider.java

示例2: addCinema

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addCinema(Cinema cinema) {
    if(getCinemaByID(cinema.getID()) != null) {
        updateCinema(cinema);
    } else {
        SQLiteDatabase db = getWritableDatabase();
        db.beginTransaction();
        try {
            db.insertOrThrow("Cinemas", null, cinema.toContentValues());
            db.setTransactionSuccessful();
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            db.endTransaction();
        }
    }
}
 
开发者ID:jpelgrom,项目名称:Movie-Notifier-Android,代码行数:17,代码来源:DBHelper.java

示例3: runCase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public Metrics runCase() {
    mDbHelper = new DbHelper(App.getInstance(), IntegerSQLiteStatementTransactionCase.class.getSimpleName());
    Metrics result = new Metrics(getClass().getSimpleName()+" ("+mInsertions+" insertions)", mTestSizeIndex);
    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    result.started();
    SQLiteStatement stmt = db.compileStatement("INSERT INTO inserts_1 (val) VALUES (?)");
    db.beginTransaction();
    for (int i = 0; i < mInsertions; i++) {
        stmt.bindLong(1, mRandom.nextInt());
        stmt.executeInsert();
        stmt.clearBindings();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    result.finished();
    return result;
}
 
开发者ID:jasonwyatt,项目名称:SQLite-Performance,代码行数:20,代码来源:IntegerSQLiteStatementTransactionCase.java

示例4: getBoomId

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public List getBoomId() {
    String coloumns[] = {BOOM};
    SQLiteDatabase db = this.getWritableDatabase();
    db.beginTransaction();
    Cursor cursor = db.query(TABLE_NAME12, coloumns, null, null, null, null, null);
    List<Integer> list = new ArrayList<>();
    while (cursor.moveToNext()) {
        int boomValue = cursor.getInt(0);
        list.add(boomValue);
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    cursor.close();
    db.close();
    return list;
}
 
开发者ID:sarveshchavan7,项目名称:Trivia-Knowledge,代码行数:17,代码来源:DemoHelperClass.java

示例5: delete

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int delete(final String table, @Nullable final String selection, @Nullable final String[] selectionArgs) {
    final SQLiteDatabase database = mHelper.getWritableDatabase();
    int count = 0;

    database.beginTransaction();

    try {
        count = database.delete(table, selection, selectionArgs);

        database.setTransactionSuccessful();
    } catch (final Exception e) {
        Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage());
    } finally {
        database.endTransaction();
    }

    return count;
}
 
开发者ID:IstiN,项目名称:android-training-2017,代码行数:20,代码来源:DbOperations.java

示例6: bulkInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    final SQLiteDatabase db = mDBHelper.getWritableDatabase();
    String tableName = getTableName(uri);
    int insertedCount = 0;

    try {
        db.beginTransaction();
        for (ContentValues cv : values) {
            long _id = db.insert(tableName, null, cv);
            if (_id > 0) {
                insertedCount++;
            }
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        //db.close();
    }

    Context context = getContext();
    if (context != null) {
        context.getContentResolver().notifyChange(uri, null);
    }

    return insertedCount;
}
 
开发者ID:agpyaephyo,项目名称:PADC-SFC-News,代码行数:28,代码来源:MMNewsProvider.java

示例7: save

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static List<User> save(@NonNull SQLiteDatabase database, @NonNull List<User> users) {
    final SQLiteStatement statement = database.compileStatement(UserContract.Script.Insert.INSERT);
    try {
        database.beginTransaction();
        for (User user : users) {
            insertUser(statement, user);
        }
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
    return users;
}
 
开发者ID:shevart,项目名称:Android-SQLite-Master-Project,代码行数:14,代码来源:UserDao.java

示例8: deleteTransaction

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void deleteTransaction(long id) {
       SQLiteDatabase db = db();
	db.beginTransaction();
	try {
           deleteTransactionNoDbTransaction(id);
		db.setTransactionSuccessful();
	} finally {
		db.endTransaction();			
	}
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:11,代码来源:DatabaseAdapter.java

示例9: delete

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public int delete(final TagModel data) {
    long id = data.getId();
    int count = 0;
    SQLiteDatabase db = getDatabase();
    try {
        db.beginTransaction();
        count = db.delete(DataBaseHelper.TABLE_TAGS, COLUMN_TAG_ID + " = " + id, null);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
    } finally {
        db.endTransaction();
    }
    return count;
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:16,代码来源:TagDAO.java

示例10: deleteRecordDetails

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void deleteRecordDetails(final RecordDetailsModel recordDetailsModel) {
    long id = recordDetailsModel.getId();
    SQLiteDatabase db = getDatabase();
    try {
        db.beginTransaction();
        db.delete(DataBaseHelper.TABLE_RECORDS_DETAILS, COLUMN_RECORD_DETAILS_ID + " = " + id, null);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
    } finally {
        db.endTransaction();
    }
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:14,代码来源:RecordDetailsDAO.java

示例11: deleteSelectedTransactions

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
    * Deletes the selected transactions
    * @param ids selected transactions' ids
    */
public void deleteSelectedTransactions(long[] ids) {
       SQLiteDatabase db = db();
	db.beginTransaction();
	try {
		for (long id : ids) {
			deleteTransactionNoDbTransaction(id);
		}
		db.setTransactionSuccessful();
	} finally {
		db.endTransaction();
	}
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:17,代码来源:DatabaseAdapter.java

示例12: bulkInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Handles requests to insert a set of new rows. In Sunshine, we are only going to be
 * inserting multiple rows of data at a time from a weather forecast. There is no use case
 * for inserting a single row of data into our ContentProvider, and so we are only going to
 * implement bulkInsert. In a normal ContentProvider's implementation, you will probably want
 * to provide proper functionality for the insert method as well.
 *
 * @param uri    The content:// URI of the insertion request.
 * @param values An array of sets of column_name/value pairs to add to the database.
 *               This must not be {@code null}.
 *
 * @return The number of values that were inserted.
 */
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    switch (sUriMatcher.match(uri)) {

        case CODE_WEATHER:
            db.beginTransaction();
            int rowsInserted = 0;
            try {
                for (ContentValues value : values) {
                    long weatherDate =
                            value.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE);
                    if (!SunshineDateUtils.isDateNormalized(weatherDate)) {
                        throw new IllegalArgumentException("Date must be normalized to insert");
                    }

                    long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value);
                    if (_id != -1) {
                        rowsInserted++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }

            if (rowsInserted > 0) {
                getContext().getContentResolver().notifyChange(uri, null);
            }

            return rowsInserted;

        default:
            return super.bulkInsert(uri, values);
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:51,代码来源:WeatherProvider.java

示例13: deleteProject

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void deleteProject(long id) {
       SQLiteDatabase db = db();
	db.beginTransaction();
	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();
	}		
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:14,代码来源:MyEntityManager.java

示例14: performRestore

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static boolean performRestore(DatabaseHelper helper) {
    SQLiteDatabase db = helper.getWritableDatabase();
    db.beginTransaction();
    try {
        new RestoreDbTask().sanitizeDB(helper, db);
        db.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        FileLog.e(TAG, "Failed to verify db", e);
        return false;
    } finally {
        db.endTransaction();
    }
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:15,代码来源:RestoreDbTask.java

示例15: createTables

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void createTables(final SQLiteDatabase readableConnection, final Class<?>[] tableClassArray) {

        readableConnection.beginTransaction();

        try {
            for (final Class<?> tableClass : tableClassArray) {
                final dbTable dbTableAnnotation = tableClass.getAnnotation(dbTable.class);
                if (dbTableAnnotation != null) {
                    final String dbTableName = dbTableAnnotation.value();

                    if (TextUtils.isEmpty(dbTableName)) {
                        return;
                    }

                    final StringBuilder stringBuilder = new StringBuilder();

                    final Field[] fields = tableClass.getFields();
                    final int fieldCount = fields.length;
                    for (int i = 0; i < fieldCount; i++) {
                        final Field field = fields[i];
                        final Annotation[] fieldAnnotations = field.getAnnotations();
                        final String fieldName = (String) field.get(null);
                        String fieldType = null;

                        for (final Annotation fieldAnnotation : fieldAnnotations) {
                            final Class<?> fieldAnnotationType = fieldAnnotation.annotationType();
                            if (fieldAnnotationType.equals(dbString.class)) {
                                fieldType = ((dbString) fieldAnnotation).value();
                            } else if (fieldAnnotationType.equals(dbLong.class)) {
                                fieldType = ((dbLong) fieldAnnotation).value();
                            } else if (fieldAnnotationType.equals(dbInteger.class)) {
                                fieldType = ((dbInteger) fieldAnnotation).value();
                            }
                            if (!TextUtils.isEmpty(fieldType)) {
                                stringBuilder.append(fieldName + " " + fieldType + ",");
                            }
                        }

                    }

                    //TODO think about solution if last field marked some annotation;
                    stringBuilder.deleteCharAt(stringBuilder.length() - 1);

                    final String tableCreteQuery = String.format(TABLE_TEMPLATE, dbTableName, stringBuilder.toString());
                    readableConnection.execSQL(tableCreteQuery);
                    Log.d(TAG, "createTables() returned: " + tableCreteQuery);
                }
            }
            readableConnection.setTransactionSuccessful();
        } catch (final Exception e) {
            Log.e(TAG, "create table exception", e);
        } finally {
            readableConnection.endTransaction();
        }

    }
 
开发者ID:IstiN,项目名称:android-training-2017,代码行数:57,代码来源:SqlConnector.java


注:本文中的android.database.sqlite.SQLiteDatabase.setTransactionSuccessful方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。