The word service can mean many specific things, but the general dictionary definition states that it’s “an act of helpful activity.” Everyone has experienced this in some way. Whether it’s an act of kindness from a friend or stranger or a service you pay for, in all instances, you have a need, and the service provides for that need.

Data-driven applications by their nature need access to a service for storing and retrieving their data. In a well-designed application, the application asks for data, and the service fetches it. The application can then display this data to the user, who reads it or modifies it. If the data is modified, the application passes it back to the service, and the service stores it. The application doesn’t need to know anything about how the service does what it does. It trusts the service to handle storing and retrieving the data, freeing the application to be as robust as it needs to be.

This is what is called loose coupling, and it’s a hallmark of good application design. If your application’s service layer is self-contained, then you can swap it out for a better service layer when something more robust comes along, and you won’t have to modify the application to take advantage of it.

Well, something more robust has come along, and it’s called Service Builder. Using the Object-Relational Mapping engine provided by Hibernate along with a sophisticated code generator, Service Builder can help you implement your service layer in a fraction of the time it would normally take. But this isn’t just any ordinary service layer: Service Builder also optionally helps you with remote services in multiple protocols, such as JSON and SOAP. And if you need to do something really funky with the database, it gets out of your way and lets you use whatever SQL queries you want.

Intrigued? We hope so. We’ll cover the following topics:

  • What is Service Builder?
  • Defining Your Object-Relational Map
  • Writing the Local Service Class
  • Calling Local Services
  • Using Model Hints
  • Enabling Remote Services
  • Developing Custom SQL Queries
  • Configuring

As you can see, there is a lot to cover, so let’s start by describing Service Builder in more detail.

What is Service Builder?

Service Builder is a model-driven code generation tool built by Liferay that allows developers to define custom object models called entities. Service Builder generates a service layer through...

Read More

Defining Your Object-Relational Map

In order to demonstrate how to use Service Builder, let’s create an example portlet project that Nose-ster, a fictitious organization, can use to schedule social events. For our example, we’ll...

Read More

Generating Services

To build a service from a service.xml file, you can use Liferay IDE, Liferay Developer Studio, or use a terminal window. Next, you’ll generate the service for the example Event Listing portlet...

Read More

Writing Local Service Classes

The heart of your service is its -LocalServiceImpl class, where you put core business logic for working with your model. Throughout this chapter, you’ve been constructing services for the Nose-ster...

Read More

Calling Local Services

Once Service Builder has generated your portlet project’s services, you can call them in our project’s -Portlet classes. You can call any methods in your EventLocalServiceUtil or...

Read More

Understanding the Service Builder-generated Code

Now let’s examine the files Service Builder generated for your Event entity. Note that the files listed under Local Service and Remote Service below are only generated for an entity that has both...

Read More

Calling Liferay Services

Every service provides a local interface to clients running in the same JVM as Liferay Portal. These are called by use of the -ServiceUtil classes. These classes mask the complexity of service...

Read More

Using Model Hints

Now that you’ve created your model entities and implemented your business logic to create and modify those entities, you probably have some ideas for helping users input valid model entity data....

Read More

Writing Remote Service Classes

Many default Liferay services are available as web services. Liferay exposes its web services via SOAP and JSON web services. If you’re running Liferay locally on port 8080, visit the following URL...

Read More

Developing Custom SQL Queries

Service Builder’s finder methods facilitate searching for entities by their attributes–their column values. Add the column as a parameter for the finder in your service.xml file, run Service...

Read More


Service Builder generates a file in your project’s docroot/WEB-INF/src folder. Liferay Portal uses the properties in this file to alter your service’s database schema and load...

Read More


You’ve covered a lot of ground in this chapter. You learned how to map out your data model as entities to use in services. You used Service Builder and Liferay IDE’s powerful editing modes to...

Read More
0 (0 Votes)
Summary Previous