Java Code Examples for com.lidroid.xutils.DbUtils

The following examples show how to use com.lidroid.xutils.DbUtils. 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
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 2
Source Project: Conquer   Source File: CustomApplication.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void onCreate() {
        super.onCreate();
        //捕获系统异常
        //		MyCrashHandler myHandler = MyCrashHandler.getInstance();
        //		myHandler.init(this);
        //		Thread.currentThread().setUncaughtExceptionHandler(myHandler);
        // 是否开启debug模式--默认开启状态

        mInstance = this;

        BmobChat.DEBUG_MODE = true;
        DbUtils.create(getApplicationContext()).configDebug(false);
        Fresco.initialize(getApplicationContext());
//        LeakCanary.install(this);
        // 将“12345678”替换成您申请的APPID,申请地址:http://open.voicecloud.cn
        SpeechUtility.createUtility(getApplicationContext(), SpeechConstant.APPID + "=556fce70");
        init();
    }
 
Example 3
Source Project: Conquer   Source File: TaskUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 返回今天本地大于当前时间的任务,并且未被提醒的
 *
 * @param context
 * @return
 * @throws Exception
 */
public static List<Task> getTodayAfterZixi(Context context) {
    List<Task> listTask = new ArrayList<Task>();
    DbUtils dbUtils = DbUtils.create(context);
    Calendar cur = Calendar.getInstance();
    cur.setTimeInMillis(System.currentTimeMillis());
    Calendar c = Calendar.getInstance();
    try {
        // 获取没有提醒的
        List<Task> findAll = new TaskDao(context).getNotAlertTasks();
        if (findAll != null && findAll.size() > 0) {
            long curTime = System.currentTimeMillis();
            L.i("大小" + findAll.size());
            for (Task task : findAll) {
                c.setTimeInMillis(task.getTime());
                // 今天,大于当前时间的
                if (task.getTime() >= curTime && c.get(Calendar.DAY_OF_YEAR) == cur.get(Calendar.DAY_OF_YEAR)) {
                    listTask.add(task);
                }
            }
        }
    } catch (Exception e) {
        // if (debugDB) e.printStackTrace();
    }
    return listTask;
}
 
Example 4
Source Project: Conquer   Source 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 5
Source Project: ALLGO   Source 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 6
Source Project: ALLGO   Source 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 7
Source Project: ALLGO   Source File: FriendsEventLogicImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 保存列表数据到数据库
 * @param eventsData
 */
@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(FriendEventVo.class);
        Log.i("DB", "deleteAll =saveFriendEvent=>" + eventsData.size()) ;
        for(int i=0 ; i<20 && i<eventsData.size() ; i++){
        	db.save(ChangEventVo.event2FriendEvent(eventsData.get(i)));
        }
		}catch(DbException e){
	    	Log.e("DB", "error :" + e.getMessage() + "\n");
	    }
}
 
Example 8
Source Project: ALLGO   Source File: CommonEventLogicImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 保存列表数据到数据库
 * @param context
 * @param eventsData
 */
@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(CommonEventVo.class);
        Log.i("DB", "deleteAll =saveCommonEvent=>" + eventsData.size()) ;
        for(int i=0 ; i<20 && i<eventsData.size() ; i++){
        	db.save(ChangEventVo.event2CommonEvent(eventsData.get(i)));
        }
		}catch(DbException e){
	    	Log.e("DB", "error :" + e.getMessage() + "\n");
	    }
}
 
Example 9
Source Project: ALLGO   Source 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 10
Source Project: android-open-project-demo   Source File: Table.java    License: Apache License 2.0 6 votes vote down vote up
public static synchronized void remove(DbUtils db, String tableName) {
    if (tableMap.size() > 0) {
        String key = null;
        for (Map.Entry<String, Table> entry : tableMap.entrySet()) {
            Table table = entry.getValue();
            if (table != null && table.tableName.equals(tableName)) {
                key = entry.getKey();
                if (key.startsWith(db.getDaoConfig().getDbName() + "#")) {
                    break;
                }
            }
        }
        if (TextUtils.isEmpty(key)) {
            tableMap.remove(key);
        }
    }
}
 
Example 11
Source Project: android-open-project-demo   Source File: SqlInfoBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public static SqlInfo buildDeleteSqlInfo(DbUtils db, Object entity) throws DbException {
    SqlInfo result = new SqlInfo();

    Class<?> entityType = entity.getClass();
    Table table = Table.get(db, entityType);
    Id id = table.id;
    Object idValue = id.getColumnValue(entity);

    if (idValue == null) {
        throw new DbException("this entity[" + entity.getClass() + "]'s id value is null");
    }
    StringBuilder sb = new StringBuilder(buildDeleteSqlByTableName(table.tableName));
    sb.append(" WHERE ").append(WhereBuilder.b(id.getColumnName(), "=", idValue));

    result.setSql(sb.toString());

    return result;
}
 
Example 12
Source Project: android-open-project-demo   Source File: SqlInfoBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public static SqlInfo buildDeleteSqlInfo(DbUtils db, Class<?> entityType, Object idValue) throws DbException {
    SqlInfo result = new SqlInfo();

    Table table = Table.get(db, entityType);
    Id id = table.id;

    if (null == idValue) {
        throw new DbException("this entity[" + entityType + "]'s id value is null");
    }
    StringBuilder sb = new StringBuilder(buildDeleteSqlByTableName(table.tableName));
    sb.append(" WHERE ").append(WhereBuilder.b(id.getColumnName(), "=", idValue));

    result.setSql(sb.toString());

    return result;
}
 
Example 13
Source Project: BigApp_Discuz_Android   Source File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static void addAllEmoji(Context context, List<EmoticonBean> beans) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        dbUtils.saveAll(beans);
    } catch (DbException e) {
        e.printStackTrace();
    }
}
 
Example 14
Source Project: BigApp_Discuz_Android   Source File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static List<EmoticonBean> getAllEmojis(Context context) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        return dbUtils.findAll(EmoticonBean.class);
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 15
Source Project: BigApp_Discuz_Android   Source 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 16
Source Project: BigApp_Discuz_Android   Source 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 17
Source Project: BigApp_Discuz_Android   Source File: EmojiDb.java    License: Apache License 2.0 5 votes vote down vote up
public static EmoticonBean getEmojiByShortname(Context context, String shortname) {
    DbUtils dbUtils = DbUtils.create(context, DB_NAME, DB_VERSION, null);
    try {
        return dbUtils.findFirst(Selector.from(EmoticonBean.class).where("shortname", "=", shortname));
    } catch (DbException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 18
Source Project: BigApp_Discuz_Android   Source 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 19
Source Project: BigApp_Discuz_Android   Source 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 20
Source Project: BigApp_Discuz_Android   Source 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 21
Source Project: BigApp_Discuz_Android   Source 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 22
Source Project: BigApp_Discuz_Android   Source 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 23
Source Project: QiQuYing   Source 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 24
Source Project: QiQuYing   Source File: DingCaiDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 查找未同步到服务器的点赞数据
 * @return
 */
public List<DingOrCai> getUnUpload() {
	DbUtils db = DbUtils.create(context);
	List<DingOrCai> dbModels = null;
	try {
		dbModels = db.findAll(Selector.from(DingOrCai.class).where(WhereBuilder.b("is_upload", "=", DingOrCai.NOT_UPLOAD)));
		Log.d(TAG, "getUnUpload success");
	} catch (DbException e) {
		Log.d(TAG, "getUnUpload failure", e);
	}
	return dbModels;
}
 
Example 25
Source Project: QiQuYing   Source File: DingCaiDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 修改同步后的数据
 * @param praises
 */
public void upload(List<DingOrCai> praises) {
	for (DingOrCai praise : praises) {
		praise.setIsUpload(DingOrCai.UPLOAD);
	}
	DbUtils db = DbUtils.create(context);
	try {
		db.updateAll(praises, "is_upload");
		Log.d(TAG, "upload praise success");
	} catch (DbException e) {
		Log.d(TAG, "upload praise failure", e);
	}
}
 
Example 26
Source Project: QiQuYing   Source 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 27
Source Project: QiQuYing   Source File: CollectDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 取消收藏
 * @param jokeId
 */
public void cancelCollect(int jokeId) {
	DbUtils db = DbUtils.create(context);
	try {
		db.delete(Collect.class, WhereBuilder.b("joke_id", "=", jokeId));
		Log.d(TAG, "cancelCollect success");
	} catch (DbException e) {
		Log.e(TAG, "cancelCollect failure", e);
	}
}
 
Example 28
Source Project: QiQuYing   Source File: CollectDAO.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取我的收藏
 * @param userId
 * @return
 */
public List<Collect> getCollects(int userId) {
	DbUtils db = DbUtils.create(context);
	List<Collect> dbModels = null;
	try {
		dbModels = db.findAll(Selector.from(Collect.class).
				where(WhereBuilder.b("user_id", "=", userId))
				.orderBy("create_at", true));
		Log.d(TAG, "getCollects success");
	} catch (DbException e) {
		Log.e(TAG, "getCollects failure", e);
	}
	return dbModels;
}
 
Example 29
Source Project: Conquer   Source File: BaseActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    initStatusBar();
    initTheme();
    initLayout();
    userManager = BmobUserManager.getInstance(getApplicationContext());
    manager = BmobChatManager.getInstance(getApplicationContext());
    mApplication = CustomApplication.getInstance();
    currentUser = BmobChatUser.getCurrentUser(context, User.class);
    DisplayMetrics metric = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metric);
    mScreenWidth = metric.widthPixels;
    mScreenHeight = metric.heightPixels;
    loader = ImageLoader.getInstance();

    option_photo = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.default_photo)
            .showImageForEmptyUri(R.drawable.default_photo).showImageOnFail(R.drawable.default_photo)
            .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true)
            .bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(200)).build();
    option_pic = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.pic_loading)
            .showImageForEmptyUri(R.drawable.pic_loading).showImageOnFail(R.drawable.pic_loading)
            .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true)
            .bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(200)).build();
    dbUtils = DbUtils.create(context);
}
 
Example 30
Source Project: Conquer   Source 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);
            }
        });
    }