com.lidroid.xutils.DbUtils Java Examples

The following examples show how to use com.lidroid.xutils.DbUtils. 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 File: UnreadLogicImpl.java    From ALLGO with 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 File: MyEventLogicImpl.java    From ALLGO with 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
Source File: PastEventLogicImpl.java    From ALLGO with 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 #4
Source File: TaskUtil.java    From Conquer with 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 File: TaskUtil.java    From Conquer with 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 #6
Source File: CustomApplication.java    From Conquer with 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 #7
Source File: GosScheduleListActivity.java    From Gizwits-SmartBuld_Android with MIT License 6 votes vote down vote up
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 #8
Source File: FriendsEventLogicImpl.java    From ALLGO with 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 #9
Source File: CommonEventLogicImpl.java    From ALLGO with 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 #10
Source File: SqlInfoBuilder.java    From android-open-project-demo with 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 #11
Source File: Table.java    From android-open-project-demo with 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 #12
Source File: SqlInfoBuilder.java    From android-open-project-demo with 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 #13
Source File: SqlInfoBuilder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static SqlInfo buildCreateTableSqlInfo(DbUtils db, Class<?> entityType) throws DbException {
    Table table = Table.get(db, entityType);
    Id id = table.id;

    StringBuffer sqlBuffer = new StringBuffer();
    sqlBuffer.append("CREATE TABLE IF NOT EXISTS ");
    sqlBuffer.append(table.tableName);
    sqlBuffer.append(" ( ");

    if (id.isAutoIncrement()) {
        sqlBuffer.append("\"").append(id.getColumnName()).append("\"  ").append("INTEGER PRIMARY KEY AUTOINCREMENT,");
    } else {
        sqlBuffer.append("\"").append(id.getColumnName()).append("\"  ").append(id.getColumnDbType()).append(" PRIMARY KEY,");
    }

    Collection<Column> columns = table.columnMap.values();
    for (Column column : columns) {
        if (column instanceof Finder) {
            continue;
        }
        sqlBuffer.append("\"").append(column.getColumnName()).append("\"  ");
        sqlBuffer.append(column.getColumnDbType());
        if (ColumnUtils.isUnique(column.getColumnField())) {
            sqlBuffer.append(" UNIQUE");
        }
        if (ColumnUtils.isNotNull(column.getColumnField())) {
            sqlBuffer.append(" NOT NULL");
        }
        String check = ColumnUtils.getCheck(column.getColumnField());
        if (check != null) {
            sqlBuffer.append(" CHECK(").append(check).append(")");
        }
        sqlBuffer.append(",");
    }

    sqlBuffer.deleteCharAt(sqlBuffer.length() - 1);
    sqlBuffer.append(" )");
    return new SqlInfo(sqlBuffer.toString());
}
 
Example #14
Source File: Table.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
private Table(DbUtils db, Class<?> entityType) {
    this.db = db;
    this.tableName = TableUtils.getTableName(entityType);
    this.id = TableUtils.getId(entityType);
    this.columnMap = TableUtils.getColumnMap(entityType);

    finderMap = new HashMap<String, Finder>();
    for (Column column : columnMap.values()) {
        column.setTable(this);
        if (column instanceof Finder) {
            finderMap.put(column.getColumnName(), (Finder) column);
        }
    }
}
 
Example #15
Source File: PastEventLogicImpl.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
@Override
public void initEvent() {

	new AsyncTask<Void, Void, ArrayList<EventVo>>() {
           @Override
           protected ArrayList<EventVo> doInBackground(Void... params) {
           	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
       		int uid = sharedPref.getInt("uid", -1) ;
       		ArrayList<EventVo> events =new ArrayList<EventVo>();
           	try{
   		    DbUtils db = DbUtils.create(context,uid + ".db");
   		    db.configAllowTransaction(true);
   	        db.configDebug(true);
   	        List<EventVo> event = db.findAll(Selector.from(PastEventVo.class));
   	        if(event != null){
   	        Log.i("DB", "initPastEvent.size()==>" + event.size());
   	        for(int i=0 ; i<event.size() ; i++) {
   	        	events.add(ChangEventVo.event2Event(event.get(i))) ;
   	        	//Log.i("DB", "=initPastEvent=>" + event.get(i).toString());
   	        	}
   	        }
   		}catch(DbException e){
   	    	Log.e("DB", "error :" + e.getMessage() + "\n");
   	    }
   		return events;
   		}

           @Override
           protected void onPostExecute(ArrayList<EventVo> result) {
               super.onPostExecute(result);
               ArrayListUtil.sortEventVo(result);
               refresh.refresh(result, 1);
           }
       }.execute();

}
 
Example #16
Source File: SqlInfoBuilder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static SqlInfo buildUpdateSqlInfo(DbUtils db, Object entity, WhereBuilder whereBuilder, String... updateColumnNames) throws DbException {

        List<KeyValue> keyValueList = entity2KeyValueList(db, entity);
        if (keyValueList.size() == 0) return null;

        HashSet<String> updateColumnNameSet = null;
        if (updateColumnNames != null && updateColumnNames.length > 0) {
            updateColumnNameSet = new HashSet<String>(updateColumnNames.length);
            Collections.addAll(updateColumnNameSet, updateColumnNames);
        }

        Class<?> entityType = entity.getClass();
        String tableName = TableUtils.getTableName(entityType);

        SqlInfo result = new SqlInfo();
        StringBuffer sqlBuffer = new StringBuffer("UPDATE ");
        sqlBuffer.append(tableName);
        sqlBuffer.append(" SET ");
        for (KeyValue kv : keyValueList) {
            if (updateColumnNameSet == null || updateColumnNameSet.contains(kv.key)) {
                sqlBuffer.append(kv.key).append("=?,");
                result.addBindArgWithoutConverter(kv.value);
            }
        }
        sqlBuffer.deleteCharAt(sqlBuffer.length() - 1);
        if (whereBuilder != null && whereBuilder.getWhereItemSize() > 0) {
            sqlBuffer.append(" WHERE ").append(whereBuilder.toString());
        }

        result.setSql(sqlBuffer.toString());
        return result;
    }
 
Example #17
Source File: SqlInfoBuilder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static SqlInfo buildUpdateSqlInfo(DbUtils db, Object entity, String... updateColumnNames) throws DbException {

        List<KeyValue> keyValueList = entity2KeyValueList(db, entity);
        if (keyValueList.size() == 0) return null;

        HashSet<String> updateColumnNameSet = null;
        if (updateColumnNames != null && updateColumnNames.length > 0) {
            updateColumnNameSet = new HashSet<String>(updateColumnNames.length);
            Collections.addAll(updateColumnNameSet, updateColumnNames);
        }

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

        if (null == idValue) {
            throw new DbException("this entity[" + entity.getClass() + "]'s id value is null");
        }

        SqlInfo result = new SqlInfo();
        StringBuffer sqlBuffer = new StringBuffer("UPDATE ");
        sqlBuffer.append(table.tableName);
        sqlBuffer.append(" SET ");
        for (KeyValue kv : keyValueList) {
            if (updateColumnNameSet == null || updateColumnNameSet.contains(kv.key)) {
                sqlBuffer.append(kv.key).append("=?,");
                result.addBindArgWithoutConverter(kv.value);
            }
        }
        sqlBuffer.deleteCharAt(sqlBuffer.length() - 1);
        sqlBuffer.append(" WHERE ").append(WhereBuilder.b(id.getColumnName(), "=", idValue));

        result.setSql(sqlBuffer.toString());
        return result;
    }
 
Example #18
Source File: SqlInfoBuilder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static SqlInfo buildDeleteSqlInfo(DbUtils db, Class<?> entityType, WhereBuilder whereBuilder) throws DbException {
    Table table = Table.get(db, entityType);
    StringBuilder sb = new StringBuilder(buildDeleteSqlByTableName(table.tableName));

    if (whereBuilder != null && whereBuilder.getWhereItemSize() > 0) {
        sb.append(" WHERE ").append(whereBuilder.toString());
    }

    return new SqlInfo(sb.toString());
}
 
Example #19
Source File: FriendsEventLogicImpl.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
/**
 * 从数据库初始化
 */
@Override
public void initEvent() {

	new AsyncTask<Void, Void, ArrayList<EventVo>>() {
           @Override
           protected ArrayList<EventVo> doInBackground(Void... params) {
           	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
       		int uid = sharedPref.getInt("uid", -1) ;
       		ArrayList<EventVo> events =new ArrayList<EventVo>();
           	try{
   		    DbUtils db = DbUtils.create(context,uid + ".db");
   		    db.configAllowTransaction(true);
   	        db.configDebug(true);
   	        List<EventVo> event = db.findAll(Selector.from(FriendEventVo.class));
   	        if(event != null){
   	        Log.i("DB", "initfriendsEvent.size()==>" + event.size());
   	        for(int i=0 ; i<event.size() ; i++) {
   	        	events.add(ChangEventVo.event2Event(event.get(i))) ;
   	        	//Log.i("DB", "=initfriendsEvent=>" + event.get(i).toString());
   	        	}
   	        }
   		}catch(DbException e){
   	    	Log.e("DB", "error :" + e.getMessage() + "\n");
   	    }
   		return events;
   		}

           @Override
           protected void onPostExecute(ArrayList<EventVo> result) {
               super.onPostExecute(result);
               ArrayListUtil.sortEventVo(result);
               refresh.refresh(result, 1);
           }
       }.execute();
       

}
 
Example #20
Source File: CommonEventLogicImpl.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化所有活动列表,从数据库得到数据
 * @param context
 */
@Override
public void initEvent() {
	
	
	new AsyncTask<Void, Void, ArrayList<EventVo>>() {
           @Override
           protected ArrayList<EventVo> doInBackground(Void... params) {
           	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
       		int uid = sharedPref.getInt("uid", -1) ;
       		ArrayList<EventVo> events =new ArrayList<EventVo>();
           	try{
   		    DbUtils db = DbUtils.create(context,uid + ".db");
   		    db.configAllowTransaction(true);
   	        db.configDebug(true);
   	        List<EventVo> event = db.findAll(Selector.from(CommonEventVo.class));
   	        if(event != null){
   	        Log.i("DB", "initcommonEvent.size()==>" + event.size());
   	        for(int i=0 ; i<event.size() ; i++) {
   	        	events.add(ChangEventVo.event2Event(event.get(i))) ;
   	        	}
   	        }
   		}catch(DbException e){
   	    	Log.e("DB", "error :" + e.getMessage() + "\n");
   	    }
   		return events;
   		}

           @Override
           protected void onPostExecute(ArrayList<EventVo> result) {
               super.onPostExecute(result);
               ArrayListUtil.sortEventVo(result);
               refresh.refresh(result, 1);
           }
       }.execute();
       

}
 
Example #21
Source File: Table.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static synchronized Table get(DbUtils db, Class<?> entityType) {
    String tableKey = db.getDaoConfig().getDbName() + "#" + entityType.getName();
    Table table = tableMap.get(tableKey);
    if (table == null) {
        table = new Table(db, entityType);
        tableMap.put(tableKey, table);
    }

    return table;
}
 
Example #22
Source File: UnreadLogicImpl.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
/**
 * 开程序初始化
 */
@Override
public void initUnread() {
	
	
	new AsyncTask<Void, Void, ArrayList<UnreadVo>>() {
           @Override
           protected ArrayList<UnreadVo> doInBackground(Void... params) {
           	SharedPreferences sharedPref = context.getSharedPreferences("userdata",Context.MODE_PRIVATE);
       		int uid = sharedPref.getInt("uid", -1) ;
       		ArrayList<UnreadVo> unreads =new ArrayList<UnreadVo>();
           	try{
   		    DbUtils db = DbUtils.create(context,uid + ".db");
   		    db.configAllowTransaction(true);
   	        db.configDebug(true);
   	        List<UnreadVo> unread = db.findAll(Selector.from(UnreadVo.class));
   	        if(unread != null){
   	        Log.i("DB", "initUnread.size()==>" + unread.size());
   	        for(int i=0 ; i<unread.size() ; i++) {
   	        	unreads.add(unread.get(i)) ;
   	        	//Log.i("DB", "=initUnreadEvent=>" + unread.get(i).toString());
   	        	}
   	        }
   		}catch(DbException e){
   	    	Log.e("DB", "error :" + e.getMessage() + "\n");
   	    }
   		return unreads;
   		}

           @Override
           protected void onPostExecute(ArrayList<UnreadVo> result) {
               super.onPostExecute(result);
               ArrayListUtil.sortUnreadVo(result);
               refresh.refresh(result, 1);
           }
       }.execute();
       

}
 
Example #23
Source File: EmojiDb.java    From BigApp_Discuz_Android with 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 #24
Source File: UnreadLogicImpl.java    From ALLGO with 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 #25
Source File: test.java    From ALLGO with 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 #26
Source File: DbFragment.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
@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 #27
Source File: DingCaiDAO.java    From QiQuYing with 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 #28
Source File: EmojiDb.java    From BigApp_Discuz_Android with 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 #29
Source File: EmojiDb.java    From BigApp_Discuz_Android with 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 #30
Source File: EmojiDb.java    From BigApp_Discuz_Android with 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;
}