Wiki

Clone wiki

XALPI / ListOfObjects

Creating Lists of Objects is a very frequent operation, thus it demanded a special treatment. Being fan of the Wizard and Builder patterns I decided to apply those patterns to list creation:

Every time you generate the classes from your XEO Models a special Select class is created. This class is your main entry point for creating lists of objects. Using the Car example, from the main page, you could to the following variants:

#!java

//Select All Cars
CarList cars = Select.Car().build();

//Select All Cars with where condition without arguments
CarList cars = Select.Car().where("name = 'SLK'").build();

//Select All Cars with where condition and arguments
CarList cars = Select.Car().where("name = ?").args("SLK").build();

//Select All Cars with where condition and arguments and options (dont use cache and use security)
CarList cars = Select.Car().where("name = ? and year = ?").args("Mercedes",2009).dontCache().useSecurity().build();

Arguments in args(Object... args) BOUI vs Instance

If you want to execute following query "select Cars where brand equals to Mercedes" in the old API you have to do the following:

#!java
EboContext ctx = boApplication.currentContext().getEboContext();
boObject mercedesObj = boObject.getBoManager().loadObject(ctx,1000);
boObjectList list = boObjectList.list(ctx, "select Car where brand = ?", new Object[]{mercedesObj.getBoui()});
With XALPI you can do the following:

#!java
ModelBrand mercedes = ModelBrandManager.load(1000);
CarList cars = Select.Car().where("brand = ?").args(mercedes).build();
No need to pass on the BOUI of the instance, just pass the instance itself as an argument

Updated