Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GORM Data Services VS Grails Services

GORM 6.1 introduced the concept of Data Services. I think of them as auto-generated persistence logic that are checked at compile time. I'm having some confusion as to the following:

  1. How are they different from Grails Services (aside from the compile time difference)?
  2. Is it possible to still implement my custom business logic inside the GORM Data Services or do I need to maintain two services, one for persistence (GORM) and the other (GRAILS) for other none persistence related business logic (e.g making an external REST request and acting on the response).
  3. I noticed grails generate-all Domain generates a Data Service interface for REST profile. This leaves me confused as to whether we can have non persistence related method names in the service.

Update: What I'm asking about is this: gorm.grails.org/latest/hibernate/manual/#dataServices. I'm trying to understand how those are different from this: docs.grails.org/latest/guide/services.html and when to use them.

like image 314
Emmanuel John Avatar asked Dec 29 '17 05:12

Emmanuel John


People also ask

What is Grails Gorm?

GORM is the data access toolkit used by Grails and provides a rich set of APIs for accessing relational and non-relational data including implementations for Hibernate (SQL), MongoDB, Neo4j, Cassandra, an in-memory ConcurrentHashMap for testing and an automatic GraphQL schema generator.

What are Grails services?

Services in Grails are the place to put the majority of the logic in your application, leaving controllers responsible for handling request flow with redirects and so on.

What is Grails domain class?

A domain class fulfills the M in the Model View Controller (MVC) pattern and represents a persistent entity that is mapped onto an underlying database table. In Grails a domain is a class that lives in the grails-app/domain directory.


1 Answers

How are they different from Grails Services (aside from the compile time difference)?

GORM Data Services are Grails services.

Is it possible to still implement my custom business logic inside the GORM Data Services or do I need to maintain two services, one for persistence (GORM) and the other (GRAILS) for other none persistence related business logic (e.g making an external REST request and acting on the response).

You can put business logic in whatever services you like. In general the logic in GORM Data Services should be related to database interactions but that is entirely up to you. If you wanted you could put 100% of your business logic in GORM Data Service instances, though that wouldn't make sense. A GORM Data Service is a Service and you can put whatever you like in it.

I noticed grails generate-all Domain generates a Data Service interface for REST profile. This leaves me confused as to whether we can have non persistence related method names in the service.

You can have non persistence related method names in the service. You can put whatever you want in the service.

The approach I would take is I would use GORM Data Service for database related code and use traditional Grails Services for everything else and inject 1 into the other where appropriate.

like image 58
Jeff Scott Brown Avatar answered Sep 30 '22 01:09

Jeff Scott Brown