From 6ff04b408c619e5949bc5a03b6ccddc39abc691c Mon Sep 17 00:00:00 2001 From: redkale Date: Mon, 8 May 2023 14:29:23 +0800 Subject: [PATCH] =?UTF-8?q?DataSqlSource=20=E5=8F=98=E9=87=8F=E7=94=B1${}?= =?UTF-8?q?=E6=94=B9=E6=88=90#{},=20=E4=B8=BA=E4=BA=86=E5=8C=BA=E5=88=AB?= =?UTF-8?q?=E4=BA=8E=E9=85=8D=E7=BD=AE=E9=A1=B9${}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/META-INF/apidoc-template.html | 2 +- .../java/META-INF/persistence-template.xml | 6 +-- .../java/META-INF/source-template.properties | 6 +-- .../java/org/redkale/boot/ApiDocCommand.java | 2 +- .../java/org/redkale/boot/NodeServer.java | 3 ++ .../org/redkale/mq/SncpMessageResponse.java | 8 ---- .../redkale/source/AbstractDataSqlSource.java | 22 ++++----- .../java/org/redkale/source/EntityInfo.java | 48 +++++++++---------- .../java/org/redkale/source/FilterNode.java | 8 ++-- 9 files changed, 50 insertions(+), 55 deletions(-) diff --git a/src/main/java/META-INF/apidoc-template.html b/src/main/java/META-INF/apidoc-template.html index 755dfc2e7..94f3f36fe 100644 --- a/src/main/java/META-INF/apidoc-template.html +++ b/src/main/java/META-INF/apidoc-template.html @@ -103,7 +103,7 @@ diff --git a/src/main/java/META-INF/persistence-template.xml b/src/main/java/META-INF/persistence-template.xml index 68b0c8e42..e4695f1ad 100644 --- a/src/main/java/META-INF/persistence-template.xml +++ b/src/main/java/META-INF/persistence-template.xml @@ -29,12 +29,12 @@ - - + + - + diff --git a/src/main/java/META-INF/source-template.properties b/src/main/java/META-INF/source-template.properties index 248be2027..33c38ebc5 100644 --- a/src/main/java/META-INF/source-template.properties +++ b/src/main/java/META-INF/source-template.properties @@ -31,13 +31,13 @@ redkale.datasource.platf.url = jdbc:mysql://127.0.0.1:3306/platf?allowPublicKeyR # \u6700\u5927\u8fde\u63a5\u6570\uff0c\u9ed8\u8ba4\u503c\uff1aCPU\u6570 redkale.datasource.platf.maxconns = 16 # \u5305\u542b\u7684SQL\u6a21\u677f\uff0c\u76f8\u5f53\u4e8e\u53cd\u5411LIKE\uff0c\u4e0d\u540c\u7684JDBC\u9a71\u52a8\u7684SQL\u8bed\u53e5\u4e0d\u4e00\u6837\uff0cRedkale\u5185\u7f6e\u4e86MySQL\u7684\u8bed\u53e5 -redkale.datasource.platf.contain-sqltemplate = LOCATE(${keystr}, ${column}) > 0 +redkale.datasource.platf.contain-sqltemplate = LOCATE(#{keystr}, #{column}) > 0 # \u5305\u542b\u7684SQL\u6a21\u677f\uff0c\u76f8\u5f53\u4e8e\u53cd\u5411LIKE\uff0c\u4e0d\u540c\u7684JDBC\u9a71\u52a8\u7684SQL\u8bed\u53e5\u4e0d\u4e00\u6837\uff0cRedkale\u5185\u7f6e\u4e86MySQL\u7684\u8bed\u53e5 -redkale.datasource.platf.notcontain-sqltemplate = LOCATE(${keystr}, ${column}) = 0 +redkale.datasource.platf.notcontain-sqltemplate = LOCATE(#{keystr}, #{column}) = 0 # \u590d\u5236\u8868\u7ed3\u6784\u7684SQL\u6a21\u677f\uff0cRedkale\u5185\u7f6e\u4e86MySQL\u7684\u8bed\u53e5 redkale.datasource.platf.tablenotexist-sqlstates = 42000;42S02 # \u590d\u5236\u8868\u7ed3\u6784\u7684SQL\u6a21\u677f\uff0cRedkale\u5185\u7f6e\u4e86MySQL\u7684\u8bed\u53e5 -redkale.datasource.platf.tablecopy-sqltemplate = CREATE TABLE IF NOT EXISTS ${newtable} LIKE ${oldtable} +redkale.datasource.platf.tablecopy-sqltemplate = CREATE TABLE IF NOT EXISTS #{newtable} LIKE #{oldtable} # DataSource \u8bfb\u5199\u5206\u79bb diff --git a/src/main/java/org/redkale/boot/ApiDocCommand.java b/src/main/java/org/redkale/boot/ApiDocCommand.java index b63ec2b1d..617c40b89 100644 --- a/src/main/java/org/redkale/boot/ApiDocCommand.java +++ b/src/main/java/org/redkale/boot/ApiDocCommand.java @@ -356,7 +356,7 @@ public final class ApiDocCommand { in = new FileInputStream(doctemplate); } if (in != null) { - String content = Utility.read(in).replace("'${content}'", json); + String content = Utility.read(in).replace("'#{content}'", json); in.close(); FileOutputStream outhtml = new FileOutputStream(new File(app.getHome(), "apidoc.html")); outhtml.write(content.getBytes(StandardCharsets.UTF_8)); diff --git a/src/main/java/org/redkale/boot/NodeServer.java b/src/main/java/org/redkale/boot/NodeServer.java index e569bc581..5f0d80a35 100644 --- a/src/main/java/org/redkale/boot/NodeServer.java +++ b/src/main/java/org/redkale/boot/NodeServer.java @@ -338,6 +338,9 @@ public abstract class NodeServer { } DataSource source = application.loadDataSource(resourceName, false); field.set(srcObj, source); + if (source instanceof DataSqlSource) { + rf.register(resourceName, DataSqlSource.class, source); + } return source; } catch (Exception e) { logger.log(Level.SEVERE, "DataSource inject to " + srcObj + " error", e); diff --git a/src/main/java/org/redkale/mq/SncpMessageResponse.java b/src/main/java/org/redkale/mq/SncpMessageResponse.java index e3e027d70..db98c9880 100644 --- a/src/main/java/org/redkale/mq/SncpMessageResponse.java +++ b/src/main/java/org/redkale/mq/SncpMessageResponse.java @@ -36,14 +36,6 @@ public class SncpMessageResponse extends SncpResponse { this.producer = producer; } - public SncpMessageResponse(SncpContext context, MessageRecord message, Runnable callback, MessageClient messageClient, MessageClientProducer producer) { - super(context, new SncpMessageRequest(context, message)); - this.message = message; - this.callback = callback; - this.messageClient = messageClient; - this.producer = producer; - } - @Override public void finish(final int retcode, final BsonWriter out) { if (callback != null) { diff --git a/src/main/java/org/redkale/source/AbstractDataSqlSource.java b/src/main/java/org/redkale/source/AbstractDataSqlSource.java index 9938abcba..1ef970a35 100644 --- a/src/main/java/org/redkale/source/AbstractDataSqlSource.java +++ b/src/main/java/org/redkale/source/AbstractDataSqlSource.java @@ -130,11 +130,11 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement protected void afterResourceChange() { this.autoDDL = "true".equals(readConfProps.getProperty(DATA_SOURCE_TABLE_AUTODDL, "false").trim()); - this.containSQL = readConfProps.getProperty(DATA_SOURCE_CONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) > 0"); - this.notContainSQL = readConfProps.getProperty(DATA_SOURCE_NOTCONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) = 0"); + this.containSQL = readConfProps.getProperty(DATA_SOURCE_CONTAIN_SQLTEMPLATE, "LOCATE(#{keystr}, #{column}) > 0"); + this.notContainSQL = readConfProps.getProperty(DATA_SOURCE_NOTCONTAIN_SQLTEMPLATE, "LOCATE(#{keystr}, #{column}) = 0"); this.tableNotExistSqlstates = ";" + readConfProps.getProperty(DATA_SOURCE_TABLENOTEXIST_SQLSTATES, "42000;42S02") + ";"; - this.tablecopySQL = readConfProps.getProperty(DATA_SOURCE_TABLECOPY_SQLTEMPLATE, "CREATE TABLE IF NOT EXISTS ${newtable} LIKE ${oldtable}"); + this.tablecopySQL = readConfProps.getProperty(DATA_SOURCE_TABLECOPY_SQLTEMPLATE, "CREATE TABLE IF NOT EXISTS #{newtable} LIKE #{oldtable}"); this.cacheForbidden = "NONE".equalsIgnoreCase(readConfProps.getProperty(DATA_SOURCE_CACHEMODE)); this.slowmsWarn = Integer.parseInt(readConfProps.getProperty(DATA_SOURCE_SLOWMS_WARN, "2000").trim()); @@ -265,23 +265,23 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement protected void initProperties(Properties props) { if ("oracle".equals(this.dbtype)) { - props.setProperty(DATA_SOURCE_CONTAIN_SQLTEMPLATE, "INSTR(${keystr}, ${column}) > 0"); - props.setProperty(DATA_SOURCE_NOTCONTAIN_SQLTEMPLATE, "INSTR(${keystr}, ${column}) = 0"); + props.setProperty(DATA_SOURCE_CONTAIN_SQLTEMPLATE, "INSTR(#{keystr}, #{column}) > 0"); + props.setProperty(DATA_SOURCE_NOTCONTAIN_SQLTEMPLATE, "INSTR(#{keystr}, #{column}) = 0"); if (!props.containsKey(DATA_SOURCE_TABLENOTEXIST_SQLSTATES)) { props.setProperty(DATA_SOURCE_TABLENOTEXIST_SQLSTATES, "42000;42S02"); } if (!props.containsKey(DATA_SOURCE_TABLECOPY_SQLTEMPLATE)) { //注意:此语句复制表结构会导致默认值和主键信息的丢失 - props.setProperty(DATA_SOURCE_TABLECOPY_SQLTEMPLATE, "CREATE TABLE IF NOT EXISTS ${newtable} AS SELECT * FROM ${oldtable} WHERE 1=2"); + props.setProperty(DATA_SOURCE_TABLECOPY_SQLTEMPLATE, "CREATE TABLE IF NOT EXISTS #{newtable} AS SELECT * FROM #{oldtable} WHERE 1=2"); } } else if ("sqlserver".equals(this.dbtype)) { - props.setProperty(DATA_SOURCE_CONTAIN_SQLTEMPLATE, "CHARINDEX(${column}, ${keystr}) > 0"); - props.setProperty(DATA_SOURCE_NOTCONTAIN_SQLTEMPLATE, "CHARINDEX(${column}, ${keystr}) = 0"); + props.setProperty(DATA_SOURCE_CONTAIN_SQLTEMPLATE, "CHARINDEX(#{column}, #{keystr}) > 0"); + props.setProperty(DATA_SOURCE_NOTCONTAIN_SQLTEMPLATE, "CHARINDEX(#{column}, #{keystr}) = 0"); } else if ("postgresql".equals(this.dbtype)) { if (!props.containsKey(DATA_SOURCE_TABLECOPY_SQLTEMPLATE)) { //注意:此语句复制表结构会导致默认值和主键信息的丢失 //注意:postgresql不支持跨库复制表结构 - //props.setProperty(DATA_SOURCE_TABLECOPY_SQLTEMPLATE, "CREATE TABLE ${newtable} AS (SELECT * FROM ${oldtable} LIMIT 0)"); - props.setProperty(DATA_SOURCE_TABLECOPY_SQLTEMPLATE, "CREATE TABLE IF NOT EXISTS ${newtable} (LIKE ${oldtable} INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING COMMENTS INCLUDING INDEXES)"); + //props.setProperty(DATA_SOURCE_TABLECOPY_SQLTEMPLATE, "CREATE TABLE #{newtable} AS (SELECT * FROM #{oldtable} LIMIT 0)"); + props.setProperty(DATA_SOURCE_TABLECOPY_SQLTEMPLATE, "CREATE TABLE IF NOT EXISTS #{newtable} (LIKE #{oldtable} INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING COMMENTS INCLUDING INDEXES)"); } if (!props.containsKey(DATA_SOURCE_TABLENOTEXIST_SQLSTATES)) { props.setProperty(DATA_SOURCE_TABLENOTEXIST_SQLSTATES, "42P01;3F000"); @@ -573,7 +573,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement @Local protected String getTableCopySQL(EntityInfo info, String newTable) { - return tablecopySQL.replace("${newtable}", newTable).replace("${oldtable}", info.table); + return tablecopySQL.replace("#{newtable}", newTable).replace("#{oldtable}", info.table); } @Local diff --git a/src/main/java/org/redkale/source/EntityInfo.java b/src/main/java/org/redkale/source/EntityInfo.java index 7f4a5d0fe..2c6f8e3e9 100644 --- a/src/main/java/org/redkale/source/EntityInfo.java +++ b/src/main/java/org/redkale/source/EntityInfo.java @@ -598,9 +598,9 @@ public final class EntityInfo { insertsbdollar.append("$").append(++index); insertsbnames.append(":").append(col); } - this.insertQuestionPrepareSQL = "INSERT INTO " + (this.tableStrategy == null ? table : "${newtable}") + "(" + insertsb + ") VALUES(" + insertsbquestion + ")"; - this.insertDollarPrepareSQL = "INSERT INTO " + (this.tableStrategy == null ? table : "${newtable}") + "(" + insertsb + ") VALUES(" + insertsbdollar + ")"; - this.insertNamesPrepareSQL = "INSERT INTO " + (this.tableStrategy == null ? table : "${newtable}") + "(" + insertsb + ") VALUES(" + insertsbnames + ")"; + this.insertQuestionPrepareSQL = "INSERT INTO " + (this.tableStrategy == null ? table : "#{newtable}") + "(" + insertsb + ") VALUES(" + insertsbquestion + ")"; + this.insertDollarPrepareSQL = "INSERT INTO " + (this.tableStrategy == null ? table : "#{newtable}") + "(" + insertsb + ") VALUES(" + insertsbdollar + ")"; + this.insertNamesPrepareSQL = "INSERT INTO " + (this.tableStrategy == null ? table : "#{newtable}") + "(" + insertsb + ") VALUES(" + insertsbnames + ")"; StringBuilder updatesbquestion = new StringBuilder(); StringBuilder updatesbdollar = new StringBuilder(); StringBuilder updatesbnames = new StringBuilder(); @@ -615,12 +615,12 @@ public final class EntityInfo { updatesbdollar.append(col).append(" = ").append("$").append(++index); updatesbnames.append(col).append(" = :").append(col); } - this.updateQuestionPrepareSQL = "UPDATE " + (this.tableStrategy == null ? table : "${newtable}") + " SET " + updatesbquestion + " WHERE " + getPrimarySQLColumn(null) + " = ?"; - this.updateDollarPrepareSQL = "UPDATE " + (this.tableStrategy == null ? table : "${newtable}") + " SET " + updatesbdollar + " WHERE " + getPrimarySQLColumn(null) + " = $" + (++index); - this.updateNamesPrepareSQL = "UPDATE " + (this.tableStrategy == null ? table : "${newtable}") + " SET " + updatesbnames + " WHERE " + getPrimarySQLColumn(null) + " = :" + getPrimarySQLColumn(null); - this.deleteQuestionPrepareSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "${newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = ?"; - this.deleteDollarPrepareSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "${newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = $1"; - this.deleteNamesPrepareSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "${newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = :" + getPrimarySQLColumn(null); + this.updateQuestionPrepareSQL = "UPDATE " + (this.tableStrategy == null ? table : "#{newtable}") + " SET " + updatesbquestion + " WHERE " + getPrimarySQLColumn(null) + " = ?"; + this.updateDollarPrepareSQL = "UPDATE " + (this.tableStrategy == null ? table : "#{newtable}") + " SET " + updatesbdollar + " WHERE " + getPrimarySQLColumn(null) + " = $" + (++index); + this.updateNamesPrepareSQL = "UPDATE " + (this.tableStrategy == null ? table : "#{newtable}") + " SET " + updatesbnames + " WHERE " + getPrimarySQLColumn(null) + " = :" + getPrimarySQLColumn(null); + this.deleteQuestionPrepareSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "#{newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = ?"; + this.deleteDollarPrepareSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "#{newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = $1"; + this.deleteNamesPrepareSQL = "DELETE FROM " + (this.tableStrategy == null ? table : "#{newtable}") + " WHERE " + getPrimarySQLColumn(null) + " = :" + getPrimarySQLColumn(null); this.allQueryPrepareSQL = "SELECT " + querydb + " FROM " + table; this.findQuestionPrepareSQL = "SELECT " + querydb + " FROM " + table + " WHERE " + getPrimarySQLColumn(null) + " = ?"; this.findDollarPrepareSQL = "SELECT " + querydb + " FROM " + table + " WHERE " + getPrimarySQLColumn(null) + " = $1"; @@ -845,7 +845,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return findQuestionPrepareSQL; } - return findQuestionPrepareSQL.replace("${newtable}", getTable(pk)); + return findQuestionPrepareSQL.replace("#{newtable}", getTable(pk)); } /** @@ -859,7 +859,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return findsQuestionPrepareSQL; } - return findsQuestionPrepareSQL.replace("${newtable}", getTable(pk)); + return findsQuestionPrepareSQL.replace("#{newtable}", getTable(pk)); } /** @@ -883,7 +883,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return findDollarPrepareSQL; } - return findDollarPrepareSQL.replace("${newtable}", getTable(pk)); + return findDollarPrepareSQL.replace("#{newtable}", getTable(pk)); } /** @@ -897,7 +897,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return findsDollarPrepareSQL; } - return findsDollarPrepareSQL.replace("${newtable}", getTable(pk)); + return findsDollarPrepareSQL.replace("#{newtable}", getTable(pk)); } /** @@ -911,7 +911,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return findNamesPrepareSQL; } - return findNamesPrepareSQL.replace("${newtable}", getTable(pk)); + return findNamesPrepareSQL.replace("#{newtable}", getTable(pk)); } /** @@ -925,7 +925,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return findsNamesPrepareSQL; } - return findsNamesPrepareSQL.replace("${newtable}", getTable(pk)); + return findsNamesPrepareSQL.replace("#{newtable}", getTable(pk)); } /** @@ -939,7 +939,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return insertQuestionPrepareSQL; } - return insertQuestionPrepareSQL.replace("${newtable}", getTable(bean)); + return insertQuestionPrepareSQL.replace("#{newtable}", getTable(bean)); } /** @@ -953,7 +953,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return insertDollarPrepareSQL; } - return insertDollarPrepareSQL.replace("${newtable}", getTable(bean)); + return insertDollarPrepareSQL.replace("#{newtable}", getTable(bean)); } /** @@ -967,7 +967,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return insertNamesPrepareSQL; } - return insertNamesPrepareSQL.replace("${newtable}", getTable(bean)); + return insertNamesPrepareSQL.replace("#{newtable}", getTable(bean)); } /** @@ -981,7 +981,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return updateQuestionPrepareSQL; } - return updateQuestionPrepareSQL.replace("${newtable}", getTable(bean)); + return updateQuestionPrepareSQL.replace("#{newtable}", getTable(bean)); } /** @@ -995,7 +995,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return updateDollarPrepareSQL; } - return updateDollarPrepareSQL.replace("${newtable}", getTable(bean)); + return updateDollarPrepareSQL.replace("#{newtable}", getTable(bean)); } /** @@ -1049,7 +1049,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return updateNamesPrepareSQL; } - return updateNamesPrepareSQL.replace("${newtable}", getTable(bean)); + return updateNamesPrepareSQL.replace("#{newtable}", getTable(bean)); } /** @@ -1063,7 +1063,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return deleteQuestionPrepareSQL; } - return deleteQuestionPrepareSQL.replace("${newtable}", getTable(bean)); + return deleteQuestionPrepareSQL.replace("#{newtable}", getTable(bean)); } /** @@ -1077,7 +1077,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return deleteDollarPrepareSQL; } - return deleteDollarPrepareSQL.replace("${newtable}", getTable(bean)); + return deleteDollarPrepareSQL.replace("#{newtable}", getTable(bean)); } /** @@ -1091,7 +1091,7 @@ public final class EntityInfo { if (this.tableStrategy == null) { return deleteNamesPrepareSQL; } - return deleteNamesPrepareSQL.replace("${newtable}", getTable(bean)); + return deleteNamesPrepareSQL.replace("#{newtable}", getTable(bean)); } /** diff --git a/src/main/java/org/redkale/source/FilterNode.java b/src/main/java/org/redkale/source/FilterNode.java index 323d478d7..f66c6cdda 100644 --- a/src/main/java/org/redkale/source/FilterNode.java +++ b/src/main/java/org/redkale/source/FilterNode.java @@ -480,16 +480,16 @@ public class FilterNode { //FilterNode 不能实现Serializable接口, 否则 } StringBuilder sb = new StringBuilder(32); if (express == CONTAIN) { - return source.containSQL.replace("${column}", info.getSQLColumn(talis, column)).replace("${keystr}", val); + return source.containSQL.replace("#{column}", info.getSQLColumn(talis, column)).replace("#{keystr}", val); } if (express == IGNORECASECONTAIN) { - return source.containSQL.replace("${column}", "LOWER(" + info.getSQLColumn(talis, column) + ")").replace("${keystr}", val); + return source.containSQL.replace("#{column}", "LOWER(" + info.getSQLColumn(talis, column) + ")").replace("#{keystr}", val); } if (express == NOTCONTAIN) { - return source.notContainSQL.replace("${column}", info.getSQLColumn(talis, column)).replace("${keystr}", val); + return source.notContainSQL.replace("#{column}", info.getSQLColumn(talis, column)).replace("#{keystr}", val); } if (express == IGNORECASENOTCONTAIN) { - return source.notContainSQL.replace("${column}", "LOWER(" + info.getSQLColumn(talis, column) + ")").replace("${keystr}", val); + return source.notContainSQL.replace("#{column}", "LOWER(" + info.getSQLColumn(talis, column) + ")").replace("#{keystr}", val); } if (express == LENGTH_EQUAL || express == LENGTH_LESSTHAN || express == LENGTH_LESSTHANOREQUALTO