so I'm trying to do something with MapDB and I've run into a wall. I'll try describing it best I can:
I have four pieces of data, we'll say it goes like this:
1) String action; //the name of the action itself
2) String categoryOfAction; //the category of the action
3) Integer personWhoPerformedAction; //the person that did the action
4) Long timeOfOccurrence; //the time the action was done
The same action can be performed multiple times in this database, by different people and at different times, as well as in different categories. I want to have three separate maps, each that organize data into something like this:
String[] actionOccurances = map1.get(action); //returns every occurrence of that action (possibly in an array), including who did that occurrence, time the occurrence occurred, and the category of that occurrence
Long latestOccurance = map2.get(action); //returns the latest occurrence of that action
String[] actionsPerformedByPerson = map3.get(personWhoPerformedAction); //returns every action that this person has done, including the category of that action, the time they performed that action, and the name of the action itself
So, I want to do this as efficiently as possible. I know that I could just do something like this:
DB thedb = DBMaker.newTempFileDB().make();
NavigableSet<Object[]> map1 = thedb.createTreeSet("actionOccurences").comparator(Fun.COMPARABLE_ARRAY_COMPARATOR).make();
HTreeMap<String, Long> map2 = thedb.getHashMap("lastOccurrence");
NavigableSet<Object[]> map3 = thedb.createTreeSet("actionsPerformedByPerson").comparator(Fun.COMPARABLE_ARRAY_COMPARATOR).make();
But I feel like that's wrong. There must be a much more efficient way where I don't have to store the same data multiple times, yeah?
I've played quite a bit with the Bind class and it's functions (secondaryValues, mapInverse, etc. etc.) but I can't seem to find a way to map this set of data out how I want it to be.
Any help? Thanks.
Ah! After awhile of working on this, I found a solution. I basically assign a unique ID to every record and then use MapDB's secondaryKey binding. It goes like this:
However, still chime in if you think you can improve this solution. Thanks!