本文整理汇总了Java中android.database.DatabaseUtils.InsertHelper.close方法的典型用法代码示例。如果您正苦于以下问题:Java InsertHelper.close方法的具体用法?Java InsertHelper.close怎么用?Java InsertHelper.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.DatabaseUtils.InsertHelper
的用法示例。
在下文中一共展示了InsertHelper.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bulkInsert
import android.database.DatabaseUtils.InsertHelper; //导入方法依赖的package包/类
@Override
public int bulkInsert(Uri uri, ContentValues[] valuesAr) {
final String table;
switch (matcher.match(uri)) {
case MATCH_TQUESTIONS_URI_CONTENT: {
table = PollsData.TQuestions.TABLE_NAME;
break;
}
case MATCH_TPOLLGROUPS_URI_CONTENT: {
table = PollsData.TPollGroups.TABLE_NAME;
break;
}
case MATCH_TPOLLS_URI_CONTENT: {
table = PollsData.TPolls.TABLE_NAME;
break;
}
case MATCH_TVARIANTS_URI_CONTENT: {
table = PollsData.TVariants.TABLE_NAME;
break;
}
case MATCH_TPOINT_HISTORY_URI_CONTENT: {
table = PollsData.TPointHistory.TABLE_NAME;
break;
}
default:
throw new IllegalArgumentException("Unsupported uri " + uri);
}
SQLiteDatabase sql = dbHelper.getWritableDatabase();
sql.beginTransaction();
int count = 0;
try {
InsertHelper ih = new InsertHelper(sql, table);
for (ContentValues values : valuesAr) {
ih.replace(values);
count++;
}
ih.close();
sql.setTransactionSuccessful();
} finally {
sql.endTransaction();
}
if (!ignoreNotify(uri)) {
notifyUri(contentResolver, uri);
}
return count;
}
示例2: bulkInsert
import android.database.DatabaseUtils.InsertHelper; //导入方法依赖的package包/类
@Override
public int bulkInsert(Uri uri, ContentValues[] valuesAr) {
final String table;
switch(matcher.match(uri)){
case MATCH_CARS_URI_CONTENT:{
table = Cars.TABLE_NAME;
break;
}
case MATCH_BLACKLIST_URI_CONTENT:{
table = BlackList.TABLE_NAME;
break;
}
case MATCH_TIMES_URI_CONTENT:{
table = Times.TABLE_NAME;
break;
}
case MATCH_SUBSCRIPTIONS_URI_CONTENT:{
table = Subscriptions.TABLE_NAME;
break;
}
case MATCH_ROADS_URI_CONTENT:{
table = Roads.TABLE_NAME;
break;
}
case MATCH_ROADGROUPS_URI_CONTENT:{
table = RoadGroups.TABLE_NAME;
break;
}
case MATCH_FLATS_URI_CONTENT:{
table = Flats.TABLE_NAME;
break;
}
default:
throw new IllegalArgumentException("Unsupported uri " + uri);
}
SQLiteDatabase sql = dbHelper.getWritableDatabase();
sql.beginTransaction();
int count = 0;
try {
InsertHelper ih = new InsertHelper(sql, table);
for (ContentValues values : valuesAr) {
ih.replace(values);
count++;
}
ih.close();
sql.setTransactionSuccessful();
} finally {
sql.endTransaction();
}
if (!ignoreNotify(uri)) {
notifyUri(contentResolver, uri);
}
return count;
}
示例3: bulkInsertUsers
import android.database.DatabaseUtils.InsertHelper; //导入方法依赖的package包/类
private int bulkInsertUsers(final ContentValues[] values) {
int numInserted = 0;
final SQLiteDatabase db = this.dbHelper.getWritableDatabase();
final InsertHelper ih = new InsertHelper(db, UserInfo.TABLE_NAME);
final int id = ih.getColumnIndex(BasicColumns.ID);
final int ownerId = ih.getColumnIndex(BasicColumns.OWNER_ID);
final int screenName = ih.getColumnIndex(UserInfo.SCREEN_NAME);
final int location = ih.getColumnIndex(UserInfo.LOCATION);
final int gender = ih.getColumnIndex(UserInfo.GENDER);
final int birthday = ih.getColumnIndex(UserInfo.BIRTHDAY);
final int description = ih.getColumnIndex(UserInfo.DESCRIPTION);
final int profileImageUrl = ih
.getColumnIndex(UserInfo.PROFILE_IMAGE_URL);
final int url = ih.getColumnIndex(UserInfo.URL);
final int protect = ih.getColumnIndex(UserInfo.PROTECTED);
final int followersCount = ih.getColumnIndex(UserInfo.FOLLOWERS_COUNT);
final int friendsCount = ih.getColumnIndex(UserInfo.FRIENDS_COUNT);
final int favoritesCount = ih.getColumnIndex(UserInfo.FAVORITES_COUNT);
final int statusesCount = ih.getColumnIndex(UserInfo.STATUSES_COUNT);
final int following = ih.getColumnIndex(UserInfo.FOLLOWING);
final int createdAt = ih.getColumnIndex(BasicColumns.CREATED_AT);
final int type = ih.getColumnIndex(BasicColumns.TYPE);
try {
db.beginTransaction();
for (final ContentValues value : values) {
ih.prepareForInsert();
ih.bind(id, value.getAsString(BasicColumns.ID));
ih.bind(ownerId, value.getAsString(BasicColumns.OWNER_ID));
ih.bind(screenName, value.getAsString(UserInfo.SCREEN_NAME));
ih.bind(location, value.getAsString(UserInfo.LOCATION));
ih.bind(gender, value.getAsString(UserInfo.GENDER));
ih.bind(birthday, value.getAsString(UserInfo.BIRTHDAY));
ih.bind(description, value.getAsString(UserInfo.DESCRIPTION));
ih.bind(profileImageUrl,
value.getAsString(UserInfo.PROFILE_IMAGE_URL));
ih.bind(url, value.getAsString(UserInfo.URL));
ih.bind(protect, value.getAsBoolean(UserInfo.PROTECTED));
ih.bind(followersCount,
value.getAsInteger(UserInfo.FOLLOWERS_COUNT));
ih.bind(friendsCount,
value.getAsInteger(UserInfo.FRIENDS_COUNT));
ih.bind(favoritesCount,
value.getAsInteger(UserInfo.FAVORITES_COUNT));
ih.bind(statusesCount,
value.getAsInteger(UserInfo.STATUSES_COUNT));
ih.bind(following, value.getAsBoolean(UserInfo.FOLLOWING));
ih.bind(createdAt, value.getAsLong(BasicColumns.CREATED_AT));
ih.bind(type, value.getAsInteger(BasicColumns.TYPE));
final long result = ih.execute();
if (result > -1) {
numInserted++;
}
}
if (AppContext.DEBUG) {
log("bulkInsertUsers insert rows=" + numInserted);
}
db.setTransactionSuccessful();
} catch (final Exception e) {
if (AppContext.DEBUG) {
e.printStackTrace();
}
} finally {
ih.close();
db.endTransaction();
}
return numInserted;
}
示例4: insertBulkCallList
import android.database.DatabaseUtils.InsertHelper; //导入方法依赖的package包/类
public void insertBulkCallList(ArrayList<SMSMessage> smsList){
SQLiteDatabase db = this.getWritableDatabase();
try{
// Create a single InsertHelper to handle this set of insertions.
InsertHelper ih = new InsertHelper(db, SMSListTable.TABLE_NAME);
// Get the numeric indexes for each of the columns that we're updating
final int smsIdColumn = ih.getColumnIndex(SMSListTable.smsId);
final int phoneColumn = ih.getColumnIndex(SMSListTable.phoneNumber);
final int threadIDColumn = ih.getColumnIndex(SMSListTable.threadID);
final int typeColumn = ih.getColumnIndex(SMSListTable.type);
final int dateColumn = ih.getColumnIndex(SMSListTable.date);
final int smsPartsColumn = ih.getColumnIndex(SMSListTable.smsParts);
try {
for (SMSMessage smsMessage : smsList) {
if(smsMessage!=null){
// ... Create the data for this row (not shown) ...
// Get the InsertHelper ready to insert a single row
ih.prepareForInsert();
// Add the data for each column
ih.bind(smsIdColumn, smsMessage.getId());
ih.bind(phoneColumn, smsMessage.getNumber());
ih.bind(threadIDColumn, smsMessage.getThreadID());
ih.bind(typeColumn, smsMessage.getType());
ih.bind(dateColumn, smsMessage.getDate());
ih.bind(smsPartsColumn, smsMessage.getSmsParts());
// Insert the row into the database.
ih.execute();
}
}
}catch(Exception e){
e.printStackTrace();
}finally {
if(ih!=null )
ih.close(); // See comment below from Stefan Anca
}
}finally{
closeDatabase(db);
}
}