开发一个好项目:三、创建数据源,首先创建本地数据源

前一篇文章:开发一个好项目:二、actvity简便跳转,创建菜单按钮,正确使用fragment 框架地址dileber android框架 希望大家能多多star一下

创建数据模型LaunchModel

public class LaunchModel extends SModel {

    UserInfoModel userInfoModel;

    public UserInfoModel getUserInfoModel() {
        return userInfoModel;
    }

    public void setUserInfoModel(UserInfoModel userInfoModel) {
        this.userInfoModel = userInfoModel;
    }

}

UserInfoModel 有一个_id ,主要是用于数据库添加自增长的id,继承于smodel,可以更好的做数据处理,比如在插入数据,或者本地数据存储,框架里都做了处理

public class UserInfoModel extends SModel {
    private Integer _id;
    public Integer get_id() {
        return _id;
    }

    public void set_id(Integer _id) {
        this._id = _id;
    }
    private Integer userinfoid;

    private Integer uid;

    private String userinfoname;

    private Integer userinfoheight;

    private Integer userinfoweight;

    private Integer userinfoclub;

    private Integer userinfohand;

    private Integer userinfobackhand;

    private Integer userinfofloor;

    private String userinfohandname;

    private String userinfobackhandname;

    private String userinfofloorname;

    private String userinfoflag;

    private Integer userinfogender;

    private Date userinfobirthday;

    private Integer userinfolocal;

    private String userinfolocalname;

    private String userinfointroduce;

    private String userinfoskill;

    private String usernikename;

    private String userphone;

    private String userimage;

    private Integer userimageversion;

    private Integer userinfofenshu;

    public Integer getUserinfofenshu() {
        return userinfofenshu;
    }

    public void setUserinfofenshu(Integer userinfofenshu) {
        this.userinfofenshu = userinfofenshu;
    }

    public String getUserphone() {
        return userphone;
    }

    public void setUserphone(String userphone) {
        this.userphone = userphone;
    }

    public String getUserimage() {
        return userimage;
    }

    public void setUserimage(String userimage) {
        this.userimage = userimage;
    }

    public Integer getUserimageversion() {
        return userimageversion;
    }

    public void setUserimageversion(Integer userimageversion) {
        this.userimageversion = userimageversion;
    }

    public String getUsernikename() {

        return usernikename;
    }

    public void setUsernikename(String usernikename) {
        this.usernikename = usernikename;
    }

    public String getUserinfoskill() {
        return userinfoskill;
    }

    public void setUserinfoskill(String userinfoskill) {
        this.userinfoskill = userinfoskill == null ? null : userinfoskill.trim();
    }


    public Integer getUserinfoid() {
        return userinfoid;
    }

    public void setUserinfoid(Integer userinfoid) {
        this.userinfoid = userinfoid;
    }

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getUserinfoname() {
        return userinfoname;
    }

    public void setUserinfoname(String userinfoname) {
        this.userinfoname = userinfoname == null ? null : userinfoname.trim();
    }

    public Integer getUserinfoheight() {
        return userinfoheight;
    }

    public void setUserinfoheight(Integer userinfoheight) {
        this.userinfoheight = userinfoheight;
    }

    public Integer getUserinfoweight() {
        return userinfoweight;
    }

    public void setUserinfoweight(Integer userinfoweight) {
        this.userinfoweight = userinfoweight;
    }

    public Integer getUserinfoclub() {
        return userinfoclub;
    }

    public void setUserinfoclub(Integer userinfoclub) {
        this.userinfoclub = userinfoclub;
    }

    public Integer getUserinfohand() {
        return userinfohand;
    }

    public void setUserinfohand(Integer userinfohand) {
        this.userinfohand = userinfohand;
    }

    public Integer getUserinfobackhand() {
        return userinfobackhand;
    }

    public void setUserinfobackhand(Integer userinfobackhand) {
        this.userinfobackhand = userinfobackhand;
    }

    public Integer getUserinfofloor() {
        return userinfofloor;
    }

    public void setUserinfofloor(Integer userinfofloor) {
        this.userinfofloor = userinfofloor;
    }

    public String getUserinfohandname() {
        return userinfohandname;
    }

    public void setUserinfohandname(String userinfohandname) {
        this.userinfohandname = userinfohandname == null ? null : userinfohandname.trim();
    }

    public String getUserinfobackhandname() {
        return userinfobackhandname;
    }

    public void setUserinfobackhandname(String userinfobackhandname) {
        this.userinfobackhandname = userinfobackhandname == null ? null : userinfobackhandname.trim();
    }

    public String getUserinfofloorname() {
        return userinfofloorname;
    }

    public void setUserinfofloorname(String userinfofloorname) {
        this.userinfofloorname = userinfofloorname == null ? null : userinfofloorname.trim();
    }

    public String getUserinfoflag() {
        return userinfoflag;
    }

    public void setUserinfoflag(String userinfoflag) {
        this.userinfoflag = userinfoflag == null ? null : userinfoflag.trim();
    }

    public Integer getUserinfogender() {
        return userinfogender;
    }

    public void setUserinfogender(Integer userinfogender) {
        this.userinfogender = userinfogender;
    }

    public Date getUserinfobirthday() {
        return userinfobirthday;
    }

    public void setUserinfobirthday(Date userinfobirthday) {
        this.userinfobirthday = userinfobirthday;
    }

    public Integer getUserinfolocal() {
        return userinfolocal;
    }

    public void setUserinfolocal(Integer userinfolocal) {
        this.userinfolocal = userinfolocal;
    }

    public String getUserinfolocalname() {
        return userinfolocalname;
    }

    public void setUserinfolocalname(String userinfolocalname) {
        this.userinfolocalname = userinfolocalname == null ? null : userinfolocalname.trim();
    }

    public String getUserinfointroduce() {
        return userinfointroduce;
    }

    public void setUserinfointroduce(String userinfointroduce) {
        this.userinfointroduce = userinfointroduce == null ? null : userinfointroduce.trim();
    }

}

创建接口SysDataSource 继承基类BaseDataSource 里面全是是获取数据的接口

public interface SysDataSource extends BaseDataSource{

    void getLaunch(BaseDataSource.BaseCallback<LaunchModel> callback);

}

创建本地数据处理类SysLocalDataSource 数据类里直接就有数据库处理方式,只需要写好数据库创建语句,之后添加到list,用dbmanager就可以使用数据库的方法了,数据库方法很多,有批量插入,批量更新。单次增删查改。也可以直接映射到model上,只要你继承smodel!

public class SysLocalDataSource extends BaseLocalDataSource implements SysDataSource{

    String match = "CREATE TABLE match (_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,matchid INTEGER,matchname TEXT,matchtime INTEGER,matchcreatetime INTEGER,matchfromuser INTEGER,matchtouser INTEGER,matchstate INTEGER,matchplace INTEGER)";



    private static volatile SysLocalDataSource instance;

    private SysLocalDataSource(){

        List<String> list = new ArrayList<>();
        list.add(match);
        dbManager = dbManager.getDB("launch",Config.DB_VERSION,list);

    }

    public static SysLocalDataSource getInstance(){
        if (instance==null){
            synchronized (SysLocalDataSource.class){
                if(instance==null){
                    instance = new SysLocalDataSource();
                }
            }
        }
        return instance;
    }

 @Override
    public void getLaunch(BaseDataSource.BaseCallback<LaunchModel> callback) {
        String launch = hPref.get(Config.PERF_APP,Config.PERF_LANUCH,null,String.class);
        Logger.sl(Log.DEBUG,launch);
        if(launch!=null){
            callback.onSuccess(HJson.fromJson(launch,LaunchModel.class));
        }else{
            callback.onFailure(new DataSourceException("数据为空"));
        }

    }
}

这个类怎么使用后续会继续讲解,后续还有如何使用缓存使得数据源快速加载。等等~~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二蛋和他的大花

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值