From ef9eaa0a66ed5080923a8bf6a4284f4568f7e9ba Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Thu, 28 Dec 2017 10:16:21 +0800 Subject: [PATCH] =?UTF-8?q?DataSource.updateColumn=E7=B3=BB=E5=88=97?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=B1=8F=E8=94=BD=E6=8E=89limit=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/source/DataJdbcSource.java | 18 +++++++++++++----- src/org/redkale/source/DataSource.java | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/org/redkale/source/DataJdbcSource.java b/src/org/redkale/source/DataJdbcSource.java index bb015da02..99e177878 100644 --- a/src/org/redkale/source/DataJdbcSource.java +++ b/src/org/redkale/source/DataJdbcSource.java @@ -109,27 +109,33 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC } @Override + @Local public void close() throws Exception { readPool.close(); writePool.close(); } + @Local public PoolJdbcSource getReadPoolJdbcSource() { return readPool; } + @Local public PoolJdbcSource getWritePoolJdbcSource() { return writePool; } + @Local public Connection createReadSQLConnection() { return readPool.poll(); } + @Local public Connection createWriteSQLConnection() { return writePool.poll(); } + @Local public void closeSQLConnection(final Connection sqlconn) { if (sqlconn == null) return; try { @@ -140,6 +146,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC } @Override + @Local public EntityInfo apply(Class t) { return loadEntityInfo(t); } @@ -972,9 +979,8 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC } String sql = "UPDATE " + info.getTable(node) + " a " + (join1 == null ? "" : (", " + join1)) + " SET " + setsql + ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2)) - : (" WHERE " + where + (join2 == null ? "" : (" AND " + join2)))); - //注:LIMIT 仅支持MySQL 且在多表关联式会异常, 该BUG尚未解决 - sql += info.createSQLOrderby(flipper) + ((flipper == null || flipper.getLimit() < 1) ? "" : (" LIMIT " + flipper.getLimit())); + : (" WHERE " + where + (join2 == null ? "" : (" AND " + join2)))) + + info.createSQLOrderby(flipper); if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql); conn.setReadOnly(false); if (blobs != null) { @@ -2369,7 +2375,8 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC * * @return 结果数组 */ - public final int[] directExecute(String... sqls) { + @Local + public int[] directExecute(String... sqls) { Connection conn = createWriteSQLConnection(); try { return directExecute(conn, sqls); @@ -2385,7 +2392,8 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC * @param sql SQL语句 * @param consumer 回调函数 */ - public final void directQuery(String sql, Consumer consumer) { + @Local + public void directQuery(String sql, Consumer consumer) { final Connection conn = createReadSQLConnection(); try { if (logger.isLoggable(Level.FINEST)) logger.finest("direct query sql=" + sql); diff --git a/src/org/redkale/source/DataSource.java b/src/org/redkale/source/DataSource.java index 9a3fa9b85..ab7e2ae4b 100644 --- a/src/org/redkale/source/DataSource.java +++ b/src/org/redkale/source/DataSource.java @@ -300,7 +300,7 @@ public interface DataSource { * 更新符合过滤条件的记录的指定字段
* Flipper中offset字段将被忽略
* 注意:Entity类中标记为@Column(updatable=false)不会被更新
- * 等价SQL: UPDATE {table} SET {column1} = {value1}, {column2} += {value2}, {column3} *= {value3}, ··· WHERE {filter node} ORDER BY {flipper.sort} LIMIT {flipper.limit}
+ * 等价SQL: UPDATE {table} SET {column1} = {value1}, {column2} += {value2}, {column3} *= {value3}, ··· WHERE {filter node} ORDER BY {flipper.sort}
* * @param Entity泛型 * @param clazz Entity类 @@ -316,7 +316,7 @@ public interface DataSource { * 更新符合过滤条件的记录的指定字段
* Flipper中offset字段将被忽略
* 注意:Entity类中标记为@Column(updatable=false)不会被更新
- * 等价SQL: UPDATE {table} SET {column1} = {value1}, {column2} += {value2}, {column3} *= {value3}, ··· WHERE {filter node} ORDER BY {flipper.sort} LIMIT {flipper.limit}
+ * 等价SQL: UPDATE {table} SET {column1} = {value1}, {column2} += {value2}, {column3} *= {value3}, ··· WHERE {filter node} ORDER BY {flipper.sort}
* * @param Entity泛型 * @param clazz Entity类