• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java InsertHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.database.DatabaseUtils.InsertHelper的典型用法代码示例。如果您正苦于以下问题:Java InsertHelper类的具体用法?Java InsertHelper怎么用?Java InsertHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InsertHelper类属于android.database.DatabaseUtils包,在下文中一共展示了InsertHelper类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: insertMany

import android.database.DatabaseUtils.InsertHelper; //导入依赖的package包/类
/**
 * Efficiently insert a collection of entities using {@link InsertHelper}.
 *
 * @param many Collection of objects
 * @return count of inserted objects or -1 immediately if any errors
 */
public long insertMany(Iterable<T> many) {
	long numInserted = 0;
	InsertHelper insertHelper = new DatabaseUtils.InsertHelper(getWritableDb(), th.getTableName());
	getWritableDb().beginTransaction();
	try {
		for (T obj : many) {
			ContentValues cv = th.getEditableValues(obj);
			if (th.getId(obj) == 0) {
				// the default, remove from ContentValues to allow autoincrement
				cv.remove(th.getIdCol().toString());
			}
			long id = insertHelper.insert(cv);
			if (id == -1)
				return -1;
			numInserted++;
		}
		getWritableDb().setTransactionSuccessful();
	} finally {
		getWritableDb().endTransaction();
	}
	return numInserted;
}
 
开发者ID:turbomanage,项目名称:storm-gen,代码行数:29,代码来源:SQLiteDao.java


示例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_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;
}
 
开发者ID:active-citizen,项目名称:android.java,代码行数:49,代码来源:PollsProvider.java


示例3: 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;
}
 
开发者ID:active-citizen,项目名称:android.java,代码行数:57,代码来源:UserDataProvider.java


示例4: insertBulkItems

import android.database.DatabaseUtils.InsertHelper; //导入依赖的package包/类
public boolean insertBulkItems(ArrayList<FeedObject> feedList) 
{
	long start = System.currentTimeMillis();
	int time = (int)(start / 1000);
	if(feedList==null || feedList.size()<1) 
		return false;
	
	Logs.d(TAG, "# Insert bulk : type="+feedList.get(0).mType+", item count = "+feedList.size());

	InsertHelper iHelp = new InsertHelper(mDb, TABLE_NAME_FEED_ITEM);
	int ktype 		= iHelp.getColumnIndex(KEY_FEED_TYPE);
	int kstatus 	= iHelp.getColumnIndex(KEY_FEED_STATUS);
	int kid 			= iHelp.getColumnIndex(KEY_FEED_IDSTRING);
	int kname 			= iHelp.getColumnIndex(KEY_FEED_NAME);
	int klink 		= iHelp.getColumnIndex(KEY_FEED_LINK);
	int kkeyword 	= iHelp.getColumnIndex(KEY_FEED_KEYWORD);
	int kcontent 	= iHelp.getColumnIndex(KEY_FEED_CONTENT);
	int kthumbnail 	= iHelp.getColumnIndex(KEY_FEED_THUMBNAILURL);
	int kdate 			= iHelp.getColumnIndex(KEY_FEED_DATE);
	int krank 			= iHelp.getColumnIndex(KEY_FEED_RANK);
	int kclick 			= iHelp.getColumnIndex(KEY_FEED_CLICK);
	int kranktype	= iHelp.getColumnIndex(KEY_FEED_ARG0);
	int kversion	= iHelp.getColumnIndex(KEY_FEED_ARG1);
	int kfullimage	= iHelp.getColumnIndex(KEY_FEED_ARG2);
	
	synchronized (mDb) {
		if(mDb == null) return false;
		try
		{
			mDb.beginTransaction();
			// First one is recent one. So insert oldest first.
			for(int i = feedList.size()-1 ; -1<i ; i--)
			{
				FeedObject feed = feedList.get(i);
				// need to tell the helper you are inserting (rather than replacing)
				iHelp.prepareForInsert();

				// do the equivalent of ContentValues.put("field","value") here
				iHelp.bind(ktype, feed.mType);
				iHelp.bind(kstatus, feed.mDownloadStatus);
				iHelp.bind(kid, feed.mId);
				if(feed.mName != null)
					iHelp.bind(kname, feed.mName);
				if(feed.mLink != null)
					iHelp.bind(klink, feed.mLink);
				if(feed.mKeyword != null)
					iHelp.bind(kkeyword, feed.mKeyword);
				if(feed.mContent != null)
					iHelp.bind(kcontent, feed.mContent);
				if(feed.mThumbnailUrl != null)
					iHelp.bind(kthumbnail, feed.mThumbnailUrl);
				if(feed.mDate != null)
					iHelp.bind(kdate, feed.mDate);
				else
					iHelp.bind(kdate, time);

				iHelp.bind(krank, feed.mRankUpAndDown);
				iHelp.bind(kclick, feed.mCommentCount);
				iHelp.bind(kranktype, feed.mRankType);
				iHelp.bind(kversion, feed.mVersion);

				if(feed.mFullSizeImageURL != null)
					iHelp.bind(kfullimage, feed.mFullSizeImageURL);
				
				//the db.insert() equilvalent
				iHelp.execute();
			}
			mDb.setTransactionSuccessful();
		}
		catch(Exception e) {
		}
		finally	{
			mDb.endTransaction();
		}
	}

	return true;
}
 
开发者ID:godstale,项目名称:retrowatch,代码行数:79,代码来源:DBHelper.java


示例5: 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;
}
 
开发者ID:mcxiaoke,项目名称:fanfouapp-opensource,代码行数:81,代码来源:FanFouProvider.java


示例6: 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);
	}
}
 
开发者ID:noundla,项目名称:SMSListTracker,代码行数:44,代码来源:SMSListDBHelper.java


示例7: bindRowValues

import android.database.DatabaseUtils.InsertHelper; //导入依赖的package包/类
/**
 * Convert the String values for each column into their appropriate SQL
 * types and bind to the insert statement using {@link InsertHelper}.
 *
 * @param insHelper
 * @param rowValues
 */
public abstract void bindRowValues(InsertHelper insHelper, String[] rowValues);
 
开发者ID:turbomanage,项目名称:storm-gen,代码行数:9,代码来源:TableHelper.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CreateRequestProto类代码示例发布时间:2022-05-22
下一篇:
Java GlobalFunctions类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap