Retrieve multiple attribute values from an Mbo

This entry is part of the Maximo Java Development series.

Maximo MBOs are not exactly lightweight, however there are some little tricks to improve performances and reduce system resources consumption.
One of the most common mistakes that I have seen is the redundant use of getters methods of the psdi.mbo.Mbo class.
In the following example three calls to getString/getInt methods are made to retrieve the attribute values from an Mbo object.

MboSetRemote mboset = getMboSet("ASSET");
MboRemote asset = mboset.getMbo(0);

String assetnum = asset.getString("ASSETNUM");
String assetdesc = asset.getString("DESCRIPTION");
int assetPriority = asset.getInt("PRIORITY");
Rather than retrieving data from attributes individually you can use the getMboValueData(String[]) method to retrieve several attributes in a single call.
String[] attrs = { "ASSETNUM", "DESCRIPTION", "PRIORITY" };

MboSetRemote mboset = getMboSet("ASSET");
MboRemote asset = mboset.getMbo(0);

MboValueData[] valData = asset.getMboValueData(attrs);
String assetnum = valData[0].getData();
String assetdesc = valData[1].getData();
int assetPriority = valData[2].getDataAsInt();

This implementation is more efficient because it makes only one remote call to the server instead of three.

Going one step further, it is possible to apply the same approach on the MboSet. In the following snippet the three attributes are retrieved in one call for the first 10 rows of the MboSet.
String[] attrs = { "ASSETNUM", "DESCRIPTION", "PRIORITY" };
MboSetRemote mboset = getMboSet("ASSET");

MboValueData[][] valData = mboset.getMboValueData(0, 10, attrs);
String assetnum0 = valData[0][0].getData();
String assetdesc0 = valData[0][1].getData();
int assetPriority0 = valData[0][2].getDataAsInt();
String assetnum1 = valData[1][0].getData();
...
The first parameter of getMboValueData method is the starting position of the required Mbo in the MboSet. The second parameter is the number of Mbos required. Passing MboConstants.ALLROWS the entire MboSet is retrieved.

Labels: , , ,