XEO API – Loading, Listing and Iterating


Today I’d like to showcase a bit of XEO’s API to load, list and iterate instances of XEOModels, which are really basic activities while using the API, so let’s get started:

Loading an instance

You have the following choices when loading an instance

EboContext ctx = boApplication.currentContext().getEboContext();

//Load a specific BOUI, bypasses securities
boObject.getBoManager().loadObject(ctx, "1234"); 
//Load a specific BOUI, respect securities
//Load using a BOQL Query (query must return a single result)
boObject.getBoManager().loadObject(ctx, "select Example where name = ?",new Objct[]{"name"});
//Load using the BOUI with the ObjectManager
boApplication.getDefaultApplication().getObjectManager().loadObject(ctx, boui);
//Instantiate the ManagerBean and load the object
new boManagerBean().loadObject(ctx, boui);

Be aware that usually there are two paths when loading a boObject. Using the SecurityManager (which respects security policies) and the normal Manager (which bypasses security)

For listing you can do the following:

EboContext ctx = boApplication.currentContext().getEboContext();

//Select without arguments
boObjectList.list(ctx, "select Example");
//Select with arguments
boObjectList.list(ctx, "select Example where name = ?", new Object[]{"name"});
//Select with multiple options
boObjectList.list(ctx, boql, args, page, pageSize, orderBy, fullText, letter_filter, userQuery, useSecurity, useCache);
//Select using a Builder
new boObjectListBuilder(ctx, "select Example where name = ? and other = ?").argsList("arg1","arg2").cache(false).pageSize(3).build();
//Use the builder without the new
boObjectList.builder("select Example where name = ?").arg("name").build();

Listing functions also have a parameter to apply security policies or not.

In case you want to iterate a list you do the following.

boObjectList list = boObjectList.list(ctx, "select Example");
while (list.next()){
	boObject current = list.getObject();

In case you want to iterate a collection attribute, do one of the following

bridgeHandler bridge = obj.getBridge("collection"); 
//Using a bridge handler directly
while (bridge.next()){
	boObject current = bridge.getObject();

//Using an "iterator"		
boBridgeIterator it = bridge.iterator();
while (it.next()){
	boObject current = it.currentRow().getObject();

That will be all, happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *