jamesfredley commented on code in PR #15395:
URL: https://github.com/apache/grails-core/pull/15395#discussion_r2824578617
##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/services/implementers/SaveImplementer.groovy:
##########
@@ -63,9 +65,18 @@ class SaveImplementer extends AbstractSaveImplementer
implements SingleResultSer
Parameter[] parameters = newMethodNode.parameters
int parameterCount = parameters.length
if (parameterCount == 1 && AstUtils.isDomainClass(parameters[0].type))
{
- body.addStatement(
- returnS(callX(varX(parameters[0]), 'save',
namedArgs(failOnError: ConstantExpression.TRUE)))
- )
+ Expression connectionId = findConnectionId(abstractMethodNode)
+ if (connectionId != null) {
+ // Route save through the instance API for the specified
connection
+ body.addStatement(
+ returnS(callX(buildInstanceApiLookup(domainClassNode,
connectionId), 'save', args(varX(parameters[0]), namedArgs(failOnError:
ConstantExpression.TRUE))))
+ )
+ }
+ else {
+ body.addStatement(
+ returnS(callX(varX(parameters[0]), 'save',
namedArgs(failOnError: ConstantExpression.TRUE)))
+ )
+ }
Review Comment:
Addressed. Harmonized to `findConnectionId(newMethodNode)` in both the
single-entity save path and the multi-arg path (via `bindParametersAndSave`).
Also renamed the parameter in `AbstractSaveImplementer.bindParametersAndSave()`
from `abstractMethodNode` to `newMethodNode` to match the convention used by
`AbstractDetachedCriteriaServiceImplementor`.
##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/services/implementers/DeleteImplementer.groovy:
##########
@@ -80,7 +81,15 @@ class DeleteImplementer extends
AbstractDetachedCriteriaServiceImplementor imple
void implementById(ClassNode domainClassNode, MethodNode
abstractMethodNode, MethodNode newMethodNode, ClassNode targetClassNode,
BlockStatement body, Expression byIdLookup) {
boolean isVoidReturnType =
ClassHelper.VOID_TYPE.equals(newMethodNode.returnType)
VariableExpression obj = varX('$obj')
- Statement deleteStatement = stmt(callX(obj, 'delete'))
+ Expression connectionId = findConnectionId(abstractMethodNode)
+ Statement deleteStatement
+ if (connectionId != null) {
+ // Route delete through the instance API for the specified
connection
+ deleteStatement =
stmt(callX(buildInstanceApiLookup(domainClassNode, connectionId), 'delete',
args(obj)))
+ }
+ else {
+ deleteStatement = stmt(callX(obj, 'delete'))
+ }
Review Comment:
Addressed. Changed to `findConnectionId(newMethodNode)` for consistency with
`AbstractDetachedCriteriaServiceImplementor`.
--
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]