问题
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