I'm trying to take advantage of the fact that groovy is more dynamic than java. I'd like to have a block of code that does
TypeA type = //do something to build an object
TypeA dbType = TypeA.findBySomethingAndSomething(something, somethingelse)
if(dbType != null)
type.id = dbType.id
type.save()
but that can work for multiple objects that support the same findBySomethingAndSomething method.
Is it possible to say
def type = //do something to build an object
def dbType = type.findBySomethingAndSomething(type.identifier, type.otheridentifier)
if(dbType != null)
type.id = dbType.id
type.save()
Is there a "better" way to accomplish this? I'm trying to avoid a large switch statement or if / else series that does essentially the same thing for each type.