最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android集成GreenDao數(shù)據(jù)庫的操作步驟

 更新時間:2022年10月11日 14:46:45   作者:xiangzhihong8  
這篇文章主要介紹了Android集成GreenDao數(shù)據(jù)庫,使用數(shù)據(jù)庫存儲時候,一般都會使用一些第三方ORM框架,比如GreenDao,本文分幾步給大家介紹Android集成GreenDao數(shù)據(jù)庫的方法,需要的朋友可以參考下

數(shù)據(jù)持久化就是指將那些內(nèi)存中的瞬時數(shù)據(jù)保存到存儲設備中,保證即使在手機或電腦關(guān)機的情況下,這些數(shù)據(jù)仍然不會丟失。保存在內(nèi)存中的數(shù)據(jù)是處于瞬時狀態(tài)的,而保存在存儲設備中的數(shù)據(jù)是處于持久狀態(tài)的,持久化技術(shù)則提供了一種機制可以讓數(shù)據(jù)在瞬時狀態(tài)和持久狀態(tài)之間進行轉(zhuǎn)換。
目前,Android系統(tǒng)中提供了3種方式的數(shù)據(jù)持久化技術(shù),即文件存儲、SharedPreferences存儲以及數(shù)據(jù)庫存儲。當然,除了這3種方式之外,你還可以將數(shù)據(jù)保存在手機的SD卡中,不過使用文件、Shared Preferences或數(shù)據(jù)庫來保存數(shù)據(jù)會相對更簡單一些,而且比起將數(shù)據(jù)保存在SD卡中會更加地安全。Shared Preferences通常用在輕量級的數(shù)據(jù)存儲場景中,比如賬號/密碼的存儲,而數(shù)據(jù)庫則用在數(shù)據(jù)量比較大的場景中,比如聊天數(shù)據(jù)的存儲。

現(xiàn)在,使用數(shù)據(jù)庫存儲時候,一般都會使用一些第三方ORM框架,比如GreenDao。在Android開發(fā)中,集成Greendao通常需要如下幾步:

1.首先,在項目的build.gradle文件中添加依賴:

 classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' // add plugin

2.然后,在app/build.gradle文件中添加如下依賴:

apply plugin: 'org.greenrobot.greendao' // apply plugin
implementation 'org.greenrobot:greendao:3.3.0'

為了方便操作GreenDao數(shù)據(jù)庫,我們還需要對其進行封裝。首先,我們創(chuàng)建一個實體對象:

package com.yufulife.xj.model;

import com.yufulife.xj.bean.CameraTakeBean;
import com.yufulife.xj.bean.JoinTakeBean;
import com.yufulife.xj.bean.ListSubCachedBeanConverter;

import org.greenrobot.greendao.annotation.Convert;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Unique;

import java.util.HashMap;
import java.util.List;
@Entity
public class People {
    //不能用int
    @Id(autoincrement = true)
    private Long id;


    //巡檢編號
    @Unique
    private String inspection_id="";


    private String content="";

    @Convert(converter = ListSubCachedBeanConverter.class, columnType = String.class)
    private List<JoinTakeBean> mImgTT;

    @Generated(hash = 574353758)
    public People(Long id, String inspection_id, String content, List<JoinTakeBean> mImgTT) {
        this.id = id;
        this.inspection_id = inspection_id;
        this.content = content;
        this.mImgTT = mImgTT;
    }

    @Generated(hash = 1406030881)
    public People() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getInspection_id() {
        return this.inspection_id;
    }

    public void setInspection_id(String inspection_id) {
        this.inspection_id = inspection_id;
    }

    public String getContent() {
        return this.content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public List<JoinTakeBean> getMImgTT() {
        return this.mImgTT;
    }

    public void setMImgTT(List<JoinTakeBean> mImgTT) {
        this.mImgTT = mImgTT;
    } 
}

然后再封裝一個統(tǒng)一的管理類:

package com.yufulife.xj.model;

import android.util.Log;

import com.google.gson.Gson;
import com.yufulife.xj.App;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.ArrayList;
import java.util.List;

 
public class FaceMsgDao {

    private static final String TAG = "ClockInfoDao";

    /**
     * 添加數(shù)據(jù),如果有重復則覆蓋
     *
     * @param people
     */
    public static void insertData(People people) {
        long l = App.getmDaoSession().getPeopleDao().insertOrReplace(people);
        System.out.println("liu::::::  "+l);
    }

    public static long getId(People people) {

        return App.getmDaoSession().getPeopleDao().getKey(people);
    }

    public static People getPeopleWhere(String Inspection_id){
        List<People> list = App.getmDaoSession().getPeopleDao().queryBuilder().where(PeopleDao.Properties.Inspection_id.eq(Inspection_id)).list();
        if (list!=null){
            if (list.size()>=1){
                return list.get(0);
            }
        }
        return null;
    }
    public static void deletePeopleWhere(String Inspection_id){
        App.getmDaoSession().getPeopleDao().queryBuilder().where(PeopleDao.Properties.Inspection_id.eq(Inspection_id)) .buildDelete().executeDeleteWithoutDetachingEntities();

    }
    /**
     * 更新數(shù)據(jù)
     *
     * @param people
     */
    public static void updateData(People people) {
        App.getmDaoSession().getPeopleDao().update(people);
    }
    /**
     * 查詢?nèi)繑?shù)據(jù)
     */
    public static List<People> queryAll() {
        return App.getmDaoSession().getPeopleDao().loadAll();
    }

    public static void systemOutPeopleAll(){
        List<People> people = queryAll();
        for (People people1:people){
            System.out.println("liu::all  "+new Gson().toJson(people1));
        }
    }
    public static People getPeople(String war) {
        List<People> clockInfos = queryAll();
        if (clockInfos==null){
            System.out.println("liu:::  "+"沒有找到數(shù)據(jù)");
            return null;
        }

        for (People info : clockInfos) {
            if (info.getInspection_id() .equals(war) ) {
                return info;
            }
        }
        System.out.println("liu:::  "+"沒有找到數(shù)據(jù)");
        return null;
    }
}

需要注意的是,在使用GreenDao數(shù)據(jù)庫之前,需要先在項目中初始化,比如。

 private static DaoSession mDaoSession;
    public static DaoSession getmDaoSession() {
        return mDaoSession;
    }
    /**
     * 初始化數(shù)據(jù)庫
     */
    private void setDataBaseData() {
        //創(chuàng)建數(shù)據(jù)庫shop.db"
        DaoMaster.DevOpenHelper mDaoMaster = new DaoMaster.DevOpenHelper(this, "inspection.db", null);
        //獲取可寫的數(shù)據(jù)庫
        SQLiteDatabase writableDatabase = mDaoMaster.getWritableDatabase();
        //獲取數(shù)據(jù)庫對象
        DaoMaster daoMaster = new DaoMaster(writableDatabase);
        //獲取Dao對象管理者
        mDaoSession = daoMaster.newSession();
    }

最后,只需要在業(yè)務中使用FaceMsgDao操作數(shù)據(jù)即可。

到此這篇關(guān)于Android集成GreenDao數(shù)據(jù)庫的文章就介紹到這了,更多相關(guān)Android GreenDao數(shù)據(jù)庫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android 圖片選擇詳解及實例代碼

    Android 圖片選擇詳解及實例代碼

    這篇文章主要介紹了 Android 圖片選擇詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • Android Studio給各種控件加邊框的操作方法

    Android Studio給各種控件加邊框的操作方法

    這篇文章主要介紹了Android Studio給各種控件加邊框的操作方法,本文通過圖文實例相結(jié)合給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • Android日期和時間選擇器實現(xiàn)代碼

    Android日期和時間選擇器實現(xiàn)代碼

    這篇文章主要為大家詳細介紹了Android日期和時間選擇器實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Android編程實現(xiàn)動態(tài)更新ListView的方法

    Android編程實現(xiàn)動態(tài)更新ListView的方法

    這篇文章主要介紹了Android編程實現(xiàn)動態(tài)更新ListView的方法,結(jié)合實例形式詳細分析了ListView的布局及動態(tài)更新實現(xiàn)方法,需要的朋友可以參考下
    2016-02-02
  • Android中Splash應用啟動白屏問題的解決方法

    Android中Splash應用啟動白屏問題的解決方法

    這篇文章主要為大家詳細介紹了Android中Splash應用啟動白屏問題的兩種解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • 詳細介紹Android中回調(diào)函數(shù)機制

    詳細介紹Android中回調(diào)函數(shù)機制

    這篇文章主要介紹了Android中回調(diào)函數(shù)機制,有需要的朋友可以參考一下
    2014-01-01
  • Android編程獲取屏幕寬高與獲取控件寬高的方法

    Android編程獲取屏幕寬高與獲取控件寬高的方法

    這篇文章主要介紹了Android編程獲取屏幕寬高與獲取控件寬高的方法,實例分析了Android針對屏幕及控件常用屬性的相關(guān)操作技巧,需要的朋友可以參考下
    2015-12-12
  • Android WorkManager實現(xiàn)后臺定時任務流程詳解

    Android WorkManager實現(xiàn)后臺定時任務流程詳解

    WorkManager是Android Jetpack的一個強大的組件,用于處理后臺耗時任務。后臺任務可以是一次性的,也可以是重復的,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2023-01-01
  • 淺談Android ANR在線監(jiān)控原理

    淺談Android ANR在線監(jiān)控原理

    這篇文章主要介紹了淺談Android ANR在線監(jiān)控原理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • AndroidStudio3 支持 Java8 了請問你敢用嗎

    AndroidStudio3 支持 Java8 了請問你敢用嗎

    Google 發(fā)布了 AS 3.0,以及一系列的 Support 包,有意思的新東西挺多,AS3里面有一個亮眼的特性就是支持J8。接下來通過本文給大家分享AndroidStudio3 支持 Java8 的相關(guān)內(nèi)容,感興趣的朋友一起看看吧
    2017-11-11

最新評論

海宁市| 巴塘县| 手游| 兴国县| 老河口市| 尉氏县| 双江| 峨山| 乌鲁木齐县| 阳原县| 丰原市| 黑河市| 桦南县| 和田县| 大同市| 苗栗市| 旺苍县| 贵定县| 尉氏县| 新巴尔虎左旗| 湘潭市| 扎兰屯市| 繁峙县| 色达县| 门头沟区| 高要市| 南开区| 屏南县| 安岳县| 西和县| 阳信县| 虞城县| 九龙县| 苗栗市| 专栏| 太湖县| 汶川县| 大足县| 湘潭市| 怀宁县| 赤城县|