Commit a361ee9403fa289bcd1672ab8ada172bd756d260
1 parent
bc9760ff
Exists in
master
and in
1 other branch
修复keyholder在并发场景下,查询出错的问题
Showing
4 changed files
with
7 additions
and
14 deletions
Show diff stats
build.gradle
| @@ -58,7 +58,7 @@ uploadArchives { | @@ -58,7 +58,7 @@ uploadArchives { | ||
| 58 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 58 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
| 59 | } | 59 | } |
| 60 | pom.project { | 60 | pom.project { |
| 61 | - version '2.2.3' | 61 | + version '2.2.4' |
| 62 | artifactId ARTIFACT_Id | 62 | artifactId ARTIFACT_Id |
| 63 | groupId GROUP_ID | 63 | groupId GROUP_ID |
| 64 | packaging TYPE | 64 | packaging TYPE |
src/main/java/com/taover/repository/CustomJdbcTemplate.java
| @@ -4,7 +4,6 @@ import java.io.Serializable; | @@ -4,7 +4,6 @@ import java.io.Serializable; | ||
| 4 | import java.lang.reflect.Field; | 4 | import java.lang.reflect.Field; |
| 5 | import java.lang.reflect.ParameterizedType; | 5 | import java.lang.reflect.ParameterizedType; |
| 6 | import java.math.BigDecimal; | 6 | import java.math.BigDecimal; |
| 7 | -import java.math.BigInteger; | ||
| 8 | import java.sql.Connection; | 7 | import java.sql.Connection; |
| 9 | import java.sql.PreparedStatement; | 8 | import java.sql.PreparedStatement; |
| 10 | import java.sql.SQLException; | 9 | import java.sql.SQLException; |
| @@ -52,7 +51,6 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { | @@ -52,7 +51,6 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { | ||
| 52 | private String tableName; | 51 | private String tableName; |
| 53 | private Class<T> tClassInfo; | 52 | private Class<T> tClassInfo; |
| 54 | private CustomJdbcTemplateRowMapper customJdbcTemplateRowMapper; | 53 | private CustomJdbcTemplateRowMapper customJdbcTemplateRowMapper; |
| 55 | - private KeyHolder keyHolder; | ||
| 56 | 54 | ||
| 57 | public CustomJdbcTemplateRowMapper getCustomJdbcTemplateRowMapper(){ | 55 | public CustomJdbcTemplateRowMapper getCustomJdbcTemplateRowMapper(){ |
| 58 | return this.customJdbcTemplateRowMapper; | 56 | return this.customJdbcTemplateRowMapper; |
| @@ -122,9 +120,6 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { | @@ -122,9 +120,6 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { | ||
| 122 | 120 | ||
| 123 | //创建rowmapper | 121 | //创建rowmapper |
| 124 | this.customJdbcTemplateRowMapper = new CustomJdbcTemplateRowMapper(this.tClassInfo, this.tableToBeanField); | 122 | this.customJdbcTemplateRowMapper = new CustomJdbcTemplateRowMapper(this.tClassInfo, this.tableToBeanField); |
| 125 | - | ||
| 126 | - //主键ID保存 | ||
| 127 | - this.keyHolder = new GeneratedKeyHolder(); | ||
| 128 | } | 123 | } |
| 129 | 124 | ||
| 130 | /** | 125 | /** |
| @@ -464,6 +459,7 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { | @@ -464,6 +459,7 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { | ||
| 464 | 459 | ||
| 465 | //执行SQL | 460 | //执行SQL |
| 466 | String exeSql = sqlInsertPart.substring(0, sqlInsertPart.length()-1)+sqlColumnPart.substring(0, sqlColumnPart.length()-1)+")"; | 461 | String exeSql = sqlInsertPart.substring(0, sqlInsertPart.length()-1)+sqlColumnPart.substring(0, sqlColumnPart.length()-1)+")"; |
| 462 | + KeyHolder keyHolder = new GeneratedKeyHolder(new ArrayList<Map<String,Object>>(1)); | ||
| 467 | jdbcTemplateWrite.update(new PreparedStatementCreator() { | 463 | jdbcTemplateWrite.update(new PreparedStatementCreator() { |
| 468 | @Override | 464 | @Override |
| 469 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { | 465 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { |
| @@ -512,6 +508,7 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { | @@ -512,6 +508,7 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { | ||
| 512 | exeSql.setCharAt(exeSql.length()-1, ';'); | 508 | exeSql.setCharAt(exeSql.length()-1, ';'); |
| 513 | 509 | ||
| 514 | //调用更新接口 | 510 | //调用更新接口 |
| 511 | + KeyHolder keyHolder = new GeneratedKeyHolder(new ArrayList<Map<String,Object>>(entityList.size())); | ||
| 515 | jdbcTemplateWrite.update(new PreparedStatementCreator() { | 512 | jdbcTemplateWrite.update(new PreparedStatementCreator() { |
| 516 | @Override | 513 | @Override |
| 517 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { | 514 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { |
src/main/java/com/taover/repository/CustomJdbcTemplateBroadcast.java
| @@ -54,7 +54,6 @@ public class CustomJdbcTemplateBroadcast<T, ID extends Serializable> implements | @@ -54,7 +54,6 @@ public class CustomJdbcTemplateBroadcast<T, ID extends Serializable> implements | ||
| 54 | private String _tableName; | 54 | private String _tableName; |
| 55 | private Class<T> _tClassInfo; | 55 | private Class<T> _tClassInfo; |
| 56 | private CustomJdbcTemplateRowMapper<T> _customJdbcTemplateRowMapper; | 56 | private CustomJdbcTemplateRowMapper<T> _customJdbcTemplateRowMapper; |
| 57 | - private KeyHolder _keyHolder; | ||
| 58 | 57 | ||
| 59 | public CustomJdbcTemplateRowMapper<T> getCustomJdbcTemplateRowMapper(){ | 58 | public CustomJdbcTemplateRowMapper<T> getCustomJdbcTemplateRowMapper(){ |
| 60 | return this._customJdbcTemplateRowMapper; | 59 | return this._customJdbcTemplateRowMapper; |
| @@ -118,9 +117,6 @@ public class CustomJdbcTemplateBroadcast<T, ID extends Serializable> implements | @@ -118,9 +117,6 @@ public class CustomJdbcTemplateBroadcast<T, ID extends Serializable> implements | ||
| 118 | 117 | ||
| 119 | //创建rowmapper | 118 | //创建rowmapper |
| 120 | this._customJdbcTemplateRowMapper = new CustomJdbcTemplateRowMapper<T>(this._tClassInfo, this._tableToBeanField); | 119 | this._customJdbcTemplateRowMapper = new CustomJdbcTemplateRowMapper<T>(this._tClassInfo, this._tableToBeanField); |
| 121 | - | ||
| 122 | - //主键ID保存 | ||
| 123 | - this._keyHolder = new GeneratedKeyHolder(); | ||
| 124 | } | 120 | } |
| 125 | 121 | ||
| 126 | /** | 122 | /** |
| @@ -397,6 +393,7 @@ public class CustomJdbcTemplateBroadcast<T, ID extends Serializable> implements | @@ -397,6 +393,7 @@ public class CustomJdbcTemplateBroadcast<T, ID extends Serializable> implements | ||
| 397 | 393 | ||
| 398 | //执行SQL | 394 | //执行SQL |
| 399 | String exeSql = sqlInsertPart.substring(0, sqlInsertPart.length()-1)+sqlColumnPart.substring(0, sqlColumnPart.length()-1)+")"; | 395 | String exeSql = sqlInsertPart.substring(0, sqlInsertPart.length()-1)+sqlColumnPart.substring(0, sqlColumnPart.length()-1)+")"; |
| 396 | + KeyHolder _keyHolder = new GeneratedKeyHolder(new ArrayList<Map<String,Object>>(1)); | ||
| 400 | _jdbcTemplateBroadcast.update(new PreparedStatementCreator() { | 397 | _jdbcTemplateBroadcast.update(new PreparedStatementCreator() { |
| 401 | @Override | 398 | @Override |
| 402 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { | 399 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { |
| @@ -447,6 +444,7 @@ public class CustomJdbcTemplateBroadcast<T, ID extends Serializable> implements | @@ -447,6 +444,7 @@ public class CustomJdbcTemplateBroadcast<T, ID extends Serializable> implements | ||
| 447 | exeSql.setCharAt(exeSql.length()-1, ';'); | 444 | exeSql.setCharAt(exeSql.length()-1, ';'); |
| 448 | 445 | ||
| 449 | //调用更新接口 | 446 | //调用更新接口 |
| 447 | + KeyHolder _keyHolder = new GeneratedKeyHolder(new ArrayList<Map<String,Object>>(entityList.size())); | ||
| 450 | _jdbcTemplateBroadcast.update(new PreparedStatementCreator() { | 448 | _jdbcTemplateBroadcast.update(new PreparedStatementCreator() { |
| 451 | @Override | 449 | @Override |
| 452 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { | 450 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { |
src/main/java/com/taover/repository/CustomJdbcTemplateWrapperTenant.java
| @@ -54,7 +54,6 @@ public class CustomJdbcTemplateWrapperTenant<T, ID extends Serializable> impleme | @@ -54,7 +54,6 @@ public class CustomJdbcTemplateWrapperTenant<T, ID extends Serializable> impleme | ||
| 54 | private String _tableName; | 54 | private String _tableName; |
| 55 | private Class<T> _tClassInfo; | 55 | private Class<T> _tClassInfo; |
| 56 | private CustomJdbcTemplateRowMapper<T> _customJdbcTemplateRowMapper; | 56 | private CustomJdbcTemplateRowMapper<T> _customJdbcTemplateRowMapper; |
| 57 | - private KeyHolder _keyHolder; | ||
| 58 | 57 | ||
| 59 | public CustomJdbcTemplateRowMapper<T> getCustomJdbcTemplateRowMapper(){ | 58 | public CustomJdbcTemplateRowMapper<T> getCustomJdbcTemplateRowMapper(){ |
| 60 | return this._customJdbcTemplateRowMapper; | 59 | return this._customJdbcTemplateRowMapper; |
| @@ -118,9 +117,6 @@ public class CustomJdbcTemplateWrapperTenant<T, ID extends Serializable> impleme | @@ -118,9 +117,6 @@ public class CustomJdbcTemplateWrapperTenant<T, ID extends Serializable> impleme | ||
| 118 | 117 | ||
| 119 | //创建rowmapper | 118 | //创建rowmapper |
| 120 | this._customJdbcTemplateRowMapper = new CustomJdbcTemplateRowMapper<T>(this._tClassInfo, this._tableToBeanField); | 119 | this._customJdbcTemplateRowMapper = new CustomJdbcTemplateRowMapper<T>(this._tClassInfo, this._tableToBeanField); |
| 121 | - | ||
| 122 | - //主键ID保存 | ||
| 123 | - this._keyHolder = new GeneratedKeyHolder(); | ||
| 124 | } | 120 | } |
| 125 | 121 | ||
| 126 | /** | 122 | /** |
| @@ -399,6 +395,7 @@ public class CustomJdbcTemplateWrapperTenant<T, ID extends Serializable> impleme | @@ -399,6 +395,7 @@ public class CustomJdbcTemplateWrapperTenant<T, ID extends Serializable> impleme | ||
| 399 | 395 | ||
| 400 | //执行SQL | 396 | //执行SQL |
| 401 | String exeSql = sqlInsertPart.substring(0, sqlInsertPart.length()-1)+sqlColumnPart.substring(0, sqlColumnPart.length()-1)+")"; | 397 | String exeSql = sqlInsertPart.substring(0, sqlInsertPart.length()-1)+sqlColumnPart.substring(0, sqlColumnPart.length()-1)+")"; |
| 398 | + KeyHolder _keyHolder = new GeneratedKeyHolder(new ArrayList<Map<String,Object>>(1)); | ||
| 402 | _jdbcTemplateWrapperTenant.update(new PreparedStatementCreator() { | 399 | _jdbcTemplateWrapperTenant.update(new PreparedStatementCreator() { |
| 403 | @Override | 400 | @Override |
| 404 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { | 401 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { |
| @@ -449,6 +446,7 @@ public class CustomJdbcTemplateWrapperTenant<T, ID extends Serializable> impleme | @@ -449,6 +446,7 @@ public class CustomJdbcTemplateWrapperTenant<T, ID extends Serializable> impleme | ||
| 449 | exeSql.setCharAt(exeSql.length()-1, ';'); | 446 | exeSql.setCharAt(exeSql.length()-1, ';'); |
| 450 | 447 | ||
| 451 | //调用更新接口 | 448 | //调用更新接口 |
| 449 | + KeyHolder _keyHolder = new GeneratedKeyHolder(new ArrayList<Map<String,Object>>(entityList.size())); | ||
| 452 | _jdbcTemplateWrapperTenant.update(new PreparedStatementCreator() { | 450 | _jdbcTemplateWrapperTenant.update(new PreparedStatementCreator() { |
| 453 | @Override | 451 | @Override |
| 454 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { | 452 | public PreparedStatement createPreparedStatement(Connection con) throws SQLException { |