Skip to content

Commit

Permalink
修正ddl.xlib中增加tenant id的sql语句生成代码
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Nov 7, 2023
1 parent 04d3de4 commit cf17d78
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 10 deletions.
20 changes: 16 additions & 4 deletions nop-core/src/main/java/io/nop/core/lang/sql/SqlHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.nop.commons.text.marker.IMarkedString;
import io.nop.commons.text.marker.Markers;
import io.nop.commons.util.CharSequenceHelper;
import io.nop.commons.util.StringHelper;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -119,18 +120,29 @@ public static List<SQL> splitSql(IMarkedString str, Supplier<SQL.SqlBuilder> cre
if (c == ';') {
SQL.SqlBuilder part = creator.get();
part.appendRange(str, startPos, i);
ret.add(part.end());
if (part.isEmpty())
continue;
SQL sql = part.end();
if (StringHelper.isBlank(sql.getText()))
continue;
ret.add(sql);
i++;
i = CharSequenceHelper.skipWhitespace(statement, i);
startPos = i;
} else {
i++;
}
}
if (i != n) {
if (startPos != n) {
SQL.SqlBuilder part = creator.get();
part.appendRange(str, i, n);
ret.add(part.end());
part.appendRange(str, startPos, n);

if (!part.isEmpty()) {
SQL sql = part.end();
if (!StringHelper.isBlank(sql.getText())) {
ret.add(sql);
}
}
}

return ret;
Expand Down
19 changes: 19 additions & 0 deletions nop-core/src/test/java/io/nop/core/lang/sql/TestSqlHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.nop.core.lang.sql;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestSqlHelper {
@Test
public void testSplit() {
String text = "\n select o where a=';' ; \n select b; ss";
List<SQL> sqls = SqlHelper.splitSqlText(text);
assertEquals(3, sqls.size());
assertEquals("\n select o where a=';' ", sqls.get(0).getText());
assertEquals("select b", sqls.get(1).getText());
assertEquals("ss", sqls.get(2).getText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5544,6 +5544,19 @@
"io.nop.http.api.server.IHttpServerContext"
]
},
{
"name": "getUserContextAsync",
"parameterTypes": [
"io.nop.auth.core.login.AuthToken"
]
},
{
"name": "handlePublicPath",
"parameterTypes": [
"io.nop.http.api.server.IHttpServerContext",
"java.util.function.Supplier"
]
},
{
"name": "handleUserContext",
"parameterTypes": [
Expand Down Expand Up @@ -5578,6 +5591,12 @@
"io.nop.auth.core.login.AuthToken"
]
},
{
"name": "loginWithOAuthCode",
"parameterTypes": [
"io.nop.http.api.server.IHttpServerContext"
]
},
{
"name": "order",
"parameterTypes": []
Expand Down Expand Up @@ -7097,11 +7116,31 @@
"allowWrite": false,
"name": "PROP_ID_createdBy"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_ID_credential"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_ID_delFlag"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_ID_extId"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_ID_lastLoginIp"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_ID_lastLoginTime"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
Expand All @@ -7117,6 +7156,11 @@
"allowWrite": false,
"name": "PROP_ID_remark"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_ID_sid"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
Expand All @@ -7132,6 +7176,11 @@
"allowWrite": false,
"name": "PROP_ID_userId"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_ID_verified"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
Expand All @@ -7147,11 +7196,31 @@
"allowWrite": false,
"name": "PROP_NAME_createdBy"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_NAME_credential"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_NAME_delFlag"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_NAME_extId"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_NAME_lastLoginIp"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_NAME_lastLoginTime"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
Expand All @@ -7167,6 +7236,11 @@
"allowWrite": false,
"name": "PROP_NAME_remark"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_NAME_sid"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
Expand All @@ -7187,6 +7261,11 @@
"allowWrite": false,
"name": "PROP_NAME_userId"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
"name": "PROP_NAME_verified"
},
{
"allowUnsafeAccess": false,
"allowWrite": false,
Expand All @@ -7206,10 +7285,26 @@
"name": "getCreatedBy",
"parameterTypes": []
},
{
"name": "getCredential",
"parameterTypes": []
},
{
"name": "getDelFlag",
"parameterTypes": []
},
{
"name": "getExtId",
"parameterTypes": []
},
{
"name": "getLastLoginIp",
"parameterTypes": []
},
{
"name": "getLastLoginTime",
"parameterTypes": []
},
{
"name": "getLoginType",
"parameterTypes": []
Expand All @@ -7222,6 +7317,10 @@
"name": "getRemark",
"parameterTypes": []
},
{
"name": "getSid",
"parameterTypes": []
},
{
"name": "getUpdateTime",
"parameterTypes": []
Expand All @@ -7238,6 +7337,10 @@
"name": "getUserId",
"parameterTypes": []
},
{
"name": "getVerified",
"parameterTypes": []
},
{
"name": "getVersion",
"parameterTypes": []
Expand Down Expand Up @@ -7308,12 +7411,36 @@
"java.lang.String"
]
},
{
"name": "setCredential",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "setDelFlag",
"parameterTypes": [
"java.lang.Byte"
]
},
{
"name": "setExtId",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "setLastLoginIp",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "setLastLoginTime",
"parameterTypes": [
"java.sql.Timestamp"
]
},
{
"name": "setLoginType",
"parameterTypes": [
Expand All @@ -7332,6 +7459,12 @@
"java.lang.String"
]
},
{
"name": "setSid",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "setUpdateTime",
"parameterTypes": [
Expand All @@ -7356,6 +7489,12 @@
"java.lang.String"
]
},
{
"name": "setVerified",
"parameterTypes": [
"java.lang.Boolean"
]
},
{
"name": "setVersion",
"parameterTypes": [
Expand Down Expand Up @@ -16071,6 +16210,13 @@
"int"
]
},
{
"name": "newConfig",
"parameterTypes": [
"int",
"long"
]
},
{
"name": "setAsync",
"parameterTypes": [
Expand Down Expand Up @@ -50665,6 +50811,13 @@
"java.lang.String"
]
},
{
"name": "findSeqItem",
"parameterTypes": [
"java.lang.String",
"boolean"
]
},
{
"name": "generateLong",
"parameterTypes": [
Expand All @@ -50689,6 +50842,12 @@
"java.lang.String"
]
},
{
"name": "removeCache",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "runLocal",
"parameterTypes": [
Expand Down
17 changes: 16 additions & 1 deletion nop-orm/src/main/java/io/nop/orm/ddl/DdlSqlCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static String getDmlLibPath(String dialectName) {
}
if (dialectName.indexOf('.') > 0) {
String basePath = "/nop/orm/xlib/ddl/ddl_" + StringHelper.firstPart(dialectName, '.') + ".xlib";
if(VirtualFileSystem.instance().getResource(basePath).exists())
if (VirtualFileSystem.instance().getResource(basePath).exists())
return basePath;
}
return path;
Expand Down Expand Up @@ -103,6 +103,21 @@ public String addTenantIdForTables(Collection<? extends IEntityModel> tables) {
return XLang.getTagAction(dmlLibPath, "AddTenantIdForTables").generateText(XLang.newEvalScope(args));
}

public String addTenantIdForTable(IEntityModel table, boolean addToPk) {
Map<String, Object> args = new HashMap<>();
args.put("table", table);
args.put("dialect", dialect);
args.put("addToPk", addToPk);
return XLang.getTagAction(dmlLibPath, "AddTenantIdForTable").generateText(XLang.newEvalScope(args));
}

public String addTenantIdToPrimaryKey(IEntityModel table) {
Map<String, Object> args = new HashMap<>();
args.put("table", table);
args.put("dialect", dialect);
return XLang.getTagAction(dmlLibPath, "AddTenantIdToPrimaryKey").generateText(XLang.newEvalScope(args));
}

public String addColumn(IColumnModel col) {
Map<String, Object> args = new HashMap<>();
args.put("col", col);
Expand Down
Loading

0 comments on commit cf17d78

Please sign in to comment.