jamesfredley opened a new pull request, #15433:
URL: https://github.com/apache/grails-core/pull/15433

   ## Summary
   
   - `@Service(DomainClass)` now automatically inherits the datasource from the 
domain class's `mapping { datasource 'xxx' }` block
   - Developers no longer need to specify `@Transactional(connection = '...')` 
when the domain already declares its datasource
   - Explicit `@Transactional(connection = '...')` on the service still takes 
precedence
   
   ## Implementation
   
   Two-layer approach:
   
   **AST (compile-time)** - `ServiceTransformation.groovy`:
   - After resolving the target domain class, parses its `static mapping` 
closure AST for `datasource(...)`, `connection(...)`, or `connections(...)` 
calls
   - If a non-default datasource is found and the service has no explicit 
`@Transactional(connection)`, propagates `@Transactional(connection = 
'domainDatasource')` to both the original class node and the generated 
implementation class
   - This ensures `findConnectionId()` in service implementers 
(SaveImplementer, DeleteImplementer, etc.) generates connection-aware 
GormEnhancer API calls
   
   **Runtime** - `DatastoreServiceMethodInvokingFactoryBean.groovy`:
   - When creating service instances, resolves the domain class's datasource 
from the mapping context via 
`ConnectionSourcesSupport.getDefaultConnectionSourceName()`
   - Sets the correct connection-specific datastore on the service instance 
(instead of always using the default)
   
   ## Before / After
   
   ```groovy
   // BEFORE: Both annotations required
   @Service(Product)
   @Transactional(connection = 'secondary')  // had to manually specify
   abstract class ProductService { ... }
   
   // AFTER: Service inherits from domain
   @Service(Product)  // Product has datasource 'secondary' - service inherits 
it
   abstract class ProductService { ... }
   ```
   
   ## Tests
   
   - **6 unit tests** added to `ConnectionRoutingServiceTransformSpec` - 
AST-level verification of annotation propagation for abstract classes, 
interfaces, explicit override, default datasource, `connection()` variant, and 
`@Transactional` without connection
   - **8 integration tests** in new `DataServiceDatasourceInheritanceSpec` - 
end-to-end with real H2 databases testing save, get, delete, count, findBy, 
interface services, explicit override, and cross-service queries
   - **6 functional tests** in `grails-test-examples` - Grails 
application-level integration test with `InheritedProductService` (no 
`@Transactional(connection)`)
   - All 16 existing `DataServiceMultiDataSourceSpec` tests continue to pass
   
   ## Documentation
   
   Added "GORM Data Service Datasource Inheritance" subsection to 
`multipleDatasources.adoc` with usage examples.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to