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:
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With