DataSqlSource 变量由${}改成#{}, 为了区别于配置项${}

This commit is contained in:
redkale
2023-05-08 14:29:23 +08:00
parent de7c5e84f4
commit 6ff04b408c
9 changed files with 50 additions and 55 deletions

View File

@@ -103,7 +103,7 @@
</script>
<script>
var jsoncontent = '${content}'; //这里必须要用单引号引起来
var jsoncontent = '#{content}'; //这里必须要用单引号引起来
document.write(createhtml(jsoncontent));
</script>
</body>

View File

@@ -29,12 +29,12 @@
<property name="javax.persistence.connections.limit" value="12"/>
<!-- 包含的SQL模板相当于反向LIKE不同的JDBC驱动的SQL语句不一样Redkale内置了MySQL的语句 -->
<property name="javax.persistence.contain.sqltemplate" value="LOCATE(${keystr}, ${column}) > 0"/>
<property name="javax.persistence.notcontain.sqltemplate" value="LOCATE(${keystr}, ${column}) = 0"/>
<property name="javax.persistence.contain.sqltemplate" value="LOCATE(#{keystr}, #{column}) > 0"/>
<property name="javax.persistence.notcontain.sqltemplate" value="LOCATE(#{keystr}, #{column}) = 0"/>
<!-- 复制表结构的SQL模板Redkale内置了MySQL的语句 -->
<property name="javax.persistence.tablenotexist.sqlstates" value="42000;42S02"/>
<property name="javax.persistence.tablecopy.sqltemplate" value="CREATE TABLE IF NOT EXISTS ${newtable} LIKE ${oldtable}"/>
<property name="javax.persistence.tablecopy.sqltemplate" value="CREATE TABLE IF NOT EXISTS #{newtable} LIKE #{oldtable}"/>
</properties>
</persistence-unit>

View File

@@ -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

View File

@@ -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));

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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

View File

@@ -598,9 +598,9 @@ public final class EntityInfo<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
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<T> {
if (this.tableStrategy == null) {
return deleteNamesPrepareSQL;
}
return deleteNamesPrepareSQL.replace("${newtable}", getTable(bean));
return deleteNamesPrepareSQL.replace("#{newtable}", getTable(bean));
}
/**

View File

@@ -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