May 26, 2012

Understanding Mbos and MboSets

This entry is part of the Maximo Java Development series.

Maximo Business Objects (MBOs) are a set of Java classes that implements the data persistence layer and business rules in Maximo/TPAE infrastructure. Those Java class files are stored in the [SMPDIR]\maximo\applications\maximo\businessobjects directory and are packaged in the businessobjects.jar file.
Roughly speaking there are two types of objects Mbo and MboSet.
  • An Mbo represents a record in a table. It has business intelligence and persistence methods. It can be compared to a session/entity bean in J2EE.
  • An MboSet is a collection of Mbo objects. It has methods to manipulate, iterate and query data.


To access data (Mbo) you first have to access the table (MboSet). The following example shows how to retrieve all the assets located in BEDFORD site.

MboSetRemote assetSet = getMboSet("ASSET");
assetSet.setWhere("LOCATION='BEDFORD'");
MboRemote asset=null;
for(int i=0; (asset=assetSet.getMbo(i))!=null; i++)
{
    ...
}

  • The getMboSet method gets a reference the ASSET table.
  • The setWhere method specifies the SQL where clause that must be applied to filter data. If the setWhere is not invoked, the entire table will be fetched.
  • The getMbo method returns a specific element of the MboSet collection. The first invocation of getMbo method automatically fetches data and initialize the MboSet.

Now that you have an Mbo object it is possible to read field values using the getXxxx methods.

String assetnum = asset.getString("ASSETNUM");
int assetid = asset.getInt("ASSETID");

To modify the value of a field the setValue methods can be used.

asset.setValue("DESCRIPTION", "New description");

In the previous examples we have used the basic psdi.mbo.Mbo and psdi.mbo.MboSet classes. However many Maximo objects have a specific handler class that is specified in the Class field of the object definition in the Database Configuration application. For the ASSET object it is psdi.app.asset.AssetSet and it extends psdi.mbo.MboSet class. Associated to psdi.app.asset.AssetSet there is psdi.app.asset.Asset that extends psdi.mbo.Mbo class. Those two specialized classes provides specific methods and logic to manage assets.
The following code snippet shows how to fetch an asset from Maximo database and understand if it is a rotating asset or not using the isRotating() method.

AssetSetRemote assetSet = (AssetSetRemote)getMboSet("ASSET");
assetSet.setWhere("ASSETNUM='1000'");
AssetRemote asset = (AssetRemote)assetSet.getMbo(0);
System.out.println("Is rotating: " + asset.isRotating());

You have just walked the first step in the long journey of the Maximo/TPAE developer...
For more articles look at Maximo MBO Java Development page.

7 comments:

  1. Really healpful for people who were starting there career in maximo

    ReplyDelete
  2. Hi Bruno,

    I need to compare two fields ( both belongs to the different object in db2 ) and out of which one field belongs to the incident object and second belongs to the different object and if it's equal then we need to set some value ? What will be the best way to achieve this task ? Is it possible through the Java codes ?

    Thanks in Advance

    ReplyDelete
    Replies
    1. Yes, it is feasible with Java. Look at his post: http://maximodev.blogspot.com/2012/09/navigate-object-relationship-in-mbo-code.html

      I think it can also be done with some scripting if you are on 7.5.

      Delete
    2. Thanks Bruno...:) It seems script will not work for us. we are using TSRM 7.2.1 . You made all the thing very easy for the beginners...:) Super Awesome..:)

      Delete
  3. Excellent article. Simple and well written. Thanks a lot.

    ReplyDelete