Results 1 to 6 of 6

Thread: Where do I put my business logic?

  1. #1
    Join Date
    Feb 2012
    Location
    Huntsville, AL
    Posts
    23

    Default 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. #2
    Join Date
    Feb 2012
    Location
    Huntsville, AL
    Posts
    23

    Default

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

  3. #3
    Join Date
    Jul 2007
    Posts
    123

    Default

    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.

  4. #4
    Join Date
    Feb 2012
    Location
    Huntsville, AL
    Posts
    23

    Default

    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.

  5. #5
    Join Date
    Feb 2012
    Location
    Huntsville, AL
    Posts
    23

    Default

    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.

  6. #6
    Join Date
    Aug 2011
    Location
    San Francisco Bay Area
    Posts
    5

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •