简体   繁体   English

如何将这些对象存储在SQLite数据库中?

[英]How should I store these objects in SQLite database?

So I have a class named A: 所以我有一个名为A的类:

public class A{
    private String A1;
    private String A2;
    private String A3;
    private String A4;
    private B A5;
    private B A6;
}

That as you can see contains some strings and 2 B class typed object. 如您所见,其中包含一些字符串和2 B类类型的对象。 The B class: B类:

public class B{
    private ArrayList<C> B1;
}

Contains 1 arraylist of C elements. 包含1个C元素的数组列表。 The C class: C类:

public class C{
    private String C1;
    private ArrayList<D> C2;

A string and arraylist of D objects. D对象的字符串和数组列表。 The D class: D类:

public class D{
    private String D1;
    private Boolean D2;
}

I get the data from JSON files, I build up an arraylist out of A objects, but I should store it in a database because I do not want to download the data every time the user opens the application... 我从JSON文件中获取数据,我从A对象中构建了一个arraylist,但是我应该将其存储在数据库中,因为我不想每次用户打开应用程序时都下载数据...

You are attempting to store non-atomic values into a relational database. 您正在尝试将非原子值存储到关系数据库中。 You must normalize it using multiple tables which relate to each other using foreign keys. 您必须使用多个使用外键相互关联的表对其进行规范化。 Quite a tedious task to do. 要做的工作很繁琐。

Perhaps you can store the object itself using serialization - resource 也许您可以使用序列化存储对象本身- 资源

You just want to store the custom model object into a database so for this you can use room Persistence database by Google. 您只想将自定义模型对象存储到数据库中,因此您可以使用Google的room Persistence数据库。 Check the following link: local database using Roome 检查以下链接: 使用Roome的本地数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM