Liferay ServiceBuilder concepts and anatomy-part2

In the previous tutorial, we have gone through service builder and its component. In this we will talk about below  generated classes and its relationships:

  • service.xml components
  • Modal Classes
  • Service Classes
  • Persistence Classes
  • Spring and Hibernate configuration

Modal Layer:

  •  –  This is interface modal class and will be used to on JSP’s and controller
  • – All you helper methods on this POJO will go in this class. Run the Service builder again after adding methods to this pojo
  • LeaveModalImpl – The base model implementation for the Leave service. Represents a row in the “js_Leave” database table, with
    each column mapped to a property of this class. This implementation and its corresponding interface org.javasavvy.system.model.LeaveModel exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in LeaveImpl.
  • How to create and update entity to database in liferay:
    •   long entryId  = CounterLocalServiceUtil.increment(Leave.class.getName()); // Counter Local service util is used to provide PK
        Leave leave = leavePersistence.create(counterLocalService.increment(Leave.class.getName())); 
        Leave leave = LeaveLocalServiceUtil.create(counterLocalService.increment(Leave.class.getName()));


Service Layer:

This is Data Transfer Layer and generates all below classes.

  • LeaveLocalServiceImpl:  Place all your custom implementation In this

  • LeaveLocalServiceUtil: As shown in diagram, Liferay Service builder generated and customer methods will be accessible via Util class. User LeaveLocalServiceUtil class in JSP pages, Controllers and other external plugin modules.

If you set remote service to true then it generates below classes:

  • LeaveServiceImpl
  • LeaveServiceUtil :


Persistence Layer:

LeavePersistenceImpl: Service Builder generates LeavePersistenceImpl that holds all finder configurations and all. Never modify this class, if you require custom SQL then write custom SQL and finder classes. this tutorial will cover in next .

Spring Configuration:
  • base-spring.xml
  • cluster-spring.xml
  • hibernate-spring.xml
  • infrastructure-spring.xml   – Holds Datasource Spring bean
  • portlet-hbm.xml  –
  • portlet-model-hints.xml – This xml file is used to increase column length and other config
  • portlet-orm.xml –  This file holds database column mapping to LeaveModalImpl class
  • portlet-spring.xml
  • shard-data-source-spring.xml

you can overwrite default datasource, transaction manger by creating new file “ext-spring.xml”  and place all configuration.

4 thoughts on “Liferay ServiceBuilder concepts and anatomy-part2”

Comments are closed.