Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store several ArrayLists in ORMLite for ApplicationSettings

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?

like image 556
Robin Avatar asked Nov 26 '12 18:11

Robin


1 Answers

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

like image 67
Driss Bounouar Avatar answered Oct 19 '22 11:10

Driss Bounouar