Saving Objects

In an HTML-client application, the thin presentation beans work with the Save As dialog and the Save Confirmation dialog to save object to the BI Beans Catalog. In a Java-client application or applet, you can use the Persistence Object Chooser to get information from a user about where and what to save, but you must write code to save the object to the Catalog.

Objects that you save to the BI Beans Catalog must implement the Persistable interface.

To save an object for the first time, you call the bind method, passing the object and the name that you want to give the saved object. The bind method binds the name to the object, making it possible to retrieve the object later.

If an object is already saved, then it has already been bound to a name. To save an object that is already in the BI Beans Catalog, you do not call bind.

If the object has not already been saved, then rebind binds the name to the object, just as bind does. You can call rebind to save an object, whether or not it has been saved before.

To save an object to the BI Beans Catalog, you call the bind or rebind method of the BIContext into which you want to store the object. It does not have to be the immediate context. You can save an object into the subcontext of the context whose method you call.

Examples: Saving a graph

The following code saves a bar graph (MySalesBarGraph) in a folder named MyGraphsFolder. The graph has not already been saved in the folder.


// ctxMyGraphsFolder is the PersistenceManager or the MDObject // for MyGraphsFolder // grSalesBarGraph is a bar graph; implements Persistable interface try{    // rebind works whether "MySalesBarGraph" is bound already or not    ctxMyGraphsFolder.rebind("MySalesBarGraph", grSalesBarGraph); } catch(NamingException ne){   ne.printStackTrace(); }

You can save an object to a subcontext of the PersistenceManager whose rebind method you call. The following call saves a graph (mySalesGraph) under the name SalesGraph, in a MyGraphs folder, which is a subfolder of a folder named MyFolder.


//create pmMyGraphs BIContext ctxMyGraphs = null; try {   ctxMyGraphs = (PersistenceManager)ctxMyFolder.createSubcontext("MyGraphs"); } catch (NamingException ne){   ne.printStackTrace(); } try {    //bind from pmMyFolder to show how to specify a path    ctxMyFolder.rebind("MyGraphs/SalesGraph", mySalesGraph); } catch (NamingException ne){   ne.printStackTrace(); }