Saturday, 2 December 2017

Jalo Layer

Jalo Layer offers an API to clients and abstracts from the database. It covers two major aspects:
  • Data Model, which you can define in the items.xml files in the form of types and attributes.
  • Business Logic, which you implement in Java classes.

For each type defined in the items.xml file, the Build Framework generates two Java files:
  • Abstract Java class: Automatically generated by the Build Framework and generated again on every build. Abstract Java classes contain automatically-generated getter and setter methods for the defined type attributes in the items.xml file.
  • Non-Abstract Java class: Extends from the abstract Java class. Non-Abstract Java classes are only generated by the Build Framework if they are non-existent. Non-Abstract Java classes are not overwritten during builds.

Jalo Layer is a tight coupling between data model and business logic, as the implemented business logic in Java classes that are generated are based on the data model. If the data model changes, your business logic might need adaption as well. For example, if you rename a type, the Java classes have to be renamed too. 

You can implement Java classes that are not backed by the data model, but the instances are runtime objects only and are not persistent. An example for such non-persistent Java classes is the JaloSession.

Using the Jalo Layer

The basic workflow of using the Jalo layer is as follows:
  • Define your data model in terms of types and attributes using the items.xml file.
<itemtype code="MyType" autocreate="true" generate="true"  jaloclass="de.hybris.jalolayer.sample.MyType">
<attributes> <attribute type="java.lang.String" qualifier="MyAttribute"> <persistence type="property" /> </attribute> </attributes></itemtype>
  • Build SAP Hybris Commerce to have the Java classes generated.
    • gensrc/de/hybris/jalolayer/sample/GeneratedMyType.java
      • Abstract Java class, containing getter and setter methods for MyAttribute such as:
        • public String getMyAttribute(final SessionContext ctx)
        • public String getMyAttribute()
        • public void setMyAttribute(final SessionContext ctx, final String value)
        • public void setMyAttribute(final String value)
    • src/de/hybris/jalolayer/sample/MyType.java
      • Non-abstract Java class extending GeneratedMyType. 
  • Implement business logic in the non-abstract Java class.
    • In MyType.java, you can implement your business logic and optionally override the getter and setter methods for MyAttribute if you need special business logic for that.

No comments:

Post a Comment