Service Builder generates code
to support your entities. The files listed under Local Service and Remote
Service below are only generated for an entity that has both
remote-service attributes set to
true. Service Builder generates services
for these entities in your application’s
*-service modules in the
packages you specified in
service.xml. For example, here are the package
paths for Liferay’s Bookmarks application:
bookmarks-api module’s interfaces define the Bookmarks application API.
*-api module interfaces define the application’s persistence layer,
service layer, and model layer. Whenever you compile and deploy the
module, all its classes and interfaces are packaged in a
.jar file called
PROJECT_NAME-api.jar in the module’s
build/libs folder. Deploying this JAR
to Liferay defines the API as OSGi services.
bookmarks-service module classes implement the
*-service module provides the OSGi service implementations to
deploy to Liferay’s OSGi framework.
Next, examine the classes and interfaces generated for the entities you
specified. Similar classes are generated for each entity, depending on how each
entity is specified in the
service.xml. Here are the three types of
* represents the entity name in the classes listed above.
Here are the persistence, service, and model classes:
[ENTITY_NAME]Persistence: Persistence interface that defines CRUD methods for the entity such as
[ENTITY_NAME]PersistenceImpl: Persistence implementation class that implements
[ENTITY_NAME]Util: Persistence utility class that wraps
[ENTITY_NAME]PersistenceImpland provides direct access to the database for CRUD operations. This utility should only be used by the service layer; in your portlet classes, use the
[ENTITY_NAME]class by referencing it with the
Local Service (generated for an entity only if the entity’s
local-serviceattribute is set to
[ENTITY_NAME]LocalService: Local service interface.
[ENTITY_NAME]LocalServiceImpl(LOCAL SERVICE IMPLEMENTATION): Local service implementation. This is the only class in the local service that you should modify manually. You can add custom business logic here. For any methods added here, Service Builder adds corresponding methods to the
[ENTITY_NAME]LocalServiceinterface the next time you run it.
[ENTITY_NAME]LocalServiceBaseImpl: Local service base implementation. This is an abstract class. Service Builder injects a number of instances of various service and persistence classes into this class.
[ENTITY_NAME]LocalServiceUtil: Local service utility class which wraps
[ENTITY_NAME]LocalServiceImpl. This class is generated for backwards compatibility purposes only. Use the
*LocalServiceclass by referencing it with the
[ENTITY_NAME]LocalServiceWrapper: Local service wrapper which implements
[ENTITY_NAME]LocalService. This class is designed to be extended and it lets you customize the entity’s local services.
Remote Service (generated for an entity only if an entity’s
remote-serviceattribute is not set to
[ENTITY_NAME]Service: Remote service interface.
[ENTITY_NAME]ServiceImpl(REMOTE SERVICE IMPLEMENTATION): Remote service implementation. This is the only class in the remote service that you should modify manually. Here, you can write code that adds additional security checks and invokes the local services. For any custom methods added here, Service Builder adds corresponding methods to the
[ENTITY_NAME]Serviceinterface the next time you run it.
[ENTITY_NAME]ServiceBaseImpl: Remote service base implementation. This is an abstract class.
[ENTITY_NAME]ServiceUtil: Remote service utility class which wraps
[ENTITY_NAME]ServiceImpl. This class is generated for backwards compatibility purposes only. Use the
*Serviceclass by referencing it with the
[ENTITY_NAME]ServiceWrapper: Remote service wrapper which implements
[ENTITY_NAME]Service. This class is designed to be extended and it lets you customize the entity’s remote services.
[ENTITY_NAME]ServiceSoap: SOAP utility which the remote
[ENTITY_NAME]ServiceUtilremote service utility can access.
[ENTITY_NAME]Soap: SOAP model, similar to
[ENTITY_NAME]Soapis serializable; it does not implement
[ENTITY_NAME]Model: Base model interface. This interface and its
[ENTITY_NAME]ModelImplimplementation serve only as a container for the default property accessors Service Builder generates. Any helper methods and all application logic should be added to
[ENTITY_NAME]ModelImpl: Base model implementation.
[ENTITY_NAME]model interface which extends
[ENTITY_NAME]Impl: (MODEL IMPLEMENTATION) Model implementation. You can use this class to add helper methods and application logic to your model. If you don’t add any helper methods or application logic, only the auto-generated field getters and setters are available. Whenever you add custom methods to this class, Service Builder adds corresponding methods to the
[ENTITY_NAME]interface the next time you run it.
[ENTITY_NAME]Wrapper: Wrapper, wraps
[ENTITY_NAME]. This class is designed to be extended and it lets you customize the entity.
Each file that Service Builder generates is assembled from an associated
FreeMarker template. The FreeMarker templates are in the
/com/liferay/portal/tools/service/builder/dependencies/ folder. For example,
Service Builder uses the
service_impl.ftl template to generate the
You can modify any
*Impl class Service Builder generates. The most common are
*Impl. If you manually modify the
other classes, Service Builder overwrites the changes the next time you run it.
Whenever you add methods to, remove methods from, or change a method signature
*ServiceImpl class, or
*Impl class, you
should run Service Builder again to regenerate the affected interfaces and the
Congratulations! You’ve generated your application’s initial model, persistence, and service layers and you understand the generated code.