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


Java SQLiteDatabase.endTransaction方法代码示例

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


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

示例1: addPathImpl

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void addPathImpl(File file) {
    if (file == null || contains(file)) {
        return;
    }
    String path = FileUtil.safeGetCanonicalPath(file);

    final SQLiteDatabase database = getWritableDatabase();
    database.beginTransaction();

    try {
        // add the entry
        final ContentValues values = new ContentValues(1);
        values.put(BlacklistStoreColumns.PATH, path);
        database.insert(BlacklistStoreColumns.NAME, null, values);

        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:21,代码来源:BlacklistStore.java

示例2: bulkInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    switch (match) {
        case WEATHER:
            db.beginTransaction();
            int returnCount = 0;
            try {
                for (ContentValues value : values) {
                    normalizeDate(value);
                    long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value);
                    if (_id != -1) {
                        returnCount++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
            getContext().getContentResolver().notifyChange(uri, null);
            return returnCount;
        default:
            return super.bulkInsert(uri, values);
    }
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:27,代码来源:WeatherProvider.java

示例3: bulkInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    SQLiteDatabase database = openHelper(getContext()).getWritableDatabase();
    Contract contract = findMatchingContract(uri);

    try {
        database.beginTransaction();

        for (ContentValues value : values) {
            database.insert(contract.getTable(), null, value);
        }

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

    if (values.length > 0)
        getContext().getContentResolver().notifyChange(uri, null);

    database.close();

    return values.length;
}
 
开发者ID:mecid,项目名称:robird-reborn,代码行数:25,代码来源:RobirdContentProvider.java

示例4: setCategoryOrder

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void setCategoryOrder(List<String> apps) {
    SQLiteDatabase db = this.getWritableDatabase();

    try {
        db.beginTransaction();

        for (int i = 0; i < apps.size(); i++) {

            ContentValues values = new ContentValues();

            values.put(INDEX, i);

            db.update(TAB_ORDER_TABLE, values, CATID + "=?", new String[]{apps.get(i)});
        }

        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e("LaunchDB", "Can't setCategoryOrder ", e);

    } finally {
        db.endTransaction();
    }
}
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:24,代码来源:DB.java

示例5: isFavorite

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean isFavorite(long songId) {
    final SQLiteDatabase database = mMusicDatabase.getWritableDatabase();
    database.beginTransaction();

    Cursor cursor = null;
    try {
        cursor = database.query(FavoriteSongColumns.NAME, new String[]{FavoriteSongColumns.SONGID},
                FavoriteSongColumns.SONGID + " =? ", new String[]{String.valueOf(songId)}, null, null, null);
        if (cursor != null && cursor.getCount() > 0) {
            return true;
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        database.setTransactionSuccessful();
        database.endTransaction();
    }
    return false;
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:21,代码来源:FavoriteSong.java

示例6: applyBatch

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Apply the given set of {@link ContentProviderOperation}, executing inside
 * a {@link SQLiteDatabase} transaction. All changes will be rolled back if
 * any single one fails.
 */
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        final int numOperations = operations.size();
        final ContentProviderResult[] results = new ContentProviderResult[numOperations];
        for (int i = 0; i < numOperations; i++) {
            results[i] = operations.get(i).apply(this, results, i);
        }
        db.setTransactionSuccessful();
        return results;
    } finally {
        db.endTransaction();
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:23,代码来源:ScheduleProvider.java

示例7: addForward

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addForward(int protocol, int dport, String raddr, int rport, int ruid) {
    lock.writeLock().lock();
    try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            ContentValues cv = new ContentValues();
            cv.put("protocol", protocol);
            cv.put("dport", dport);
            cv.put("raddr", raddr);
            cv.put("rport", rport);
            cv.put("ruid", ruid);

            if (db.insert("forward", null, cv) < 0)
                Log.e(TAG, "Insert forward failed");

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyForwardChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:27,代码来源:DatabaseHelper.java

示例8: deleteAttribute

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void deleteAttribute(long id) {
       SQLiteDatabase db = db();
	db.beginTransaction();
	try {
		Attribute attr=getAttribute(id);
		String key=attr.remoteKey;
		String[] p = new String[]{String.valueOf(id)};
		db.delete(ATTRIBUTES_TABLE, AttributeColumns.ID+"=?", p);
		db.delete(CATEGORY_ATTRIBUTE_TABLE, CategoryAttributeColumns.ATTRIBUTE_ID+"=?", p);
		db.delete(TRANSACTION_ATTRIBUTE_TABLE, TransactionAttributeColumns.ATTRIBUTE_ID+"=?", p);
		db.setTransactionSuccessful();
		writeDeleteLog(ATTRIBUTES_TABLE, key);
	} finally {
		db.endTransaction();
	}
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:17,代码来源:DatabaseAdapter.java

示例9: onCreate

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onCreate(SQLiteDatabase database) {
    try {
        database.beginTransaction();

        new PlanTable().create(database);
        new IncomePlanTable().create(database);
        new ExpensesPlanTable().create(database);
        new IncomeTable().create(database);
        new ExpensesTable().create(database);

        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
 
开发者ID:kerick-jeff,项目名称:MyBP,代码行数:17,代码来源:DatabaseHelper.java

示例10: insertInBulk

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private int insertInBulk(SQLiteDatabase database, String tableName, ContentValues[] values) {
    database.beginTransaction();

    for (ContentValues value : values) {
        database.insertOrThrow(tableName, null, value);
    }

    database.setTransactionSuccessful();
    database.endTransaction();
    return values.length;
}
 
开发者ID:Madrapps,项目名称:AsyncQuery,代码行数:12,代码来源:DataProvider.java

示例11: replaceRate

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

示例12: testSizeAgeOff

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Test
public void testSizeAgeOff() throws IOException {
    int numPackets = 110000;
    List<DataPacket> dataPackets = new ArrayList<>(numPackets);
    for (int i = 0; i < numPackets; i++) {
        dataPackets.add(new ByteArrayDataPacket(Collections.singletonMap("id", "testId" + i), ("testPayload" + i).getBytes(Charsets.UTF_8)));
    }
    sqLiteDataPacketQueue.enqueue(dataPackets.iterator());
    Collections.reverse(dataPackets);

    List<DataPacket> expectedDataPackets = new ArrayList<>();
    long size = 0L;
    for (DataPacket dataPacket : dataPackets) {
        size += sqLiteDataPacketQueue.getAttributesBytes(dataPacket).length;
        size += dataPacket.getSize();
        if (size <= MAX_SIZE) {
            expectedDataPackets.add(dataPacket);
        }
    }

    SQLiteDatabase writableDatabase = siteToSiteDB.getWritableDatabase();
    writableDatabase.beginTransaction();
    try {
        sqLiteDataPacketQueue.ageOffSize(writableDatabase);
        writableDatabase.setTransactionSuccessful();
    } finally {
        writableDatabase.endTransaction();
        writableDatabase.close();
    }

    assertDataPacketsMatchIterator(expectedDataPackets);
}
 
开发者ID:hortonworks,项目名称:nifi-android-s2s,代码行数:33,代码来源:SQLiteDataPacketQueueTest.java

示例13: 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:gmontoya2483,项目名称:GoUbiquitous,代码行数:51,代码来源:WeatherProvider.java

示例14: onUpgrade

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  db.beginTransaction();
  try {
    db.execSQL(SQL_DROP_TABLE);
    db.setTransactionSuccessful();
  } finally {
    db.endTransaction();
  }
  onCreate(db);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:MediaVariationsIndexDatabase.java

示例15: insertOrUpdateUpdate

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public Long insertOrUpdateUpdate(UpdateModel update) {
    SQLiteDatabase writableDatabase = this.openHelper.getWritableDatabase();
    writableDatabase.beginTransaction();
    try {
        Long valueOf;
        ContentValues contentValues = new ContentValues();
        contentValues.put(DBConstants.UPDATE_COL_TYPE, Integer.valueOf(update.getType()));
        contentValues.put(DBConstants.UPDATE_COL_OLD_VALUE, update.getOldValue());
        contentValues.put(DBConstants.UPDATE_COL_NEW_VALUE, update.getNewValue());
        contentValues.put(DBConstants.UPDATE_COL_USER_ID, Integer.valueOf(update.getUserId()));
        contentValues.put(DBConstants.UPDATE_COL_IS_NEW, Integer.valueOf(update.isNew() ? 1 : 0));
        if (update.getChangeDate() != null) {
            contentValues.put(DBConstants.UPDATE_COL_CHANGE_DATE, update.getChangeDate());
        }
        if (update.getId() == null) {
            long result = writableDatabase.insertOrThrow(DBConstants.TABLE_UPDATE, null, contentValues);
            writableDatabase.setTransactionSuccessful();
            valueOf = Long.valueOf(result);
        } else {
            writableDatabase.update(DBConstants.TABLE_UPDATE, contentValues, "_id=" + update.getId().longValue(), null);
            writableDatabase.setTransactionSuccessful();
            valueOf = update.getId();
            writableDatabase.endTransaction();
        }
        return valueOf;
    } finally {
        writableDatabase.endTransaction();
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:30,代码来源:DataBaseAccess.java


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