Wiki

Clone wiki

XALPI / Home

Welcome to the XALPI Wiki

XALPI stands for XEO Alternative API and is an attempt to provide a different API to interact with XEO Model Instances in an XEO Application, specifically it attempts to:

  • Provide a more convenient API
  • Provide the means to allow unit testing of business logic

Notice: XALPI is not associated with the XEO Framework.

XALPI Features

An example, lets imagine a Car XEOModel (and ModelBrand and Color XEO Model) with the following specification

Car
  model : String
  year : Number
  type : String (Lov - LovType)
  brand : ModelBrand
  colors : Color (collection)

ModelBrand
   name : String

Color
   colorName : String

LovType
    0 - NORMAL
    1 - PREMIUM

How do I use XALPI?

Download the XALPI binary and extract it to the project's root and run the xalpi.xml using ant (directly within Eclipse). The xalpi.xml ant can be used as is, but you can edit the following properties:

  • models-src (Where to find the compiled XEOModels, defaults to .build\bodef-deployment)
  • models-destiny (Where to create the models, defaults to .build\xalpi)
  • models-package (This you may want to edit, the package where your classes will be created, defaults to com.corrspt.models)
  • useInheritance (Whether or not the interfaces generated should extend from one another when XEO Models extends from one another. If set to true interfaces will use extension, if set to false each interface will have its own hierarchy - defaults to false, see known issues)

How does it work?

XALPI generates a .jar archive with the generated classes and interfaces and places it in the base_lib/modules directory of your XEO Application. If you change the models, run the xalpi.xml ant file again and everything will be regenerated.

Known Issues

  • You cannot have Lovs with the old format, if you have Lovs in the old format convert them to the new format using the XEO Studio (expand the Lov in the XEO Navigator view)
  • If you use the useInheritance parameter you cannot have XEO Models that extend other XEO Models and redefine an object relation to return a different type of object - Example. Model A has a relation to Model B through atribute myAttribute. Model C cannot extend from Model A and redefine myAttribute to be a relation with Model D.

Old API Example

#!java

//Load an Object
long boui = 1000; // Boui to load from somewhere
EboContext ctx = boApplication.currentContext().getEboContext();
boObject car = boObject.getBoManager().loadObject(ctx, boui);

//Get / Set Attribute
try{
  car.getAttribute("name").setValueString("newName")
  String name = car.getAttribute("name").getValueString("newName")

  car.getAttribute("type").setValueString("0");
  String value = car.getAttribute("type").getValueString();

  boObject modelBrand = car.getAttribute("brand").getObject();
} catch (boRuntimeException e)
{
   e.printStackTrace();
}

//Create Object Lists
EboContext ctx = boApplication.currentContext().getEboContext();
boObjectList list = boObjectList.list(ctx,"select Car where brand = ?", new Object[]{boui});


//Iterate a bridge
bridgeHandler handler = car.getBridge("colors");
boBridgeIterator it = handler.iterator();
while (it.next()){
   boObject currentColor = it.currentRow().getObject();
}

XALPI Example

#!java

public interface Car extends BaseModel{

  public String getName();
  public void setName(String newName);

  public Long getYear();
  public void setYear(Long newYear);

  public LovType getType();
  public void setType(LovType newType);

  public ModelBrand getBrand();
  public void setBrand(ModelBrand newBrand);

  public ColorCollection getColors();

}

//Load/Create an Object
long boui = 1000;
Car car = CarManager.load(boui);
Car newCar  CarManager.create();

//Get / Set Attribute
car.setName("newName");
String name = car.getName();

LovType type = car.getType();
car.setType(LovType.PREMIUM);

ModelBrand brand = car.getBrand();


//Create Object Lists
CarList list = select.Car().where("brand = ?").args(brand).build();

//Iterator a bridge
ColorCollection colors = car.getColors();
Iterator<Color> it = colors.iterator();
while (it.hasNext()){
   Color currentColor = it.next();
}

Why does every interface extends from BaseModel?

The BaseModel interface represents the common attributes and operations for every XEOModel instance (like update/destroy and checking if an instance isDisabled ou exists) You can check the BaseModel javadoc here.

Creating Unit Tests with XALPI

Check the creating Unit Tests Page

Creating / Loading Instances

To check more about a manager class, check here

Roadmap

Check the Roadmap here

Happy coding! If you find an issue report in the issues page.

Updated