Android Question Need some advice on best data structure to use for Parent/Child

Widget

Well-Known Member
Licensed User
Longtime User
BACKGROUND:
I am writing a B4A/B4i application that will be processing data for a Parent/Child relationship. The data will eventually be stored in a SQLite database locally and also retrieved from a web server too. I'm thinking of storing the data in JSON format and may just store it in a Text field in the table. This will simplify things if I use a REST server to send the JSON text to the B4A/B4i app because it will be a lot less work for the REST server compared to storing the data in a normal CS tables and have the REST server generate the JSON data from the table records before sending it to the client.

But that is not too important at the moment. I am more concerned in how to access this Parent/Child data in the B4A/B4i application.

CURRENT DATA STRUCTURE USES LIST -> TYPE:
Currently I have two Lists, lstParent and lstChild that stores Type data for each item: TrcdParent and TrcdChild are the Types. The TrcdParent and TrcdChild Types consists of a few Strings and numbers with no more than 8 fields. The TrcdChild has a ParentId (UUID) that corresponds to the lstParent item. It currently has to do a manual search on lstParent to find the proper ParentId but that is ok because there won't be too many rows in lstParent, probably no more than a dozen at a time. The lstChild will hold around 10 items per parent. It could go as high as 100 but that will be rare.

ALTERNATIVE USE LIST -> MAP?
Here is my problem. I started playing around with the JSON tutorial and I'm impressed with what can be done with Lists items being able to reference a Map. I am wondering if I should stop using Types and replace it with a Map? The lstParent entry instead of referencing TrcdParent will reference mapParent with a Key=Value pair for each field along with a lstChild (that has the 10-100 items) with each item pointing to a mapChild with a Key=Value pair for each child value for this child record.

So instead of a single TrcdParent type, there will be a map of field value pairs. Instead of a TrcdChild there will be a mapChild with field value pairs.

QUESTION:
My question is, will using a Map for the Parent and Child be too slow or too memory extensive compared to using a Type? I will have to traverse the lstChild entries for a single parent and do some simple tallies and occasionally delete or add a few child rows.

Does anyone have any recommendations?
TIA
 

Widget

Well-Known Member
Licensed User
Longtime User
I don't know JSON; given that there is an ExecuteJSON command in DBUtils, I would try to store data in two "classic" related DB tables (local SQLite) and try that command.

Thanks for the reply. So you're saying it is better for my application to access the Parent/Child data directly using SQLite tables rather than accessing the data using complex Lists and Maps to store the field values?

After posting I took an hour off and thought some more about the problem. I think maybe you're right. I see no advantage to putting all of that data into memory structures like a List or Map when the record data will only be accessed occasionally. Using lists and maps for storing data makes for an interesting mental challenge, but it may just complicate the code unnecessarily. I'll try SQLite and use Lists/Maps only when I need generate the JSON to transfer the data to/from the server.

Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…