GORM 数据服务 VS Grails 服务
GORM Data Services VS Grails Services
GORM 6.1 引入了数据服务的概念。我认为它们是在编译时检查的自动生成的持久性逻辑。我对以下内容有些困惑:
- 它们与 Grails 服务有何不同(除了编译时间差异)?
- 是否仍然可以在 GORM 数据服务中实现我的自定义业务逻辑,或者我是否需要维护两项服务,一项用于持久性 (GORM),另一项 (GRAILS) 用于其他 none 持久性相关业务逻辑(例如发出外部 REST 请求并根据响应执行操作)。
- 我注意到
grails generate-all Domain
为 REST 配置文件生成了一个数据服务接口。这让我对我们是否可以在服务中使用非持久性相关的方法名称感到困惑。
更新: 我要问的是: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 以及何时使用它们。
我已根据您在下面给出的要点区分了您的问题。
所有 GORM 持久性方法都已编译(JAR 文件)但不是您正在实现/编写的服务方法调用,它们会在您键入和保存代码时动态编译。 GORM 方法得到了很好的优化。
可以在一个方法中同时编写您的自定义业务逻辑和 GORM API 调用,但如果您想编写通用方法,则需要了解场景对于许多其他控制器调用,也希望避免复杂性,在这种情况下,您可以为上述两种情况编写单独的调用。
对于简短的自定义业务逻辑,您可以在同一方法中编写代码。
我们也可以在同一服务中编写非持久性相关的方法,但这取决于您。您还可以为这些方法创建单独的服务或使用现有的其他服务以避免任何混淆和复杂性。
Note : Services are transactional by default, but can be made
non-transactional if none of their methods update the persistence
store.
How are they different from Grails Services (aside from the compile
time difference)?
GORM 数据服务是 Grails 服务。
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).
您可以将业务逻辑放入您喜欢的任何服务中。一般来说,GORM 数据服务中的逻辑应该与数据库交互相关,但这完全取决于您。如果您愿意,您可以将 100% 的业务逻辑放在 GORM 数据服务实例中,尽管那没有意义。 GORM 数据服务是一种服务,您可以在其中放入任何您喜欢的东西。
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.
您可以在服务中使用非持久性相关的方法名称。你可以在服务中放入任何你想要的东西。
我将采用的方法是,我将 GORM 数据服务用于数据库相关代码,而将传统的 Grails 服务用于其他一切,并在适当的地方将 1 注入另一个。
GORM 6.1 引入了数据服务的概念。我认为它们是在编译时检查的自动生成的持久性逻辑。我对以下内容有些困惑:
- 它们与 Grails 服务有何不同(除了编译时间差异)?
- 是否仍然可以在 GORM 数据服务中实现我的自定义业务逻辑,或者我是否需要维护两项服务,一项用于持久性 (GORM),另一项 (GRAILS) 用于其他 none 持久性相关业务逻辑(例如发出外部 REST 请求并根据响应执行操作)。
- 我注意到
grails generate-all Domain
为 REST 配置文件生成了一个数据服务接口。这让我对我们是否可以在服务中使用非持久性相关的方法名称感到困惑。
更新: 我要问的是: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 以及何时使用它们。
我已根据您在下面给出的要点区分了您的问题。
所有 GORM 持久性方法都已编译(JAR 文件)但不是您正在实现/编写的服务方法调用,它们会在您键入和保存代码时动态编译。 GORM 方法得到了很好的优化。
可以在一个方法中同时编写您的自定义业务逻辑和 GORM API 调用,但如果您想编写通用方法,则需要了解场景对于许多其他控制器调用,也希望避免复杂性,在这种情况下,您可以为上述两种情况编写单独的调用。 对于简短的自定义业务逻辑,您可以在同一方法中编写代码。
我们也可以在同一服务中编写非持久性相关的方法,但这取决于您。您还可以为这些方法创建单独的服务或使用现有的其他服务以避免任何混淆和复杂性。
Note : Services are transactional by default, but can be made non-transactional if none of their methods update the persistence store.
How are they different from Grails Services (aside from the compile time difference)?
GORM 数据服务是 Grails 服务。
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).
您可以将业务逻辑放入您喜欢的任何服务中。一般来说,GORM 数据服务中的逻辑应该与数据库交互相关,但这完全取决于您。如果您愿意,您可以将 100% 的业务逻辑放在 GORM 数据服务实例中,尽管那没有意义。 GORM 数据服务是一种服务,您可以在其中放入任何您喜欢的东西。
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.
您可以在服务中使用非持久性相关的方法名称。你可以在服务中放入任何你想要的东西。
我将采用的方法是,我将 GORM 数据服务用于数据库相关代码,而将传统的 Grails 服务用于其他一切,并在适当的地方将 1 注入另一个。