Created
October 3, 2018 10:49
-
-
Save sunnyone/b9e5c9d3b6bc05fe2b09cdfc5c12dc8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun convert(value: Any?, sqlType: Int, typeName: String?): Triple<Any?, Int, String?> { | |
if (value is CodedEnum) { | |
return Triple(value.code, sqlType, typeName) | |
} | |
return Triple(value, sqlType, typeName) | |
} | |
open class CustomizedNamedParameterJdbcTemplate(classicJdbcTemplate: JdbcOperations) : | |
NamedParameterJdbcTemplate(classicJdbcTemplate) { | |
override fun getPreparedStatementCreator(sql: String, | |
paramSource: SqlParameterSource, | |
customizer: Consumer<PreparedStatementCreatorFactory>?) | |
: PreparedStatementCreator { | |
val newParamSource = MapSqlParameterSource() | |
paramSource.parameterNames?.forEach { name -> | |
val (value, sqlType, typeName) = convert( | |
paramSource.getValue(name), | |
paramSource.getSqlType(name), | |
paramSource.getTypeName(name)) | |
if (typeName != null) { | |
newParamSource.addValue(name, value, sqlType, typeName) | |
} else { | |
newParamSource.addValue(name, value, sqlType) | |
} | |
} | |
return super.getPreparedStatementCreator(sql, newParamSource, customizer) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment