Using the Staged Model Repository Framework

Leveraging the Staged Model Repository framework in your app is easy once you’ve created staged model repository implementation classes.

You’ll step through a quick example to demonstrate leveraging the StagedModelRepository interface in a staged model data handler. The code snippets originate from Liferay’s Bookmarks app and Bookmarks Entries.

  1. Create a getter and setter method to make a StagedModelRepository object available for the BookmarksEntry entity:

    protected StagedModelRepository<BookmarksEntry> getStagedModelRepository() {
        return _stagedModelRepository;
        target = "(",
        unbind = "-"
    protected void setStagedModelRepository(
        StagedModelRepository<BookmarksEntry> stagedModelRepository) {
        _stagedModelRepository = stagedModelRepository;
    private StagedModelRepository<BookmarksEntry> _stagedModelRepository;
  2. Call your _stagedModelRepository object to leverage its specialized export/import logic. For example,

    newEntry = _stagedModelRepository.updateStagedModel(portletDataContext, importedEntry);

    Without the staged model repository logic, you would’ve called your local service like this:

    newEntry = _bookmarksEntryLocalService.addEntry(
        userId, portletDataContext.getScopeGroupId(), folderId, entry.getName(), entry.getUrl(), entry.getDescription(), serviceContext);

    The large number of parameters and UUID setter the local service method requires aren’t needed when leveraging the staged model repository.

Great! You’ve successfully leveraged your staged model repository from a data handler!

« Implementing the Staged Model Repository FrameworkUsing the Export/Import Lifecycle Listener Framework »
Was this article helpful?
0 out of 0 found this helpful