cl3b34 / vocabuilder

Automatically exported from code.google.com/p/vocabuilder
0 stars 0 forks source link

Create a more flexible file format for storing data in the RMS #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently I'm storing meta data from the SetOfCards and data from the Card
in all the records saved to RMS.

This is highly inefficient for parsing the data back. Data from the set
needs to be read all the time.

A new format for the metadata should be created. Since I want to keep using
the DataInputStream and DataOutputStream facilities, I have to create a
fixed format for the metadata in the *second* record or store a XML or JSON
version of the metadata in a String in the first record. 

The second option seems too complex for the current needs, since I don't
need to transfer the data anywhere, creating a parser would be too much
overhead.

For the first option the record format should be something like:

setOfCardsTitle setOfCardsIsDone setOfCardsStudyTime totalCardsDisplayed
lastTimeSetViewed lastTimeSetMarkedDone markedDoneSetCounter

which translates to the Java types:

String boolean long int long long int int

The metadata is stored in the second record because I want to create a
'file format version' metadata so I'm able to maintain backwards
compatibility in case I need to change the file format again. This metadata
will be stored in the *first* record and has the format:

fileFormatVersion

int

The data about the FlashCards will be stored from the 3rd record on and
follows the format:

cardSideOneTitle cardSideOneText cardSideTwoTitle cardSideTwoText
cardIsDone cardTip cardViewedCounter cardMarkedDoneCounter
cardLastTimeViewed cardLastTimeMarkedDone 

String String String String boolean String int int long long 

Original issue reported on code.google.com by cl3...@gmail.com on 18 Apr 2008 at 5:16

GoogleCodeExporter commented 9 years ago
Current file format (set meta data is mixed with card data):

title setIsDone totalTime side1title side1text side2title side2text cardIsDone 
tip
totalOfDisplayedCards setLastTimeViewed setLastTimeMarkedDone 
setMarkedDoneCounter
cardViewedCounter cardMarkedDoneCounter cardLastTimeViewed 
cardLastTimeMarkedDone

String boolean int String String String String boolean String int long long int 
int
int long long

Original comment by cl3...@gmail.com on 18 Apr 2008 at 7:29

GoogleCodeExporter commented 9 years ago
while creating the new file format the following has to be done:

1 - add a new field 'cardId' to the FlashCard VO
2 - Check if the recordStore being read has the file format version number and 
the
number is the same we expect.
3 - If not, we need to upgrade the file format. We read using the old method and
write the store back immediately in the new format.
4 - The store need to be written back immediately since the record size of a 
single
card is now larger and saving it to the old store would corrupt data. 
5 - This will cause a substantial delay on the first app startup after the 
upgrade,
since we will need to read and write the whole store at startup time.

Original comment by cl3...@gmail.com on 21 Apr 2008 at 6:18

GoogleCodeExporter commented 9 years ago
New file format implemented.
Instead of using the 'update a single record' method, I'm creating the whole 
store
again, only that now I save all the card data in a single ( 3rd ) record. 
This way, the data only needs to be saved on the end, as before.
So:

1st record: File format version (currently 4)
2nd record: Set meta data
3rd record: card data

Original comment by cl3...@gmail.com on 13 May 2008 at 8:45