API / Apache Grails Interview questions
Explain the internal working of GORM Data Services?
Unlike dynamic finders, which are resolved dynamically every time they're called at runtime, GORM Data Services do essentially all of their work once, at compile time, through a Groovy AST (Abstract Syntax Tree) transformation.
At compile time, GORM's AST transformation inspects every abstract method declared on the annotated interface, parses its name and signature against the same recognizable vocabulary dynamic finders use (save, get, find, list, count, and so on), and generates real, compiled implementation code for each one directly into the class file — there's no runtime method-name parsing happening at all by the time the application actually runs.
The generated implementation is then registered as an ordinary Spring bean, exactly like a hand-written service, so from the perspective of a controller or another service injecting it, a Data Service is indistinguishable from any other dependency — the only difference is that its implementation was written by the compiler rather than by a developer, and any mistake in the method signature surfaces as a build failure rather than a runtime exception.
More Related questions...