|
This page contains information on how to use and exploit the MaxBase bean. To know how to add a MaxBase bean into your projects
under IBM VisualAge for Java click here. Use of the MaxBase class with plain Jdk What you can do with the MaxBase Bean
Several methods to control MaxBase are available: Constructors: nrio.MaxBase MaxBase() This is the most basic type of constructor for MaxBase. The MaxBase java.awt.Frame is kept invisible (you can make it visible by issueing .setVisible(1) as with any other Frame) and no database gets loaded. nrio.MaxBase MaxBase(MBAParam m) This constructor is used when MaxBase is called by an applet. See the section devoted to applets to see how to fill the MBAParam object. Using this constructor, MaxBase is put on the foreground after initialization. nrio.MaxBase MaxBase(String DbName, String[] resources, LPInterface LP, AMInterface AM) This is the most complete constructor for MaxBase. Using it, MaxBase is put on the foreground after initialization. The parameters are: String DbName
... Name of the database to be loaded. It can be a plain file name
(ending with the .dat extension) or an URL in the form:
mbase://host.domain:port(password)
or mbase://host.domain:port
. Of course the latter is
used when no password is needed on the server. Methods: First of all, please remember that MaxBase is an object of type java.awt.Frame, therefore you can use any of the methods available for that object. In addition to the methods typical for java.awt.Frame, you can use the following ones: String[][] dbinfo() with this method you can retrieve information about fields of a MaxBase instance. The returned values are in the following form: |
||||
[0, 0] is the number of fields which are being passed. |
|||||
[i, 0] max. length of the "i"-th field. |
|||||
[i, 1] name of the "i"-th field. |
|||||
[i, 2] indexing of the "i"-th field. |
|||||
String deleRec(String[] sToDele, boolean bDelete) Delerec is used to delete/undelete one or more records. sToDele[0] has to be
the total number of records to be (un)deleted, and sToDele[n] is
the ACTUAL position of the n-th record to be (un)deleted on the
database (NOT A NUMBER RELATIVE TO AN INDEX). void deselectAll() This method deselects all the records on screen (if there are any selected, of course). void disconnect() This method disconnects from the currently in use database (if any). String[][] loadRecWithFilter(String sIdx, String sHowManyRec, String sStart, boolean bForward, String sFilt) This method lets you do a query on a MaxBase instance (like a SELECT statement with SQL). The parameters mean: sIdx is the index on which you want the returned records to be ordered. sHowManyRec is the maximum number of the records that you want returned. This value can be numeric (a String representing a number, like '190', or the keyword "ALL" if you want all of them). sStart is the record from which to start loading records. Valid values can be numeric or you can use the "LAST" keyword -- which means "start from the last record in the archive". bForward can be true or false, and indicates that you want to retrieve the record going forward or backward. sFilt is the filter to be used. String[][] peekSelected() This method returns information about the selected records in a MaxBase instance. The returned values are: |
|||||
|
|||||
void refreshView() Use this method to force the refresh of the current view (showed records in a MaxBase instance). void selectAll() This method selects all the records currently loaded (if there are any, of course). void shutDown() This method saves any db-related setting for MaxBase (if allowed, eg. If the db is in the local hard disk). By default, MaxBase doesn't do this on program exit if it's been instantiated by an external object. Several useful properties are readable/writeable. Most of them (externalAddModi, PluginFactory, LPParent) are there to let MaxBase know which are the other classes that will interact with it, and so they are to be used primarily in write mode. activeDB is a MaxBase property (String); it is used to make MaxBase connect to a database. The string can be a plain file name (ending with the .dat extension) or an URL in the form: mbase://host.domain:port(password) or mbase://host.domain:port . Of course the latter is used when no password is needed on the server. Note: If you change the value of this property and MaxBase is already accessing a database, the currently being accessed db will be closed, and the new one opened. The methods used to access activeDB are the following: String getActiveDB(void); Read more about externalAddModi, the interface that lets you use your own add & modify panels, here. MBFilter is another MaxBase (String) property; it is used to force a filter in a MaxBase instance. Set MBFilter with the very same strings you would use to set filters from inside MaxBase. The methods used to access MBFilter are the following: String getMBFilter(void); LPParent is a MaxBase property that defines an object of type nrio.LPInterface, which is an interface that must implement the following method: String[][] processRequest(String sCommand, String sDBSource, String sDBTarget) This interface is here only to set a standard way of passing requests among instances of MaxBase. Note that, unlike externalAddModi, this is here only for your convenience -- MaxBase itself will not use this property. What use does it have? If the object that creates a MaxBase instance (could be an applet, a program, or simply another class) implements this interface, you will be able to use it as a "dispatching center" for multi-db operations. Let's suppose you want to use some fields of a database in another one, e.g. supplier names in an item database. You would, most probably, let the user choose from a list of suppliers instead of having him/her enter a name by hand, so you can ask (from inside the add/modify panel of the items database) the object represented by LPParent to send requests to the suppliers database ("send all suppliers' names"). Normally there will be an object implementing LPInterface and launching several instances of MaxBase (like the "mimages: prototipo" window in the above example -- but it needs not to be visible, of course) and serving the cross-database requests of these MaxBase instances. Using this technique is not compulsory, of course, and you can choose to implement your own way to make more DBs communicate. The methods used to access LPParent are the following: nrio.LPInterface getLPParent(void); Another option is to pass the LPInterface parameter when you create the MaxBase instance with the following constructor: MaxBase(String DbName, String[] resources, LPInterface LP, AMInterface AM) PluginFactory is a MaxBase property which represents an object of type nrio.MBPlugin (nrio.MBPlugin is an interface); it is used to add features to MaxBase. Let's see how. You must implement somewhere (in the applet, program or whatever else is controlling the MaxBase instance(s)) the nrio.MBPlugin interface, and this means implementing the following methods: void pluginLaunch(String
sTextLabel) After you instantiate MaxBase, you set the PluginFactory property of MaxBase making it point to the controlling program/applet/class, like this: myMBInstance.setPluginFactory(MBPlugin this); from there on, before MaxBase displays a panel to the user it asks your program to provide (if there are any) the strings containing the text labels for the buttons to be added. It does this by calling your program's sendMenu method, passing the name of the panel that's going to be displayed as a parameter. Here is a listing of the names used to identify the panels: addfield Example: the user selects the "data.." button in the main MaxBase panel, so MaxBase calls your program's sendMenu method using as a parameter the string "data". If your program wants to add one or more buttons to that panel, it must return the string array containing the names, else the null value. If the user presses one of your buttons, your program gets notified via the pluginLaunch method, passing as a parameter the text (label) of the button pressed. So, say that the user presses the "e-mail them" button (that you provided via sendMenu as described above), MaxBase calls your program's pluginLaunch method with parameter "e-mail them", and your program can do whatever it wants (it could, for example, call MaxBase's peekSelected() method to ask for the selected records, and then send an e-mail to the people represented by the records). Since this technique doesn't rely on external .ini files as the user-defined plugins, it works everywhere, even in a browser (browser Java problems allowing, of course :-)). resources is a MaxBase property that lets you specify the text properties for the MaxBase instance. The usual comment apply: using "-" as a button label disables that button. The method used to access resources is the following: void setResources(java.lang.String[] res); Another option is to pass the resource parameter when you create the MaxBase instance with the following constructor: MaxBase(String DbName, String[] resources, LPInterface LP, AMInterface AM) NOTE: You must provide all of the resources in an indexed array; you can build the resources using a method like the following in your programs. Click here to get the (Java) listing of the prepareResources method. |
Max
Marsiglietti © 1997
Layout and
artwork Andrea Resmini 1997