Service Builder
Liferay’s code generator for database-driven applications (creates *LocalService and *ServiceImpl).
- Automate CRUD operations for custom tables.
- Handle SQL/JPA boilerplate.
Implementation
Section titled “Implementation”Create the Module
Section titled “Create the Module”blade create -t service-builder bookstoreDefine Entities in service.xml
Section titled “Define Entities in service.xml”<entity name="Book" local-service="true"> <column name="bookId" type="long" primary="true" /> <column name="title" type="String" /> <column name="author" type="String" /></entity>Build Services
Section titled “Build Services”Run:
blade gw buildServiceThis generates:
BookLocalService(interface).BookLocalServiceImpl(your custom logic).
Use the Service
Section titled “Use the Service”// In a portlet or another module@Referenceprivate BookLocalService _bookLocalService;
public void addBook(String title, String author) { Book book = _bookLocalService.createBook(0L); book.setTitle(title); book.setAuthor(author); _bookLocalService.addBook(book);}Use Cases
Section titled “Use Cases”- Custom Tables: Store application-specific data (e.g., “Book”, “Order”).
- Legacy Data Migration: Map external databases to Liferay.