Java Code Examples for com.lidroid.xutils.DbUtils#create()

The following examples show how to use com.lidroid.xutils.DbUtils#create() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ALLGO   File: UnreadLogicImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 结束保存
 */
@Override
public void saveUnread(ArrayList<UnreadVo> unreadDate) {

	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
	int uid = sharedPref.getInt("uid", -1) ;
   	try{
	    DbUtils db = DbUtils.create(context,uid + ".db");
	    db.configAllowTransaction(true);
        db.configDebug(true);
        Log.i("DB", "deleteNo =saveUnread=>" + unreadDate.size()) ;
        for(int i=0 ; i<unreadDate.size() ; i++){
        	db.saveOrUpdate(unreadDate.get(i));
        }
		}catch(DbException e){
	    	Log.e("DB", "error :" + e.getMessage() + "\n");
	    }
}
 
Example 2
Source Project: ALLGO   File: MyEventLogicImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void saveEvent(ArrayList<EventVo> eventsData) {
	
	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
	int uid = sharedPref.getInt("uid", -1) ;
   	try{
	    DbUtils db = DbUtils.create(context,uid + ".db");
	    db.configAllowTransaction(true);
        db.configDebug(true);
        db.deleteAll(MyEventVo.class);
        Log.i("DB", "deleteAll =saveBindingId=>" + eventsData.size()) ;
        for(int i=0 ; i<20 && i<eventsData.size() ; i++){
        	db.save(ChangEventVo.event2MyEvent(eventsData.get(i)));
        }
		}catch(DbException e){
	    	Log.e("DB", "error :" + e.getMessage() + "\n");
	    }

}
 
Example 3
private void initDate() {
	siteTool = new GosScheduleSiteTool(this, device, spf.getString("Token", ""));
	DbUtils.DaoConfig config = new DaoConfig(this);
	config.setDbName("gizwits");
	config.setDbVersion(1); // db版本
	dbUtils = DbUtils.create(config);// db还有其他的一些构造方法,比如含有更新表版本的监听器的DbUtils
	try {
		// 创建一张表
		dbUtils.createTableIfNotExist(GosScheduleData.class);
	} catch (DbException e) {
		e.printStackTrace();
	}
	GosScheduleData.setSiteTool(siteTool);
	GosScheduleData.setDbUtils(dbUtils);
	GosScheduleData.setContext(getApplicationContext());
	setProgressDialog(getResources().getString(R.string.site_setting_time), true, false);
}
 
Example 4
Source Project: ALLGO   File: PastEventLogicImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void saveEvent(ArrayList<EventVo> eventsData) {
	
	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
	int uid = sharedPref.getInt("uid", -1) ;
   	try{
	    DbUtils db = DbUtils.create(context,uid + ".db");
	    db.configAllowTransaction(true);
        db.configDebug(true);
        db.deleteAll(PastEventVo.class);
        Log.i("DB", "deleteAll =saveBindingId=>" + eventsData.size()) ;
        for(int i=0 ; i<20 && i<eventsData.size() ; i++){
        	db.save(ChangEventVo.event2PastEvent(eventsData.get(i)));
        }
		}catch(DbException e){
	    	Log.e("DB", "error :" + e.getMessage() + "\n");
	    }

}
 
Example 5
Source Project: Conquer   File: TaskUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
     * 根据日期返回数据库用户某天的任务
     *
     * @param context
     * @return
     * @throws Exception
     */
    public static List<Task> getZixiByDay(Context context, long time) {
        DbUtils dbUtils = DbUtils.create(context);
        List<Task> temp = new ArrayList<Task>();
        try {
//            List<Task> findAll = dbUtils.findAll(Selector.from(Task.class).orderBy("time"));
            List<Task> findAll = new TaskDao(context).getAllTask();
            if (CollectionUtils.isNotNull(findAll)) {
                for (Task task : findAll) {
                    if (isToday(task.getTime(), time) && task.getRepeat() == 0) temp.add(task);
                }
                L.i("大小" + temp.size());
            }
        } catch (Exception e) {
            // if (debugDB) e.printStackTrace();
        }
        return temp;
    }
 
Example 6
Source Project: BigApp_Discuz_Android   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonBean> getEmojiGroup(Context context, String group) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        return dbUtils.findAll(Selector.from(EmoticonBean.class).where("groupName", "=", group));
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 7
Source Project: BigApp_Discuz_Android   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static EmoticonBean getEmojiByUnicode(Context context, String unicode) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        return dbUtils.findFirst(Selector.from(EmoticonBean.class).where("content", "=", unicode));
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 8
Source Project: BigApp_Discuz_Android   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public static List<EmoticonSetBean> getEmojiSets(Context context) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        EmoticonSetBean setBean = dbUtils.findFirst(EmoticonSetBean.class);
        List<EmoticonBean> beans = getAllEmojis(context);
        setBean.setEmoticonList(beans);
        List<EmoticonSetBean> list = new ArrayList<EmoticonSetBean>();
        list.add(setBean);
        return list;
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 9
Source Project: BigApp_Discuz_Android   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonSetBean> getAllEmojiSet(Context context) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        List<EmoticonSetBean> setBean = dbUtils.findAll(EmoticonSetBean.class);
        return setBean;
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 10
Source Project: BigApp_Discuz_Android   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonSetBean> getEmojiSetsByName(Context context, String name) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        EmoticonSetBean setBean = dbUtils.findFirst(Selector.from(EmoticonSetBean.class).where("name", "=", name));
        List<EmoticonBean> beans = getAllEmojis(context);
        setBean.setEmoticonList(beans);
        List<EmoticonSetBean> list = new ArrayList<EmoticonSetBean>();
        list.add(setBean);
        return list;
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 11
Source Project: BigApp_Discuz_Android   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonSetBean> getEmojiLibraryByGroup(Context context, String name, String group) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        EmoticonSetBean setBean = dbUtils.findFirst(Selector.from(EmoticonSetBean.class).where("name", "=", name));
        List<EmoticonBean> beans = getEmojiGroup(context, group);
        setBean.setEmoticonList(beans);
        List<EmoticonSetBean> list = new ArrayList<EmoticonSetBean>();
        list.add(setBean);
        return list;
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 12
Source Project: BigApp_Discuz_Android   File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static void clear(Context context) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        dbUtils.dropTable(EmoticonSetBean.class);
        dbUtils.dropTable(EmoticonBean.class);
    } catch (DbException e) {
        e.printStackTrace();
    }
}
 
Example 13
Source Project: QiQuYing   File: DingCaiDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 检查是否点过赞
 * @param userId
 * @param jokeId
 * @return
 */
public DingOrCai getDingOrCai(int userId, int jokeId) {
	DbUtils db = DbUtils.create(context);
	DingOrCai dingOrCai = null;
	try {
		dingOrCai = db.findFirst(Selector.from(DingOrCai.class).where(WhereBuilder.b("user_id", "=", userId).and("joke_id", "=", jokeId)));
		Log.d(TAG, "getDingOrCai success");
	} catch (DbException e) {
		Log.d(TAG, "getDingOrCai failure", e);
	}
	return dingOrCai;
}
 
Example 14
Source Project: Conquer   File: TaskUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 返回网络上用户所有的任务
     *
     * @param context
     * @param currentUser
     * @param getZixiCallBack 获取网络数据的回调
     * @throws Exception
     */
    public static void getNetAllZixi(final Context context, User currentUser, final GetZixiCallBack getZixiCallBack) {
        final DbUtils dbUtils = DbUtils.create(context);
        BmobQuery<Task> query = new BmobQuery<Task>();
        query.addWhereEqualTo("user", currentUser);
        // 这个查询也包括了用户的已经过时的任务
        query.findObjects(context, new FindListener<Task>() {
            @Override
            public void onSuccess(List<Task> arg0) {
//                try {
                // 1.更新本地数据库
                if (arg0.size() > 0) {
//                        dbUtils.deleteAll(Task.class);
//                        dbUtils.saveAll(arg0);
                    TaskDao taskDao = new TaskDao(context);
                    taskDao.saveAll(arg0);
//                    }
//                } catch (DbException e) {
                    // if (debugDB) e.printStackTrace();
//                }
                    // 2.筛选大于当后时间的
                    List<Task> listTask = new ArrayList<Task>();
                    long curTime = System.currentTimeMillis();
                    for (Task task : arg0) {
                        if (task.getTime() >= curTime) {
                            listTask.add(task);
                        }
                    }
                    getZixiCallBack.onSuccess(listTask);
                }

            }

            @Override
            public void onError(int i, String s) {
                getZixiCallBack.onError(i, s);
            }
        });
    }
 
Example 15
@Override
public View onCreateView(LayoutInflater inflater,
		@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
	View view = inflater.inflate(R.layout.db_fragment_view, container,
			false);
	ViewUtils.inject(this, view);

	db = DbUtils.create(this.getActivity());
	// 创建方式有多个重载, 实际项目中可能选择这个 因为数据库升级,后期数据维护都用的到
	// DbUtils.create(context, dbDir, dbName, dbVersion, dbUpgradeListener)
	db.configDebug(true); // debug模式 会输入sql语句
	db.configAllowTransaction(true); // 允许事务
	return view;
}
 
Example 16
Source Project: QiQuYing   File: CollectDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 检查是否收藏过
 * @param userId
 * @param jokeId
 * @return
 */
public Collect getCollect(int userId, int jokeId) {
	DbUtils db = DbUtils.create(context);
	Collect collect = null;
	try {
		collect = db.findFirst(Selector.from(Collect.class).where(WhereBuilder.b("user_id", "=", userId).and("joke_id", "=", jokeId)));
		Log.d(TAG, "getDingOrCai success");
	} catch (DbException e) {
		Log.e(TAG, "getDingOrCai failure", e);
	}
	return collect;
}
 
Example 17
Source Project: ALLGO   File: UnreadLogicImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setRead(UnreadVo unread) {
	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
	int uid = sharedPref.getInt("uid", -1) ;
   	try{
   		unread.setIsread(true);
	    DbUtils db = DbUtils.create(context,uid + ".db");
	    db.configAllowTransaction(true);
        db.configDebug(true);
        db.saveOrUpdate(unread);
		}catch(DbException e){
	    	Log.e("DB", "error :" + e.getMessage() + "\n");
	    }
	
}
 
Example 18
Source Project: ALLGO   File: test.java    License: Apache License 2.0 5 votes vote down vote up
public void test1(){
	ArrayList<FriendEventVo> eventsDate =new ArrayList<FriendEventVo>() ;
	eventsDate.add(new FriendEventVo(11002617,"去栖霞山爬山",123456,"千军万马1",
   			"Mon Feb 15 08:00:00 GMT+08:00 2014",null,"去栖霞山爬山","栖霞山",
   			"江苏省 南京市 栖霞区","Mon Feb 13 08:00:00 GMT+08:00 2013","旅游",0,
   			0,0));
	eventsDate.add(new FriendEventVo(11002618,"去栖霞山爬山",123456,"千军万马2",
   			"Mon Feb 15 08:00:00 GMT+08:00 2014",null,"去栖霞山爬山","栖霞山",
   			"江苏省 南京市 栖霞区","Mon Feb 13 08:00:00 GMT+08:00 2013","旅游",0,
   			0,0));
	eventsDate.add(new FriendEventVo(11002619,"去栖霞山爬山",123456,"千军万马3",
   			"Mon Feb 15 08:00:00 GMT+08:00 2014",null,"去栖霞山爬山","栖霞山",
   			"江苏省 南京市 栖霞区","Mon Feb 13 08:00:00 GMT+08:00 2013","旅游",0,
   			0,0));
	
	try{
	    DbUtils db = DbUtils.create(this.getContext(),"123456.db");
	    db.configAllowTransaction(true);
        db.configDebug(true);
        db.saveBindingIdAll(eventsDate);
        
        //List<EventVo> events = db.findAll(Selector.from(FriendEventVo.class));
        //Log.i("DB", "Parents size:" + events.get(0) + "\n") ;

        
	}catch(DbException e){
    	Log.e("DB", "error :" + e.getMessage() + "\n");
    }
}
 
Example 19
DownloadManager(Context appContext) {
    ColumnConverterFactory.registerColumnConverter(HttpHandler.State.class, new HttpHandlerStateConverter());
    mContext = appContext;
    db = DbUtils.create(mContext);
    try {
        downloadInfoList = db.findAll(Selector.from(DownloadInfo.class));
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (downloadInfoList == null) {
        downloadInfoList = new ArrayList<DownloadInfo>();
    }
}
 
Example 20
Source Project: qingyang   File: DBManager.java    License: Apache License 2.0 4 votes vote down vote up
public DBManager(Context context) {
	// 创建数据库
	db = DbUtils.create(context, DB_NBAM);
}