11 changed files with 526 additions and 1 deletions
@ -0,0 +1,158 @@ |
|||||||
|
{ |
||||||
|
"formatVersion": 1, |
||||||
|
"database": { |
||||||
|
"version": 1, |
||||||
|
"identityHash": "966ac67768ec0c8feefb2e843474d8c7", |
||||||
|
"entities": [ |
||||||
|
{ |
||||||
|
"tableName": "t_record", |
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `name` TEXT, `check_date` INTEGER, `description` TEXT, `create_date` INTEGER, `deleted` INTEGER, PRIMARY KEY(`id`))", |
||||||
|
"fields": [ |
||||||
|
{ |
||||||
|
"fieldPath": "id", |
||||||
|
"columnName": "id", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "name", |
||||||
|
"columnName": "name", |
||||||
|
"affinity": "TEXT", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "checkDate", |
||||||
|
"columnName": "check_date", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "description", |
||||||
|
"columnName": "description", |
||||||
|
"affinity": "TEXT", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "createDate", |
||||||
|
"columnName": "create_date", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "deleted", |
||||||
|
"columnName": "deleted", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
} |
||||||
|
], |
||||||
|
"primaryKey": { |
||||||
|
"autoGenerate": false, |
||||||
|
"columnNames": [ |
||||||
|
"id" |
||||||
|
] |
||||||
|
}, |
||||||
|
"indices": [], |
||||||
|
"foreignKeys": [] |
||||||
|
}, |
||||||
|
{ |
||||||
|
"tableName": "t_project", |
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `name` TEXT, `project_icon_id` INTEGER, `create_date` INTEGER, `deleted` INTEGER, PRIMARY KEY(`id`))", |
||||||
|
"fields": [ |
||||||
|
{ |
||||||
|
"fieldPath": "id", |
||||||
|
"columnName": "id", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "name", |
||||||
|
"columnName": "name", |
||||||
|
"affinity": "TEXT", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "projectIconId", |
||||||
|
"columnName": "project_icon_id", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "createDate", |
||||||
|
"columnName": "create_date", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "deleted", |
||||||
|
"columnName": "deleted", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
} |
||||||
|
], |
||||||
|
"primaryKey": { |
||||||
|
"autoGenerate": false, |
||||||
|
"columnNames": [ |
||||||
|
"id" |
||||||
|
] |
||||||
|
}, |
||||||
|
"indices": [], |
||||||
|
"foreignKeys": [] |
||||||
|
}, |
||||||
|
{ |
||||||
|
"tableName": "t_icon", |
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `icon` TEXT, `color` TEXT, `size` INTEGER, `create_date` INTEGER, `deleted` INTEGER, PRIMARY KEY(`id`))", |
||||||
|
"fields": [ |
||||||
|
{ |
||||||
|
"fieldPath": "id", |
||||||
|
"columnName": "id", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "icon", |
||||||
|
"columnName": "icon", |
||||||
|
"affinity": "TEXT", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "color", |
||||||
|
"columnName": "color", |
||||||
|
"affinity": "TEXT", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "size", |
||||||
|
"columnName": "size", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "createDate", |
||||||
|
"columnName": "create_date", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
}, |
||||||
|
{ |
||||||
|
"fieldPath": "deleted", |
||||||
|
"columnName": "deleted", |
||||||
|
"affinity": "INTEGER", |
||||||
|
"notNull": false |
||||||
|
} |
||||||
|
], |
||||||
|
"primaryKey": { |
||||||
|
"autoGenerate": false, |
||||||
|
"columnNames": [ |
||||||
|
"id" |
||||||
|
] |
||||||
|
}, |
||||||
|
"indices": [], |
||||||
|
"foreignKeys": [] |
||||||
|
} |
||||||
|
], |
||||||
|
"views": [], |
||||||
|
"setupQueries": [ |
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", |
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '966ac67768ec0c8feefb2e843474d8c7')" |
||||||
|
] |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
package cc.niushuai.dididone.biz.dao; |
||||||
|
|
||||||
|
import androidx.room.Dao; |
||||||
|
import androidx.room.Delete; |
||||||
|
import androidx.room.Insert; |
||||||
|
import androidx.room.Query; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import cc.niushuai.dididone.biz.entity.Project; |
||||||
|
import io.reactivex.Completable; |
||||||
|
import io.reactivex.Flowable; |
||||||
|
|
||||||
|
@Dao |
||||||
|
public interface ProjectDao { |
||||||
|
|
||||||
|
@Query("SELECT * FROM t_project") |
||||||
|
Flowable<List<Project>> testListAll(); |
||||||
|
|
||||||
|
@Query("SELECT * FROM t_project where deleted = 0 order by create_date desc") |
||||||
|
Flowable<List<Project>> listAll(); |
||||||
|
|
||||||
|
@Query("SELECT count(*) FROM t_project where deleted = 0 and name = :name") |
||||||
|
Flowable<Integer> countByName(String name); |
||||||
|
|
||||||
|
@Insert |
||||||
|
Completable insertAll(Project... projects); |
||||||
|
|
||||||
|
@Delete |
||||||
|
void delete(Project project); |
||||||
|
|
||||||
|
@Query("delete from t_project where id = :id") |
||||||
|
void deleteById(Long id); |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
package cc.niushuai.dididone.biz.dao; |
||||||
|
|
||||||
|
import androidx.room.Dao; |
||||||
|
import androidx.room.Delete; |
||||||
|
import androidx.room.Insert; |
||||||
|
import androidx.room.Query; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import cc.niushuai.dididone.biz.entity.Record; |
||||||
|
|
||||||
|
import io.reactivex.Completable; |
||||||
|
import io.reactivex.Flowable; |
||||||
|
|
||||||
|
@Dao |
||||||
|
public interface RecordDao { |
||||||
|
|
||||||
|
@Query("SELECT * FROM t_record order by check_date desc, create_date desc") |
||||||
|
Flowable<List<Record>> listAll(); |
||||||
|
|
||||||
|
@Query("select * from t_record where deleted = 0 and check_date = :date order by check_date desc, create_date desc") |
||||||
|
Flowable<List<Record>> queryByDate(long date); |
||||||
|
|
||||||
|
@Query("select * from t_record where deleted = 0 and create_date >= :startDate and create_date <= :endDate order by check_date desc, create_date desc") |
||||||
|
Flowable<List<Record>> queryByDate(long startDate, long endDate); |
||||||
|
|
||||||
|
@Insert |
||||||
|
Completable insertAll(Record... records); |
||||||
|
|
||||||
|
@Delete |
||||||
|
void delete(Record record); |
||||||
|
|
||||||
|
@Delete |
||||||
|
void delete(Record... records); |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
package cc.niushuai.dididone.biz.dao; |
||||||
|
|
||||||
|
import androidx.room.Dao; |
||||||
|
|
||||||
|
@Dao |
||||||
|
public interface SavedIconDao { |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
package cc.niushuai.dididone.biz.entity; |
||||||
|
|
||||||
|
import androidx.room.ColumnInfo; |
||||||
|
import androidx.room.Entity; |
||||||
|
import androidx.room.PrimaryKey; |
||||||
|
|
||||||
|
@Entity(tableName = "t_project") |
||||||
|
public class Project { |
||||||
|
|
||||||
|
@PrimaryKey |
||||||
|
private Long id; |
||||||
|
|
||||||
|
@ColumnInfo(name = "name") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ColumnInfo(name = "project_icon_id") |
||||||
|
private Long projectIconId; |
||||||
|
|
||||||
|
@ColumnInfo(name = "create_date") |
||||||
|
private Long createDate; |
||||||
|
|
||||||
|
@ColumnInfo(name = "deleted") |
||||||
|
private Integer deleted; |
||||||
|
|
||||||
|
|
||||||
|
public Long getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(Long id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public Long getProjectIconId() { |
||||||
|
return projectIconId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProjectIconId(Long projectIconId) { |
||||||
|
this.projectIconId = projectIconId; |
||||||
|
} |
||||||
|
|
||||||
|
public Long getCreateDate() { |
||||||
|
return createDate; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCreateDate(Long createDate) { |
||||||
|
this.createDate = createDate; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getDeleted() { |
||||||
|
return deleted; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDeleted(Integer deleted) { |
||||||
|
this.deleted = deleted; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
package cc.niushuai.dididone.biz.entity; |
||||||
|
|
||||||
|
import androidx.room.ColumnInfo; |
||||||
|
import androidx.room.Entity; |
||||||
|
import androidx.room.PrimaryKey; |
||||||
|
|
||||||
|
@Entity(tableName = "t_record") |
||||||
|
public class Record { |
||||||
|
|
||||||
|
@PrimaryKey |
||||||
|
private Long id; |
||||||
|
|
||||||
|
@ColumnInfo(name = "name") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ColumnInfo(name = "check_date") |
||||||
|
private Long checkDate; |
||||||
|
|
||||||
|
@ColumnInfo(name = "description") |
||||||
|
private String description; |
||||||
|
|
||||||
|
@ColumnInfo(name = "create_date") |
||||||
|
private Long createDate; |
||||||
|
|
||||||
|
@ColumnInfo(name = "deleted") |
||||||
|
private Integer deleted; |
||||||
|
|
||||||
|
public Long getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(Long id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public Long getCheckDate() { |
||||||
|
return checkDate; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCheckDate(Long checkDate) { |
||||||
|
this.checkDate = checkDate; |
||||||
|
} |
||||||
|
|
||||||
|
public String getDescription() { |
||||||
|
return description; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDescription(String description) { |
||||||
|
this.description = description; |
||||||
|
} |
||||||
|
|
||||||
|
public Long getCreateDate() { |
||||||
|
return createDate; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCreateDate(Long createDate) { |
||||||
|
this.createDate = createDate; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getDeleted() { |
||||||
|
return deleted; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDeleted(Integer deleted) { |
||||||
|
this.deleted = deleted; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
package cc.niushuai.dididone.biz.entity; |
||||||
|
|
||||||
|
import androidx.room.ColumnInfo; |
||||||
|
import androidx.room.Entity; |
||||||
|
import androidx.room.PrimaryKey; |
||||||
|
|
||||||
|
@Entity(tableName = "t_icon") |
||||||
|
public class SavedIcon { |
||||||
|
|
||||||
|
@PrimaryKey |
||||||
|
private Long id; |
||||||
|
|
||||||
|
@ColumnInfo(name = "icon") |
||||||
|
private String icon; |
||||||
|
|
||||||
|
@ColumnInfo(name = "color") |
||||||
|
private String color; |
||||||
|
|
||||||
|
@ColumnInfo(name = "size") |
||||||
|
private Integer size; |
||||||
|
|
||||||
|
@ColumnInfo(name = "create_date") |
||||||
|
private Long createDate; |
||||||
|
|
||||||
|
@ColumnInfo(name = "deleted") |
||||||
|
private Integer deleted; |
||||||
|
|
||||||
|
public Long getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(Long id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getIcon() { |
||||||
|
return icon; |
||||||
|
} |
||||||
|
|
||||||
|
public void setIcon(String icon) { |
||||||
|
this.icon = icon; |
||||||
|
} |
||||||
|
|
||||||
|
public String getColor() { |
||||||
|
return color; |
||||||
|
} |
||||||
|
|
||||||
|
public void setColor(String color) { |
||||||
|
this.color = color; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getSize() { |
||||||
|
return size; |
||||||
|
} |
||||||
|
|
||||||
|
public void setSize(Integer size) { |
||||||
|
this.size = size; |
||||||
|
} |
||||||
|
|
||||||
|
public Long getCreateDate() { |
||||||
|
return createDate; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCreateDate(Long createDate) { |
||||||
|
this.createDate = createDate; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getDeleted() { |
||||||
|
return deleted; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDeleted(Integer deleted) { |
||||||
|
this.deleted = deleted; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
package cc.niushuai.dididone.biz.roomx; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
|
||||||
|
import androidx.room.Room; |
||||||
|
import androidx.room.RoomDatabase; |
||||||
|
|
||||||
|
import cc.niushuai.dididone.biz.dao.ProjectDao; |
||||||
|
import cc.niushuai.dididone.biz.dao.RecordDao; |
||||||
|
import cc.niushuai.dididone.biz.dao.SavedIconDao; |
||||||
|
|
||||||
|
public class DBManager { |
||||||
|
|
||||||
|
public static DBManager INSTANCE; |
||||||
|
private Context context; |
||||||
|
private Database database; |
||||||
|
|
||||||
|
public DBManager(Context context) { |
||||||
|
this.context = context; |
||||||
|
} |
||||||
|
|
||||||
|
public static void init(Context context) { |
||||||
|
INSTANCE = new DBManager(context); |
||||||
|
} |
||||||
|
|
||||||
|
public static RoomDatabase buildDatabase(Context context, Class<? extends RoomDatabase> clazz, String dbName) { |
||||||
|
RoomDatabase.Builder<? extends RoomDatabase> databaseBuilder = Room.databaseBuilder(context, clazz, dbName); |
||||||
|
databaseBuilder.setJournalMode(RoomDatabase.JournalMode.AUTOMATIC); |
||||||
|
databaseBuilder.allowMainThreadQueries(); |
||||||
|
return databaseBuilder.build(); |
||||||
|
} |
||||||
|
|
||||||
|
public Database getDataBase() { |
||||||
|
if (null == database) { |
||||||
|
database = (Database) buildDatabase(context, Database.class, "darling_done.db"); |
||||||
|
} |
||||||
|
return database; |
||||||
|
} |
||||||
|
|
||||||
|
public RecordDao recordDao() { |
||||||
|
return getDataBase().recordDao(); |
||||||
|
} |
||||||
|
|
||||||
|
public ProjectDao projectDao() { |
||||||
|
return getDataBase().projectDao(); |
||||||
|
} |
||||||
|
|
||||||
|
public SavedIconDao iconDao() { |
||||||
|
return getDataBase().savedIconDao(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package cc.niushuai.dididone.biz.roomx; |
||||||
|
|
||||||
|
import androidx.room.RoomDatabase; |
||||||
|
|
||||||
|
import cc.niushuai.dididone.biz.dao.ProjectDao; |
||||||
|
import cc.niushuai.dididone.biz.dao.RecordDao; |
||||||
|
import cc.niushuai.dididone.biz.dao.SavedIconDao; |
||||||
|
import cc.niushuai.dididone.biz.entity.Record; |
||||||
|
import cc.niushuai.dididone.biz.entity.Project; |
||||||
|
import cc.niushuai.dididone.biz.entity.SavedIcon; |
||||||
|
|
||||||
|
|
||||||
|
@androidx.room.Database(entities = {Record.class, Project.class, SavedIcon.class}, version = 1) |
||||||
|
public abstract class Database extends RoomDatabase { |
||||||
|
|
||||||
|
public abstract RecordDao recordDao(); |
||||||
|
|
||||||
|
public abstract ProjectDao projectDao(); |
||||||
|
|
||||||
|
public abstract SavedIconDao savedIconDao(); |
||||||
|
} |
Loading…
Reference in new issue