Storing persistent data

Lab,Persistent and Runtime Store,Storing Data

Exercise

 

Write an application that stores and uses persistent data.

 

Objectives

  • Discover how to store data for an application.
  • Discover how to create objects that can persist.
  • Discover how to save and retrieve data.

Setup

  1. Extract music_stores_incomplete.zip
  2. In the IDE, open the music_stores.jdw workspace
  3. Open the MusicStores.java source file.

Tasks

  1. In the static initializer, retrieve a reference to a PersistentObject using the store variable.
  2. In the synchronized block, if the PersistentObject is empty, set its contents to a new Vector.
  3. Retrieve PersistentObject contents and store it in a Vector.
    TIP: Use the _data variable already defined.
  4. Add code to the StoreInfo inner class to define an object that can persist. TIP: Each object stores information about one music store.
  5. Add code to saveItem to create a Save menu item that saves the music store information that users have entered.
  6. Add code to getItem to create a Get menu item that retrieves and displays data from the last music store that was added.

Check Your Work

 

(from music_store_complete.zip)

Review

 

In this exercise, you discovered the following things:

  • how to create a data storage area for an application
  • how to create a new type of object that can persist
  • how to retrieve data from a persistent data store
  • how to add data to a persistent data store