MetaData and Object Manager API

Some applications or frameworks can operate against MBOs generically by invoking MBO operations without prior knowledge of MBO classes. This can be achieved by using the MetaData and Object Manager APIs.

These APIs allow retrieving the metadata of packages, MBOs, attributes, operations and parameters during runtime. The APIs are especially useful for a runtime environment without a reflection mechanism such as J2ME.

You can generate metadata classes using the –md code generation option. You can use the –rm option to generate the object manager class.

The following code synchronizes and retrieves MBO data:

<PkgName>DB.loginToSync(“username”, “password”);
<PkgName>DB.synchronize();
Customer cust = Customer.findById(123);

The following code gets the same result by using the reflection mechanism:

ObjectManager om = new <PkgName>DB_RM();
DatabaseMetaData dbmd = <PkgName>DB.getMetaData();
ObjectList params = new ObjectList(2);
params.add("username");
params.add("password");
om.invoke(dbmd, dbmd.getOperation("loginToSync"), params);
om.invoke(dbmd, dbmd.getOperation("synchronize"), null);
ObjectList syncParams = new ObjectList(1);
syncParams.add("default");
om.invoke(dbmd, dbmd.getOperation("synchronize",new 
String[] {"string"}),syncParams);