Skip to content

Commit

Permalink
checkDaoNotNull可让子类调用
Browse files Browse the repository at this point in the history
  • Loading branch information
feer921 authored and Lyphy999 committed Sep 23, 2017
1 parent 24bcff9 commit bfa7113
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ public QueryBuilder<T> queryBuilder() {
checkDaoNotNull();
return curDao.queryBuilder();
}
void checkDaoNotNull() {
/**
* 让子类可调用,但不可重载
**/
protected final void checkDaoNotNull() {
if (curDao == null) {
curDao = provideDao();
}
Expand Down
13 changes: 10 additions & 3 deletions TinyDbModule/src/main/java/me/common/tinydb/AbsTableUpgrader.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void upgradeTables() {
String tempTableName = tableName + "_temp";
String sql = "ALTER TABLE " + tableName +" RENAME TO " + tempTableName;
db.execSQL(sql);
//2、再创建一次原表,
//2、再创建一次原表,这里可以传入false因为上面已经把原表重命名了
createMyTable(false);
//3、准备从临时表中把数据给Load进新建的表的前提:获取需要复制数据的所有字段
ArrayList<String> toInsertDataColumns = getNeedLoadDataColumnsFromTempTable(getIgnoreCopyDataColumns());
Expand All @@ -79,10 +79,12 @@ public void upgradeTables() {
db.execSQL(sql);
}
//5、删除掉生成的临时表
db.execSQL("DROP TABLE IF EXISTS " + tempTableName, null);
db.execSQL("DROP TABLE IF EXISTS " + tempTableName);
db.setTransactionSuccessful();
} catch (Exception ignore) {
Log.e(TAG, "--> upgradeTables() occur " + ignore);
// db.execSQL("DROP TABLE IF EXISTS " + tableName + "_temp");
// db.setTransactionSuccessful();
}
finally {
db.endTransaction();
Expand Down Expand Up @@ -154,7 +156,12 @@ public ArrayList<String> getIgnoreCopyDataColumns(){
return ignoreCopyDataColumns;
}

public abstract void createMyTable(boolean isNotExists);
/**
* 重新创建表
* 于{@link #upgradeTables()}中调用
* @param ifNotExists 创建表时判断表是否已经存在,如果旧表存在的话,直接创建表会失败;true:要判断是否存在;false:不判断表是否存在
*/
public abstract void createMyTable(boolean ifNotExists);

/**
* 从一张表中获取到所有的列名、字段
Expand Down

0 comments on commit bfa7113

Please sign in to comment.