TinyDB old vs new

93 views
Skip to first unread message

Steve Marcus

unread,
Aug 18, 2013, 1:17:47 PM8/18/13
to alternate-java-bridg...@googlegroups.com
Hi all,

I want to update an app written in Eclipse using the java bridge, with an app written in App Inventor.

I have done this before and it was all fine. However this time the app has a TinyDB, and users have information stored in it.

I notice that with App Inventor, the TinyDB file is a single xml file. However with the Java Bridge, it is a lot of individual files for each value.

Is there any way, when updating the app to the Eclipse version, to 'convert' all the values in the single xml file to the new TinyDB system of individual files?

I was thinking of updating the app inventor app first to somehow get all the values of the TinyDB xml data and save it to a text file on their sd card. Then update the app again using the bridge version, and then run a procedure to grab those values again from the sd card, and store it in the new TinyDB. However the way my app works this would be rather messy. 

Is there any way to do it? Or perhaps does it do it automatically? (hope hope)..


Thanks,


S

Imp Inc

unread,
Aug 18, 2013, 7:25:31 PM8/18/13
to alternate-java-bridg...@googlegroups.com
You bring up a good point here.

Just so you, and everyone else know, there are 3 main options for local data persistence in the bridge:

1. Prefs - This behaves like the old TinyDB. However, to access stuff written with the AI TinyDB, I had to add the UseOldTinyDBFile(boolean useOld) method to this Prefs class. Set that method to true, and it will use the "TinyDB" file instead. (I'll upload the new jar sometime in the very near future). If you use this class, along with setting that method to true, it should be able to read the old data. This is best used for small amounts of data, like preferences.

2. TinyDB - The name doesn't really suit what this class does. Every value is stored to it's own file. This is good if you want to store large arraylists, or hashmaps (or any serializable object). The prefs class only allows int, long. String, and boolean, so if you want to store something else, you'll have to use TinyDB.

3. SimpleSQL - This class uses a SQLite database to store data. Use this if you have to store a large amount of data in columns, and rows (like a big spreadsheet).

- Ryan

Steve Marcus

unread,
Aug 19, 2013, 8:11:01 AM8/19/13
to alternate-java-bridg...@googlegroups.com
Hey that sounds promising - so could I use UseOldTinyDBFile(true) to read the old TinyDB xml file and then once I have those values in the app, store them in the new TinyDB file system? Would that be possible?

It's not a huge amount of data, but not small either, and it does contain arraylists, say around 10 of them.

Imp Inc

unread,
Aug 19, 2013, 11:46:49 AM8/19/13
to alternate-java-bridg...@googlegroups.com
The arraylists will have to take a little more thought. You won't be able to read those with the Prefs class right now. I'll work on it soon (most likely the weekend).

Ryan

Steve Marcus

unread,
Sep 20, 2013, 11:51:52 AM9/20/13
to alternate-java-bridg...@googlegroups.com
Great I can see it there. Do I do it like this?

import com.xiledsystems.AlternateJavaBridgelib.components.altbridge.Prefs;
.
.
Prefs oldPreferences;
.
.
oldPreferences = new Prefs(this);
.
.
oldPreferences.UseOldTinyDBFile(true);


After this, whenever I do a TinyDB Get command, will this then get the value from the old TinyDB file?

Then when I have got the values, if I changed it back to false, can I use the TinyDB Store Value to save the value in the new TinyDB file system?

Would that work?




Steve Marcus

unread,
Sep 20, 2013, 12:23:38 PM9/20/13
to alternate-java-bridg...@googlegroups.com
Never mind I worked it out.

int value1 = Convert.Int(oldPreferences.GetString("value1"));

then tinyDB.StoreValue("value1", value1);

does the trick!

Steve Marcus

unread,
Sep 21, 2013, 12:02:56 PM9/21/13
to alternate-java-bridg...@googlegroups.com
I created a method to convert a list from the old TinyDB into an ArrayList<Integer> in the new TinyDB. Works great.

private void convertArrayListInteger(String tinyDBName, int length) {
String temp = oldPreferences.GetString(tinyDBName).replace("[", "").replace("]", "");
String [] temp2 = temp.split(",");
ArrayList<Integer> temp3 = new ArrayList<Integer>();
for (int i = 0; i < length; i++) {
temp3.add(Convert.Int(temp2[i]));
}
tinyDB.StoreValue(tinyDBName, temp3);
Reply all
Reply to author
Forward
0 new messages