Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 342
Registered: ‎09-28-2009
My Device: Not Specified

Relational Objects in Persistent Storage

Howdy, all.

 

I'm implementing persistent storage of relational objects, and I wanted to check the forum and see if there's a better way that what I'm doing.  Right now, I simply create pointers to other objects and store them all together, but I haven't tested it yet.  Would it be better to assign each object a unique ID number, and reference objects through that instead of a pointer?

 

Thanks,

Joe

Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Relational Objects in Persistent Storage

What platform are you targeting?

Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: Relational Objects in Persistent Storage

Assuming that you really do have to use persistent storage (and can't use SQL, which is I think the point of ydaraishy's question), then I would recommend that you store a single 'table' in a single UID.

 

We have implemented something similar to store data - we have 'tables' that have up to 15,000 rows in a Vector, each Vector has its own GUID.

 

But if you can do it with SQL, I would seriously recommend looking at SQLite in OS 5.0 (and later). 

Developer
Posts: 342
Registered: ‎09-28-2009
My Device: Not Specified

Re: Relational Objects in Persistent Storage

To simplify, what I'm doing now is something like:

 

class SampleContainer
{
    public Vector vA;
    public Vector vB;
    public Vector vC;
    
    public SampleContainer(){}
}
class SampleA
{
    public SampleB b;
    public Vector vC;
    
    public SampleA(){}
}
class SampleB
{
    public int val;
    public SampleB()
    { val = 24; }
}
class SampleC
{
    public String szVal;
    public SampleC(String s)
    { szVal = s; }
}

 

Where I have a bunch of standalone classes that may contain or reference one or more instances of each other.  Some objects are thumbnails, others just contain booleans and strings.  What I'm not sure of is if I do something like:

 

SampleContainer sc = new SampleContainer();
SampleA a = new SampleA();
SampleB b = new SampleB();
SampleC c1 = new SampleC("1");
SampleC c2 = new SampleC("2");
a.b = b;
a.vC.addElement(c1);
a.vC.addElement(c2);
sc.vA.addElement(a);
sc.vB.addElement(b);
sc.vC.addElement(c1);
sc.vC.addElement(c2);
PersistentStore.getPersistentObject(MY_ID).setContents(sc);

 

If I call back that persistent store, will the vC vector in the SampleA object still contain pointers to the SampleC objects?  If not, how do you recommend I achieve this pre-5.0?

 

Also, I read in the documentation that a PersistentStore object has a limit of 64KB.  Does it count that SampleContainer object as a single element, or each individual object contained within?  I would expect a megabyte or two of storage being necessary when applied to the actual objects.

 

Thanks very much, guys.  Looking forward to your answer.

Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Relational Objects in Persistent Storage

Instance variables of an object should be preserved in a persist of that object, but, there may be an different way: like SQL maintains links to other tables by same IDs in both tabes and then joining upon them, you can do something similar by crafting "table" classes and then persisting those. This might be easier and it might not be...

Developer
Posts: 342
Registered: ‎09-28-2009
My Device: Not Specified

Re: Relational Objects in Persistent Storage

Thanks, I got my test working, and the references stay.  Now my other question that I'm testing for right now is size limitations.  The documentation says that a PersistentObject can be a maximum of 64Kb in size.  I need to store much, much more data than that.  Currently, I'm storing a vector that contains a vector of objects for each type of class.  Does the size limitation apply to that master vector, or can I make it as big as I like, as long as none of the contained objects are larger than 64Kb?

Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: Relational Objects in Persistent Storage

Ignore that limit, that article should have been updated ages ago.  Put a link in here to where you found it, and we will see if we can't get RIM to fix the size limit.

 

I'm not aware of the limit, but it is many megabytes.....

Developer
Posts: 342
Registered: ‎09-28-2009
My Device: Not Specified

Re: Relational Objects in Persistent Storage

Took me a moment to find it, but here's the link:

http://docs.blackberry.com/en/developers/deliverables/5580/BB_persistent_store_APIs_447292_11.jsp

 

I'll let you know if I find any notable size limit while I'm testing.

Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: Relational Objects in Persistent Storage

Sorry, nothing we can do about that, that is a published document....

 

As noted, I've stored 15,000 rows on a 7290 when I was testing back when that was a current device.  For today's devices, I would expect significantly more that that number.  And when you start getting to that sort of number, the biggest issue turns into getting the data to the device....