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
New Developer
Posts: 4
Registered: ‎03-29-2009
My Device: Not Specified

Is double persistable - API doesn't list it as such

I'm using RIM's PersistentStore and have successfully persisted doubles, but their API documentation for PersistentObject states:

 

"Notice that some classes are implicitly persistable: Boolean, Byte, Character, Integer, Long, Object, Short, String, Vector, Hashtable"

 

I have also read some BlackBerry books that state the same thing - Double is left out.  So even though doubles appear to be persistable, I am concerned that I may run into some unforeseen problems.

 

Can someone from RIM confirm?

 

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Is double persistable - API doesn't list it as such

When you've persisted doubles, that's as part of an Object of some sort that has been declared (or is implicitly) Persistable? I don't think that's a problem at all.

 

It's just that Double (and Float) evidently are not implicitly persistable like the other classes listed. I don't know why those were left out, but I don't think it's anything to worry about. (Maybe it's just the docs that left it out. I suppose someone could do an experiment and try to persist a Double.)




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
New Developer
Posts: 4
Registered: ‎03-29-2009
My Device: Not Specified

Re: Is double persistable - API doesn't list it as such

I have some (primitive) doubles as part of some custom persistable classes.  I tried to persist them on some actual devices running OS 4.7 and 5.0 and it works, so maybe it is just something missing form their API doc as you mentioned, but I would still like to know officially from RIM, since unsupported features that work now may not work in future versions.

 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Is double persistable - API doesn't list it as such

Why would you think the other classes are implicitly persistable and not Double (and Float)? Objects are persistable as long as all of their data elements are persistable. All of the data/number objects contain only a field with that type of value; so saying any if them are not inherently persistable is saying that any of the primitive data types themselves are not persistable.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Is double persistable - API doesn't list it as such

From the API docs for interface Persistable:

Every object that can persist between handheld resets must implement persistable. A class must explicitly implement this interface for the system to persistently store instances of the class. Sub-classes do not inherit implementation of this interface.

And from the docs for class PersistentObject:

Notice that some classes are implicitly persistable: Boolean, Byte, Character, Integer, Long, Object, Short, String, Vector, Hashtable

No mention of Double or Float.

 

I'm not surprised that all primitive data members of a Persistable class can be written to persistent store. I was just saying that Double and Float do not appear to implement Persistable.

 

The data elements of a Persistable object do not, as far as I know, need to be themselves Persistable. Where did you read this? I think perhaps you are confusing Persistable with the Serializable mechansm of J2SE.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Is double persistable - API doesn't list it as such

If you try to persist a custom class with non-persistable elements/inner classes it will give you that error that it doesnt implement the persistable interface.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Is double persistable - API doesn't list it as such

You're right. Somehow I never realized that. Smiley Sad

 

This code:

 

class Foobar implements Persistable {
    Double dbl;
}

generates the following compile time error:

 

Foobar: Error!: Class Foobar marked Persistable by interface: net.rim.device.api.util.Persistable is not Persistable: field dbl: Class java.lang.Double does not implement net.rim.vm.Persistable

 

Simliarly with Float. The other primitive-boxing classes all seem to be Persistable. I have no idea why RIM excluded Float and Double.

 

Irritatingly, the compiler only complains about the first non-Persistable field it finds, even if the class has several of them.

 




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Is double persistable - API doesn't list it as such

[ Edited ]

That is intersting and a seemingly bad API choice by RIM, but then again you can just save the primitive data value. I guess since each of the object wrappers states they only contain a single field there is no need for the overhead of aFloat/Double object.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Is double persistable - API doesn't list it as such

Sometimes boxing a primitive in an object is useful. It's the only way, for instance, of delivering values through an Enumerator; you can use a null value to indicate "not initialized" (which might be very useful when persisting data); you can use it in a hash table or other object-oriented structure; etc.

 

RIM supplies IntVector, etc. to avoid the overhead of boxing, but only for a few primitive data types.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Highlighted
New Developer
Posts: 19
Registered: ‎03-06-2009
My Device: Bold

Re: Is double persistable - API doesn't list it as such

This may be redundant...  If you have a look at the Meeting.java file in the samples directory (Research In Motion\BlackBerry JDE 5.0.0\samples\com\rim\samples\device\persistentstoredemo\) you'll see this comment:

 

// Primitive data types can be persisted. The following class members are
// included for demonstration purposes only, they have no functional use in
// this class.
private int demoInt;
private boolean demoBool;
private byte demoByte;
private short demoShort;
private long demoLong;
private float demoFloat;
private double demoDouble;
private char demoChar;

 

 



There is no sex in your violence