jamesfredley commented on code in PR #15418: URL: https://github.com/apache/grails-core/pull/15418#discussion_r2835210520
########## grails-data-hibernate5/core/src/test/groovy/org/grails/orm/hibernate/connections/WhereQueryMultiDataSourceSpec.groovy: ########## @@ -0,0 +1,187 @@ +/* + * 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 org.grails.orm.hibernate.connections + +import org.hibernate.dialect.H2Dialect +import spock.lang.AutoCleanup +import spock.lang.Issue +import spock.lang.Shared +import spock.lang.Specification + +import grails.gorm.annotation.Entity +import grails.gorm.services.Service +import grails.gorm.services.Where +import grails.gorm.transactions.Transactional +import org.grails.datastore.gorm.GormEnhancer +import org.grails.datastore.gorm.GormEntity +import org.grails.datastore.mapping.core.DatastoreUtils +import org.grails.orm.hibernate.HibernateDatastore + +@Issue("https://github.com/apache/grails-core/issues/15416") +class WhereQueryMultiDataSourceSpec extends Specification { + + @Shared Map config = [ + 'dataSource.url':"jdbc:h2:mem:defaultDB;LOCK_TIMEOUT=10000", + 'dataSource.dbCreate': 'create-drop', + 'dataSource.dialect': H2Dialect.name, + 'dataSource.formatSql': 'true', + 'hibernate.flush.mode': 'COMMIT', + 'hibernate.cache.queries': 'true', + 'hibernate.hbm2ddl.auto': 'create-drop', + 'dataSources.secondary':[url:"jdbc:h2:mem:secondaryDB;LOCK_TIMEOUT=10000"], + ] + + @Shared @AutoCleanup HibernateDatastore datastore = new HibernateDatastore( + DatastoreUtils.createPropertyResolver(config), Item + ) + + @Shared ItemQueryService itemQueryService + + void setupSpec() { + itemQueryService = datastore + .getDatastoreForConnection('secondary') + .getService(ItemQueryService) + } + + void setup() { + def api = GormEnhancer.findStaticApi(Item, 'secondary') + api.withNewTransaction { + api.executeUpdate('delete from Item') Review Comment: Fixed - moved the data deletion from `setup()` to `cleanup()` so each test cleans up after itself regardless of pass/fail. See commit 98e9b51. ########## grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/services/implementers/AbstractWhereImplementer.groovy: ########## @@ -96,16 +96,16 @@ abstract class AbstractWhereImplementer extends AbstractReadOperationImplementer body.addStatement( declS(queryVar, ctorX(getDetachedCriteriaType(domainClassNode), args(classX(domainClassNode.plainNodeReference)))) ) - Expression connectionId = findConnectionId(newMethodNode) + body.addStatement( + assignS(queryVar, callX(queryVar, 'build', closureExpression)) Review Comment: Done - added a full TCK test (`WhereQueryConnectionRoutingSpec`) with domain class, service interface, and multi-datasource support in both the Hibernate and MongoDB TCK managers. The test validates @Where, count, list, and findByName all route to the correct secondary datasource. Verified passing on: - Hibernate5: 5/5 pass - MongoDB: 5/5 pass - SimpleMap: skipped (no multi-datasource support) See commit 98e9b51. -- 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]
