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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With