JdbcMapperProcessor considers anything implementing Bindable a shortcut for {sql:}

This commit is contained in:
Travis Burtrum 2019-03-10 23:40:16 -04:00
parent e47ec84325
commit 1766a9af6d
2 changed files with 14 additions and 4 deletions

View File

@ -400,8 +400,17 @@ public class JdbcMapperProcessor extends AbstractProcessor {
final String inColumnName = bindParamMatcher.group(2);
if (inColumnName == null) {
if(clobBlobSql == null){
bindParamMatcher.appendReplacement(sb, "?");
bindParams.add(bindParam);
// shortcut for Bindable without sql:
if (types.isAssignable(bindParam.asType(), bindableType)) {
bindParamMatcher.appendReplacement(sb, "REPLACEMEWITHUNQUOTEDQUOTEPLZ + " + paramName + " + REPLACEMEWITHUNQUOTEDQUOTEPLZ");
final SpecialVariableElement sve = new SpecialVariableElement(bindParam, SQL, null);
bindParams.add(sve);
sqlParam = true;
sqlIterableParam |= sve.iterable || sve.bindable;
} else {
bindParamMatcher.appendReplacement(sb, "?");
bindParams.add(bindParam);
}
} else {
final String upperClobBlobSql = clobBlobSql.toUpperCase();
String blobCharset = bindParamMatcher.group(6);
@ -1051,7 +1060,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
method = "Ref";
} else {
// shouldn't get here ever, if we do the types should be more specific
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@JdbcMapper.SQL could not properly infer PreparedStatement bind call for param", param);
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@JdbcMapper.SQL could not properly infer PreparedStatement bind call for param: " + variableName, param);
return;
}
w.write("ps.set");

View File

@ -275,7 +275,8 @@ public interface QmDao extends JdbcMapper {
@SQL("SELECT person_no FROM person WHERE person_no = {personNo1} {sql:sql} OR first_name = {firstName}")
List<Long> selectRandomSql(long personNo1, String sql, String firstName) throws SQLException;
@SQL("SELECT person_no FROM person WHERE person_no = {personNo1} {sql:sql} OR first_name = {firstName}")
// do not need sql: for anything extending Bindable
@SQL("SELECT person_no FROM person WHERE person_no = {personNo1} {sql} OR first_name = {firstName}")
List<Long> selectRandomSqlBuilder(long personNo1, Bindable sql, String firstName) throws SQLException;
// these we just check if they generated