From 5f91958ddb7e0472706ea54bcf4aabdc724e6e68 Mon Sep 17 00:00:00 2001 From: houxy Date: Thu, 14 Nov 2019 13:34:22 +0800 Subject: [PATCH] #49 --- .../io/github/biezhi/anima/core/AnimaQuery.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/biezhi/anima/core/AnimaQuery.java b/src/main/java/io/github/biezhi/anima/core/AnimaQuery.java index c14693e..2d12ac8 100755 --- a/src/main/java/io/github/biezhi/anima/core/AnimaQuery.java +++ b/src/main/java/io/github/biezhi/anima/core/AnimaQuery.java @@ -831,7 +831,7 @@ public T one() { */ public List all() { this.beforeCheck(); - String sql = this.buildSelectSQL(true); + String sql = this.buildSelectSQL(true); List models = this.queryList(modelClass, sql, paramValues); this.setJoin(models); return models; @@ -1228,8 +1228,8 @@ public int execute(String sql, List params) { */ public ResultKey save(S model) { List columnValues = AnimaUtils.toColumnValues(model, true); - String sql = this.buildInsertSQL(model, columnValues); - Connection conn = getConn(); + String sql = this.buildInsertSQL(model, columnValues); + Connection conn = getConn(); try { List params = columnValues.stream() @@ -1277,7 +1277,7 @@ public int deleteById(S id) { */ public int deleteByModel(S model) { this.beforeCheck(); - String sql = this.buildDeleteSQL(model); + String sql = this.buildDeleteSQL(model); List columnValueList = AnimaUtils.toColumnValues(model, false); return this.execute(sql, columnValueList); } @@ -1289,7 +1289,7 @@ public int deleteByModel(S model) { */ public int update() { this.beforeCheck(); - String sql = this.buildUpdateSQL(null, updateColumns); + String sql = this.buildUpdateSQL(null, updateColumns); List columnValueList = new ArrayList<>(); updateColumns.forEach((key, value) -> columnValueList.add(value)); columnValueList.addAll(paramValues); @@ -1317,7 +1317,7 @@ public int updateById(Serializable id) { */ public int updateById(S model, Serializable id) { this.where(primaryKeyColumn, id); - String sql = this.buildUpdateSQL(model, null); + String sql = this.buildUpdateSQL(model, null); List columnValueList = AnimaUtils.toColumnValues(model, false); columnValueList.add(id); return this.execute(sql, columnValueList); @@ -1493,7 +1493,10 @@ private void beforeCheck() { */ private Connection getConn() { Connection connection = localConnection.get(); - return ifNotNullReturn(connection, connection, this.getSql2o().open()); + if (connection != null) { + return connection; + } + return getSql2o().open(); } /**