本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.inTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.inTransaction方法的具体用法?Java SQLiteDatabase.inTransaction怎么用?Java SQLiteDatabase.inTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase.inTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUriAndNotify
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* returns that baseUri with appended Id and
* if not in an transaction calls notifyChange for the baseUri and any additional Uri
*/
private final static Uri createUriAndNotify(long rowId, SQLiteDatabase db,
Uri baseUri, ContentResolver cr, Uri... additionalNotifications) {
if (rowId < 0) return null;
Uri returnValue = ContentUris.withAppendedId(baseUri, rowId);
// only notify when not in an transaction
if (!db.inTransaction()) {
cr.notifyChange(baseUri, null);
if (additionalNotifications != null)
for (Uri additional : additionalNotifications)
cr.notifyChange(additional, null);
}
return returnValue;
}
示例2: delete
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
if (DBG) Log.d(TAG, "DELTE " + uri);
int match = URI_MATCHER.match(uri);
SQLiteDatabase db = mDbHolder.get();
// direct access to raw tables
if (match == RAW) {
String tableName = uri.getLastPathSegment();
int result = db.delete(tableName, selection, selectionArgs);
if (result > 0 && !db.inTransaction()) {
mCr.notifyChange(MusicStore.ALL_CONTENT_URI, null);
}
return result;
}
// the rest uses the usual way as in Android
int count;
synchronized (sGetTableAndWhereParam) {
getTableAndWhere(uri, match, selection, sGetTableAndWhereParam);
switch (match) {
case FILES:
case FILES_ID:
case AUDIO_MEDIA:
case AUDIO_MEDIA_ID:
return forwardDelete(db, sGetTableAndWhereParam.table, sGetTableAndWhereParam.where, selectionArgs);
case AUDIO_GENRES_ID_MEMBERS:
count = db.delete(MusicOpenHelper.AUDIO_GENRES_MAP_TABLE_NAME,
sGetTableAndWhereParam.where, selectionArgs);
break;
default:
count = db.delete(sGetTableAndWhereParam.table,
sGetTableAndWhereParam.where, selectionArgs);
break;
}
}
// TODO reset Artist / Album cache?
// since deletes may affect a lot of stuff notify everywhere.
if (count > 0 && !db.inTransaction())
mCr.notifyChange(MusicStore.ALL_CONTENT_URI, null);
return count;
}
示例3: update
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
String table;
switch (sUriMatcher.match(uri)) {
case EPISODE_ID:
selection = "_id=?";
selectionArgs = new String[] { uri.getLastPathSegment() };
//$FALL-THROUGH$
case EPISODE:
table = ScraperTables.EPISODE_TABLE_NAME;
break;
case SHOW_ID:
selection = "_id=?";
selectionArgs = new String[] { uri.getLastPathSegment() };
//$FALL-THROUGH$
case SHOW:
case SHOW_NAME:
table = ScraperTables.SHOW_TABLE_NAME;
break;
case MOVIE_ID:
selection = "_id=?";
selectionArgs = new String[] { uri.getLastPathSegment() };
//$FALL-THROUGH$
case MOVIE:
table = ScraperTables.MOVIE_TABLE_NAME;
break;
case MOVIE_BACKDROPS:
table = ScraperTables.MOVIE_BACKDROPS_TABLE_NAME;
break;
case MOVIE_POSTERS:
table = ScraperTables.MOVIE_POSTERS_TABLE_NAME;
break;
case SHOW_BACKDROPS:
table = ScraperTables.SHOW_BACKDROPS_TABLE_NAME;
break;
case SHOW_POSTERS:
table = ScraperTables.SHOW_POSTERS_TABLE_NAME;
break;
default:
throw new IllegalArgumentException("URI not supported in update(): " + uri);
}
SQLiteDatabase db = mDbHolder.get();
int updated = db.update(table, values,
selection, selectionArgs);
if (updated > 0 && !db.inTransaction()) {
mCr.notifyChange(uri, null);
mCr.notifyChange(VideoStore.Video.Media.EXTERNAL_CONTENT_URI, null);
}
return updated;
}
示例4: delete
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
if (DBG) Log.d(TAG, "DELTE " + uri);
int match = URI_MATCHER.match(uri);
// let ScraperProvider handle that
if (ScraperProvider.handles(match))
return mScraperProvider.delete(uri, selection, selectionArgs);
SQLiteDatabase db = mDbHolder.get();
switch (match) {
case UriMatcher.NO_MATCH:
case FILES:
case FILES_ID:
case VIDEO_MEDIA:
case VIDEO_MEDIA_ID:
// those must be deleted in Android's db and the result imported
throw new IllegalStateException("delete not supported, has to be done via Android's MediaStore");
case RAW:
String tableName = uri.getLastPathSegment();
int result = db.delete(tableName, selection, selectionArgs);
if (result > 0 && !db.inTransaction()) {
mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
}
return result;
case VIDEO_LIST:
selection+= " AND "+ VideoStore.VideoList.Columns.LIST_ID+" = ?";
List<String> whereArgs = new ArrayList<String>(Arrays.asList(selectionArgs));
whereArgs.add(uri.getLastPathSegment());
result = db.delete(ListTables.VIDEO_LIST_TABLE, selection, whereArgs.toArray(new String[0]));
mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
return result;
case LIST:
result = db.delete(ListTables.LIST_TABLE, selection, selectionArgs);
mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
return result;
}
// the rest uses the usual way as in Android
int count;
GetTableAndWhereOutParameter tableAndWhere = sGetTableAndWhereParam.get();
getTableAndWhere(uri, match, selection, tableAndWhere);
count = db.delete(tableAndWhere.table, tableAndWhere.where, selectionArgs);
if (count > 0 && !db.inTransaction())
mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
return count;
}