Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:05:22+00:00 2026-05-23T18:05:22+00:00

I’m writing a service that shouldn’t have to save anything. It gets some values.

  • 0

I’m writing a service that shouldn’t have to save anything. It gets some values. Looks up a few things in the database, and then coughs back a response. Is there anything I should do to make the service faster/less overhead? Also whats the best way to pass it something. I usually pass the id and get it again; is that good/bad/dumb?

example

class DoStuffController {
  def ExampleProcessingService
  def yesDoIt = {
    def lookup = "findme"
    def theObject = ExampleThing.findByLookie(lookup)
    def lolMap = ExampleProcessingService.doYourThing(theObject.id)
    if(lolMap["successBool"]){
      theObject.imaString = "Stuff"
      theObject.save()
    }
    []
  }
}

service

class ExampleProcessingService{
  static transactional = true //???????? false? not-a?
  def doYourThing = {theID ->
    def returnMap = [:]
    def myInstance = ExampleThing.get(theID)
    if(myInstance.something)returnMap.put "successBool", true
    else returnMap.put "successBool", false
    return returnMap
  }
}

domain object

class ExampleThing {

  String imaString
  String lookie
  static constraints = {
    imaString(nullable:true)

  }
  def getSomething() {
    return true
  }
}

bootstrap

import learngrails.*
class BootStrap {

    def init = { servletContext ->
        def newThing = new ExampleThing(lookie:"findme")
        newThing.save()
    }
    def destroy = {
    } 
}

Is the an advantage, disadvantage or standard to passing ID and doing get vs. passing the object? Does this change given my case of not going to save anything in the service? Is there something I’m doing glaringly wrong? Do you have a better suggestion for the title?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:05:22+00:00Added an answer on May 23, 2026 at 6:05 pm

    You’ve asked a lot of questions, and should split this into several individual questions. But I’ll address the overall issue – this approach is fine in general.

    There’s not a lot of overhead in starting and committing a transaction that doesn’t do any database persistence, but it is wasteful, so you should add

    static transactional = false
    

    In this case you’re using the class as an easily injected singleton helper class. It’s convenient to do transactional work in services because they’re automatically transactional, but it’s far from a requirement.

    One thing though – do not use closures in services. They’re required in controllers and taglibs (until 2.0 anyway) but should always be avoided in services and other classes. If you’re not using the fact that it’s a closure – i.e. passing it as an object to a method as a parameter, or setting its delegate, etc. – then you’re just being way too groovy. If you’re calling it like a method, make it a method. The real downside to closures in services is that when you want them to be transactional, they cannot be. This is because Spring interceptors intercept method calls, not closure calls that Groovy pretends are method calls. So there won’t be any interception for transactions, security, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.