1
1
/*
2
- * Copyright 2014-2015 the original author or authors.
2
+ * Copyright 2014-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -98,7 +98,7 @@ public Object execute(final ExecutableMongoScript script, final Object... args)
98
98
99
99
@ Override
100
100
public Object doInDB (DB db ) throws MongoException , DataAccessException {
101
- return db .eval (script .getCode (), convertScriptArgs (args ));
101
+ return db .eval (script .getCode (), convertScriptArgs (false , args ));
102
102
}
103
103
});
104
104
}
@@ -116,7 +116,7 @@ public Object call(final String scriptName, final Object... args) {
116
116
117
117
@ Override
118
118
public Object doInDB (DB db ) throws MongoException , DataAccessException {
119
- return db .eval (String .format ("%s(%s)" , scriptName , convertAndJoinScriptArgs (args )));
119
+ return db .eval (String .format ("%s(%s)" , scriptName , convertAndJoinScriptArgs (true , args )));
120
120
}
121
121
});
122
122
}
@@ -155,7 +155,7 @@ public Set<String> getScriptNames() {
155
155
return scriptNames ;
156
156
}
157
157
158
- private Object [] convertScriptArgs (Object ... args ) {
158
+ private Object [] convertScriptArgs (boolean quote , Object ... args ) {
159
159
160
160
if (ObjectUtils .isEmpty (args )) {
161
161
return args ;
@@ -164,15 +164,15 @@ private Object[] convertScriptArgs(Object... args) {
164
164
List <Object > convertedValues = new ArrayList <Object >(args .length );
165
165
166
166
for (Object arg : args ) {
167
- convertedValues .add (arg instanceof String ? String .format ("'%s'" , arg ) : this . mongoOperations . getConverter ( )
168
- .convertToMongoType (arg ));
167
+ convertedValues .add (arg instanceof String && quote ? String .format ("'%s'" , arg )
168
+ : this . mongoOperations . getConverter () .convertToMongoType (arg ));
169
169
}
170
170
171
171
return convertedValues .toArray ();
172
172
}
173
173
174
- private String convertAndJoinScriptArgs (Object ... args ) {
175
- return ObjectUtils .isEmpty (args ) ? "" : StringUtils .arrayToCommaDelimitedString (convertScriptArgs (args ));
174
+ private String convertAndJoinScriptArgs (boolean quote , Object ... args ) {
175
+ return ObjectUtils .isEmpty (args ) ? "" : StringUtils .arrayToCommaDelimitedString (convertScriptArgs (quote , args ));
176
176
}
177
177
178
178
/**
0 commit comments