Persistence Against Statelessness Grails

I'm currently moving on to business logic from the controller method to the service when I fell into the rabbit hole of Grail services. My service has the following method:

Job closeJobOpportunity(Job op, Employee res) {
    op.chosenOne = res
    op.requisitionCanceledDate = new Date() 
    if(!op.chosenOne || !op.hrEffectiveDate){
        return null
    }
    else if(StringUtils.isEmpty(op.chosenOne.id)){
        return null
    }
    return op
}

I started thinking about how this method can cause synchronization problems (due to the fact that grails does a singleton service), and noticed that the Grails documentation mentions that business logic should be injected into the service while you don’t save condition .

With the risk of voicing ignorant or insufficiently informed, can someone just provide the difference between Grails and stateless services in Grails? Is the above method a condition? Should it then be surrounded by an attempt to catch in the controller?

+4
2

stateful stateless Grails ( ) , .

-, , , , , , - . , .

, .

class MyStatefulService {
  Long someNumber
  String someString

  void doSomething(Long addMe) {
    someNumber += addMe
  }

  void updateSomething(String newValue) {
    someString = newValue
  }
}

, . , . , . , , , . , . , , .

, , . . , , ( , ).

, , , , , . , , , .

, .

+7

Source: https://habr.com/ru/post/1540779/


All Articles