jamesfredley commented on code in PR #15395: URL: https://github.com/apache/grails-core/pull/15395#discussion_r2824580048
########## grails-datamapping-core/src/test/groovy/grails/gorm/services/ConnectionRoutingServiceTransformSpec.groovy: ########## @@ -0,0 +1,327 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package grails.gorm.services + +import grails.gorm.transactions.Transactional +import org.grails.datastore.gorm.services.Implemented +import org.grails.datastore.gorm.services.implementers.DeleteImplementer +import org.grails.datastore.gorm.services.implementers.FindAndDeleteImplementer +import org.grails.datastore.gorm.services.implementers.FindOneImplementer +import org.grails.datastore.gorm.services.implementers.SaveImplementer +import spock.lang.Specification + +/** + * Tests that auto-implemented Data Service methods correctly route through + * connection-aware GormEnhancer APIs when @Transactional(connection=...) is specified. + * + * Covers the fix for: save (single-entity), delete (by-id), find-and-delete (by-id), + * and get/find (by-id) which previously bypassed connection routing and always hit + * the default datasource. + * + * @see org.grails.datastore.gorm.services.implementers.SaveImplementer + * @see org.grails.datastore.gorm.services.implementers.DeleteImplementer + * @see org.grails.datastore.gorm.services.implementers.FindAndDeleteImplementer + * @see org.grails.datastore.gorm.services.implementers.AbstractDetachedCriteriaServiceImplementor + */ +class ConnectionRoutingServiceTransformSpec extends Specification { + + void "test save with @Transactional(connection) routes through connection-aware API"() { + when: "an abstract data service with @Transactional(connection='secondary') declares save(Foo)" + Class service = new GroovyClassLoader().parseClass(''' +import grails.gorm.services.Service +import grails.gorm.annotation.Entity +import grails.gorm.transactions.Transactional + +@Service(Foo) +@Transactional(connection = 'secondary') +abstract class FooService { + + abstract Foo save(Foo foo) + + abstract Foo saveFoo(String title) +} + +@Entity +class Foo { + String title +} +''') Review Comment: The "abstract class implements interface" pattern isn't how `@Service` Data Services work in Grails - the framework generates implementations directly from either abstract classes or interfaces, not from abstract classes that extend interfaces. The existing tests already cover both patterns independently: abstract class services and interface-only services (added in the latest commit with `ProductDataService`). The TCK integration tests in `DataServiceMultiDataSourceSpec` now test both patterns with full Hibernate backing. -- 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]
