Announcement Announcement Module
Collapse
No announcement yet.
Where do I put my business logic? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Where do I put my business logic?

    Hi, I have years of non-Spring J2EE experience, but I am new to Grails and Spring. Is the grails-app/src directory for business logic? I was under the impression I should put my non-MVC code here. However, I'm unable to run test cases because it doesn't consider my code there to be "a Domain".

    To elaborate on what I am trying to accomplish, I have a domain class "A" with a large text field. This field will be populated by the user, then I want to parse it on create. The results of my parse will be a list of domain classes "B" which are contained by "A". I know this is not particularly normalized, but my reasoning is I want to hang onto the original text in case my parsing is erroneous.

    In my mind my parsing logic should not be part of the controller's create() method. Can anyone steer me towards the correct way to solve this type of problem using Grails/Spring? I'm assuming that it is highly likely that my paradigm needs to shift more.

    Thanks!
    Joe

  • #2
    Am I so far off that no one even knows how to start answering? This could be bad.

    Comment


    • #3
      I'm not sure what you mean by grails-app/src. There's a src folder in the root where you can put Java and Groovy classes that aren't standard artifacts like domain classes, controllers, etc. In general services (under grails-app/services) are where business logic goes. They're transactional by default (but this can be disabled) so they're the best place to put transactional database work.

      btw you'll have a lot more luck on the Grails User mailing list - it's a lot more active than this forum. See http://grails.org/Mailing+lists to sign up.

      Comment


      • #4
        Ok, thanks! By "grails-app/src" I meant the src directory that you mentioned at the root. I didn't mean the directory that is actually named "grails-app"... not a good choice of name on my part.

        I'll play around in the services directory. Glad to know what that one is. When you say they're transactional, I assume that you mean every method on any class runs as a single transaction by default? If so, that's awesome.

        Thanks for the tip to use the Grails User mailing list. I'll hop over there and see what I can learn.

        Comment


        • #5
          Looks like I found all of my answers here: http://grails.org/doc/2.0.x/guide/services.html
          Thanks for the tip on the services directory.

          Comment


          • #6
            Have a look at Automated Business Logic - with Grails sample app

            Comment

            Working...
            X