Best way to store several ArrayLists in ORMLite for ApplicationSettings

微笑、不失礼 提交于 2019-12-12 11:07:45

问题


Right now I am trying to persist the Settings of an Application to my DB with the help of ORMLite.

Well my settings consist of different String[] or ArrayList<String> or maybe a Map actually just a bunch of Strings. So my question is, what datatype should I use for such a scenario and optional maybe you could also provide me a small code example.

Right now I tried different things, but I never was happy with the solution. I tried stuff like:

private HashMap<String, ArrayList<String>> configurationMap;

private String[] stringArr1;
private String[] stringArr2;

private ArrayList<String> arrList1;

But when it comes to setup the DB Datatypes I always think, "I don't want an extra table to store the data" or "having a map serialized to the DB sucks...".

Maybe anybody has an idea how to solve this in a nice and convenient way?


回答1:


For the arrayList you can simply do the following :

public class YourClass{
    @GeneratedId
    private int id;

    @ForeignCollectionField
    private Collection<MyString> bunchOfStrings = new ArrayList<MyString>();
    ...
}

In the MyString class you have the following :

public class MyString{
    @DatabaseField(canBeNull = true, foreign = true)
    private YourClass yourClass;

     @DatabaseField
     private String text;
    ....
}

And that's all



来源:https://stackoverflow.com/questions/13570578/best-way-to-store-several-arraylists-in-ormlite-for-applicationsettings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!