0

I'm migrating a 2.5.6 app to 3.3.10. When generating controllers, detected that a service was created and used from the controllers auto-generated code. Looking at the service, is just an interface.

Looking at the grails generate-controller documentation, I can't find information about that "interface service"

http://docs.grails.org/3.3.10/ref/Command%20Line/create-controller.html

What that service is doing internally is also a mistery, and it's not clear what/where should I touch the code when I need to customize any of those methods in the service. I guess this is a new thing in Grails 3.3.x but not sure where to find more info.

So the concrete questions are:

  1. What is the purpose of that interface service?
  2. Where is that documented?
  3. How to customize? Like being implemented by a custom service?

Sample service:

import grails.gorm.services.Service

@Service(SyncLog)
interface SyncLogService {

    SyncLog get(Serializable id)

    List<SyncLog> list(Map args)

    Long count()

    void delete(Serializable id)

    SyncLog save(SyncLog syncLog)

}
Pablo Pazos
  • 3,080
  • 29
  • 42

1 Answers1

3

What is the purpose of that interface service?

It is a starting point for your data access layer.

Where is that documented?

At http://gorm.grails.org/latest/hibernate/manual/index.html#dataServices

How to customize?

It is an interface that you can edit and add/delete whatever query methods you like. The documentation linked above describes a lot of details.

Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47
  • Good, I can see the extension mechanism is through abstract classes, and the idea of this new pattern is for GORM data access, not for general app logic. In which version was this pattern added to Grails? Thanks Jeff. – Pablo Pazos Oct 06 '19 at 00:53
  • 1
    " In which version was this pattern added to Grails?" - That file is generated by the `scaffolding` plugin. Version 3.4.0 of the scaffolding plugin is the first version which generated a GORM Data Service interface. Grails 3.3.1 is the first version of Grails to include that. Grails 3.3.0 used scaffolding 3.3.3, which did not generate the interface. – Jeff Scott Brown Oct 06 '19 at 03:16
  • This also was added as an API scaffold as Grails doesn't abstract away communication logic from business logic creating an architectural cross cutting concern. This goes against AOP because it not only binds communication/business logic but makes it impossible to share/synchronize state without duplication. – Orubel Oct 06 '19 at 16:17
  • 1
    What do you mean by "communication logic", http hadling? Isn't that done with Spring Boot? – Pablo Pazos Oct 06 '19 at 17:06
  • The way Grails binds API logic is with Annotations. This binds communication logic and data to the controller/business logic. Thus making it impossible to share/syncronize that data without duplication. Most MODERN API Frameworks have abstracted this away; for example, I advised AWS team on this and they changed it so that Lambdas no longer bind this data and instead store this in a cache so that they can share it with the AWS Gateway service. This is the proper methodology for doing this. – Orubel Oct 07 '19 at 17:45
  • To see an example of separated 'state', view this gist: https://gist.github.com/orubel/159e94db62023c78a07ebe6d86633763 . This shows all the data for a controller, separated out so that it can be loaded at runtime, shared/syncronized via hooks with other services in network. – Orubel Oct 07 '19 at 17:55