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
Contributor
viviprost
Posts: 13
Registered: ‎02-18-2013
My Device: BOLD 9900

Persistent Storage

Hello,

 

I'm trying to persist the sample MessageListDemo and i'm answering me questions.

 

public static synchronized MessageListDemoStore getInstance()
    {
    	
    	_store = PersistentStore.getPersistentObject(PERSISTENT_STORE_DEMO_ID);
    	
    	synchronized(_store)
        {         
            if(_store.getContents() == null)
            {
                _store.setContents(new MessageListDemoStore());  
            }      
        }
    	
    	_instance = (MessageListDemoStore)_store.getContents(); 
    	_store.commit();

        return _instance;
    }

  MessageListDemoStore object _instance is persistable ?

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Persistent Storage

no.
you can check http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/util/Persistable.html for a list of classes that implement Persistable by default.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
viviprost
Posts: 13
Registered: ‎02-18-2013
My Device: BOLD 9900

Re: Persistent Storage

Ok thank you.

 

I tried that but it doesn't work.

 

public final class MessageListDemoStore extends Vector implements Persistable
{
     public static synchronized Vector getInstance()
    {
    	
    	_store =     PersistentStore.getPersistentObject(PERSISTENT_STORE_DEMO_ID);
    	
    	synchronized(_store)
        {         
            // If the PersistentObject is empty, initialize it
            if(_store.getContents() == null)
            {
                _store.setContents(new Vector());  
            }      
        }
    	
    	_instance = (Vector)_store.getContents(); 
    	_store.commit();

        return _instance;
    }

 

If i understand, here,  i store contents of my vector in a persistent Storage.

When i receive message i do a cast on _instance to MessageListDemoStore.

Like that i can use all members functions of my class.. it's good ?

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

Re: Persistent Storage

This is better I think:

 

public final class MessageListDemoStore extends Vector implements Persistable
{
     public static synchronized MessageListDemoStore getInstance()
    {
    	
    	_store =     PersistentStore.getPersistentObject(PERSISTENT_STORE_DEMO_ID);
    	
    	synchronized(_store)
        {         
            // If the PersistentObject is empty, initialize it
            if(_store.getContents() == null)
            {
                _store.setContents(new MessageListDemoStore());  
                _store.commit();
            }      
        }
    	
    	_instance = (MessageListDemoStore)_store.getContents(); 

        return _instance;
    }

 

 

 

 

 

Contributor
viviprost
Posts: 13
Registered: ‎02-18-2013
My Device: BOLD 9900

Re: Persistent Storage

Error message :

 

C:\Users\Demba\Desktop\eclipse\plugins\net.rim.ejde.componentpack7.0.0_7.0.0.33\components\bin\rapc.exe -convertpng -quiet codename=deliverables\Standard\7.0.0\MessageListDemo -sourceroot=C:\Users\Demba\workspace\MessageListDemo\src;C:\Users\Demba\workspace\MessageListDemo\res -import=C:\Users\Demba\Desktop\eclipse\plugins\net.rim.ejde.componentpack7.0.0_7.0.0.33\components\lib\net_rim_api.jar deliverables\Standard\7.0.0\MessageListDemo.rapc C:\Users\Demba\workspace\MessageListDemo\bin
com.rim.samples.device.messagelistdemo.MessageListDemoStore: Error!: Class com.rim.samples.device.messagelistdemo.MessageListDemoStore marked Persistable by interface: net.rim.device.api.util.Persistable is not Persistable: field _inboxMessages: Class com.rim.samples.device.messagelistdemo.MessageListDemoStore$ReadableListImpl does not implement net.rim.vm.Persistable
Packaging project MessageListDemo failed (took 5.42 seconds)

 

In the MessageListDemoStore there is an over class :

 

static class ReadableListImpl implements ReadableList
{
        private Vector messages;

        /**
         * Creates a empty instance of ReadableListImpl
         */
        ReadableListImpl()
        {
            messages = new Vector();
        }

    ...
}

Readable isn't a persistent class, but it is store in a Vector

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Persistent Storage

every class and subclass you want to store has to implement persistable.

with that in mind i would suggest that you think about a storage model before you try to implement something.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
viviprost
Posts: 13
Registered: ‎02-18-2013
My Device: BOLD 9900

Re: Persistent Storage

When you think about storage model, you think about an example of an persistant storage ?

 

When i use extends Vector implements Persistable there is an error :

 

C:\Users\Demba\Desktop\eclipse\plugins\net.rim.ejde.componentpack7.0.0_7.0.0.33\components\bin\rapc.exe -convertpng -quiet codename=deliverables\Standard\7.0.0\MessageListDemo -sourceroot=C:\Users\Demba\workspace\MessageListDemo\src;C:\Users\Demba\workspace\MessageListDemo\res -import=C:\Users\Demba\Desktop\eclipse\plugins\net.rim.ejde.componentpack7.0.0_7.0.0.33\components\lib\net_rim_api.jar deliverables\Standard\7.0.0\MessageListDemo.rapc C:\Users\Demba\workspace\MessageListDemo\bin
com.rim.samples.device.messagelistdemo.MessageListDemoStore: Error!: Class com.rim.samples.device.messagelistdemo.MessageListDemoStore marked Persistable by interface: net.rim.device.api.util.Persistable is not Persistable: field _mainFolder: Class net.rim.blackberry.api.messagelist.ApplicationMessageFolder does not implement net.rim.vm.Persistable
Packaging project MessageListDemo failed (took 6.537 seconds)

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Persistent Storage

you add elements that are not persistable, and the error message is quite clear about it.
ApplicationMessageFolder does not implement Persistable

store the important things, don't try to throw the whole class in if it is not needed.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
viviprost
Posts: 13
Registered: ‎02-18-2013
My Device: BOLD 9900

Re: Persistent Storage

Can i have more explication on the MessageListDemoDeamon please ?

 

public final class MessageListDemoDaemon extends Application implements ApplicationMessageFolderListener
{
    private static final String APPLICATION_NAME = "Message List Demo";


    /**
     * Called during device startup. Registers application descriptors, message
     * folder listeners, message icons and menu items.
     */
    void init()
    {
        // 1. Register folders and application descriptors ----------------------

        ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance();

        // Some context menu items don't need a GUI (e.g. an item for deleting a
        // message) and will be run in the current daemon application.
        ApplicationDescriptor daemonDescr = ApplicationDescriptor.currentApplicationDescriptor();

        // Main application descriptor - causes application to be launched with
        // default welcome screen if a user clicks on the "Message List Demo"
        // header in the home screen notifications view.
        ApplicationDescriptor mainDescr = new ApplicationDescriptor(daemonDescr, APPLICATION_NAME, new String[] {});

        // This application descriptor launches this application with a GUI to
        // execute listener callbacks, e.g. to display a message.
        ApplicationDescriptor uiCallbackDescr = new ApplicationDescriptor(daemonDescr, APPLICATION_NAME, new String[] {"gui"});

        // Get existing messages from storage and register them in folders        
        ApplicationFolderIntegrationConfig inboxIntegration = new ApplicationFolderIntegrationConfig(true, true, mainDescr);
        ApplicationFolderIntegrationConfig deletedIntegration = new ApplicationFolderIntegrationConfig(false);

        MessageListDemoStore messages = MessageListDemoStore.getInstance();
        ApplicationMessageFolder inbox = reg.registerFolder(MessageListDemo.INBOX_FOLDER_ID, "Inbox", messages.getInboxMessages(),
                        inboxIntegration);
        ApplicationMessageFolder deleted = reg.registerFolder(MessageListDemo.DELETED_FOLDER_ID, "Deleted Messages", messages.getDeletedMessages(), deletedIntegration);

        // Register as a listener for callback notifications
        inbox.addListener(this, ApplicationMessageFolderListener.MESSAGE_DELETED | ApplicationMessageFolderListener.MESSAGE_MARKED_OPENED
            | ApplicationMessageFolderListener.MESSAGE_MARKED_UNOPENED | ApplicationMessageFolderListener.MESSAGES_MARKED_OLD, daemonDescr);
            deleted.addListener(this, ApplicationMessageFolderListener.MESSAGE_DELETED, daemonDescr);

        messages.setFolders(inbox, deleted);

        // We've registered two folders, specify root folder name for the
        // [View Folder] screen.
        reg.setRootFolderName(APPLICATION_NAME);

        // 2. Register message icons -------------------------------------------

        ApplicationIcon newIcon = new ApplicationIcon(EncodedImage.getEncodedImageResource("img/new.png"));
        ApplicationIcon readIcon = new ApplicationIcon(EncodedImage.getEncodedImageResource("img/read.png"));
        ApplicationIcon repliedIcon = new ApplicationIcon(EncodedImage.getEncodedImageResource("img/replied.png"));
        ApplicationIcon deletedIcon = new ApplicationIcon(EncodedImage.getEncodedImageResource("img/deleted.png"));

        reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_NEW, newIcon);
        reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_OPENED, readIcon);
        reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_REPLIED, repliedIcon);
        reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_DELETED, deletedIcon);

        // 3. Register message menu items --------------------------------------

        ApplicationMenuItem openMenuItem = new OpenContextMenu(0x230010);
        ApplicationMenuItem replyMenuItem = new ReplyContextMenu(0x230020);
        ApplicationMenuItem markOpenedMenuItem = new MarkOpenedContextMenu(0x230030);
        ApplicationMenuItem markUnopenedMenuItem = new MarkUnreadContextMenu(0x230040);

        ApplicationMenuItem[] newGuiMenuItems = new ApplicationMenuItem[] {openMenuItem};
        ApplicationMenuItem[] newDaemonMenuItems = new ApplicationMenuItem[] {markOpenedMenuItem, replyMenuItem};
        ApplicationMenuItem[] openedGuiMenuItems = new ApplicationMenuItem[] {openMenuItem};
        ApplicationMenuItem[] openedDaemonMenuItems = new ApplicationMenuItem[] {markUnopenedMenuItem, replyMenuItem};
        ApplicationMenuItem[] repliedGuiMenuItems = new ApplicationMenuItem[] {openMenuItem};
        ApplicationMenuItem[] repliedDaemonMenuItems = new ApplicationMenuItem[] {markUnopenedMenuItem};
        ApplicationMenuItem[] deletedGuiMenuItems = new ApplicationMenuItem[] {openMenuItem,};

        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_NEW, newGuiMenuItems, uiCallbackDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_NEW, newDaemonMenuItems, daemonDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_OPENED, openedGuiMenuItems, uiCallbackDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_OPENED, openedDaemonMenuItems, daemonDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_REPLIED, repliedGuiMenuItems, uiCallbackDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_REPLIED, repliedDaemonMenuItems, daemonDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_DELETED, deletedGuiMenuItems, uiCallbackDescr);

        reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_MESSAGE_TYPE,       MessageListDemo.STATUS_NEW, true, false);
        reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_OPENED, false, true);
        reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_MESSAGE_TYPE, MessageListDemo.STATUS_REPLIED, false, true);
    }

 This is important to modify this class for persistent storage ?

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Persistent Storage

you will NOT be able to persist this class. Never. No. Not possible.
And there is absolutely no reason to persist it either.
You can persist messages and add them to the message folder on startup, for example.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter