Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sqlrest
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
comm
sqlrest
Commits
2f6de5c1
Commit
2f6de5c1
authored
May 06, 2025
by
inrgihc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试问题修复
parent
beac5827
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
45 deletions
+76
-45
sqlrest-common/src/main/java/com/gitee/sqlrest/common/dto/ItemParam.java
+3
-3
sqlrest-common/src/main/java/com/gitee/sqlrest/common/dto/OutParam.java
+29
-0
sqlrest-core/src/main/java/com/gitee/sqlrest/core/service/ApiAssignmentService.java
+19
-7
sqlrest-template/src/main/java/com/gitee/sqlrest/template/XmlSqlTemplate.java
+6
-0
sqlrest-template/src/main/resources/script-1.0.dtd
+0
-35
sqlrest-template/src/test/java/com/gitee/sqlrest/template/TemplateTest.java
+19
-0
No files found.
sqlrest-common/src/main/java/com/gitee/sqlrest/common/dto/ItemParam.java
View file @
2f6de5c1
...
@@ -23,18 +23,18 @@ public class ItemParam extends BaseParam {
...
@@ -23,18 +23,18 @@ public class ItemParam extends BaseParam {
public
void
checkValid
()
{
public
void
checkValid
()
{
if
(
StringUtils
.
isBlank
(
getName
()))
{
if
(
StringUtils
.
isBlank
(
getName
()))
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
"parameter name must is not blank"
);
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
"
input
parameter name must is not blank"
);
}
}
if
(
getType
()
==
ParamTypeEnum
.
OBJECT
)
{
if
(
getType
()
==
ParamTypeEnum
.
OBJECT
)
{
if
(
null
!=
children
&&
children
.
size
()
>
0
)
{
if
(
null
!=
children
&&
children
.
size
()
>
0
)
{
for
(
BaseParam
param
:
children
)
{
for
(
BaseParam
param
:
children
)
{
if
(
StringUtils
.
isBlank
(
param
.
getName
()))
{
if
(
StringUtils
.
isBlank
(
param
.
getName
()))
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
"parameter name must is not blank"
);
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
"
input
parameter name must is not blank"
);
}
}
}
}
}
else
{
}
else
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
"Object
I
nput param '"
+
getName
()
+
"' must have child parameter."
);
"Object
i
nput param '"
+
getName
()
+
"' must have child parameter."
);
}
}
}
else
{
}
else
{
children
=
Collections
.
emptyList
();
children
=
Collections
.
emptyList
();
...
...
sqlrest-common/src/main/java/com/gitee/sqlrest/common/dto/OutParam.java
View file @
2f6de5c1
package
com
.
gitee
.
sqlrest
.
common
.
dto
;
package
com
.
gitee
.
sqlrest
.
common
.
dto
;
import
com.gitee.sqlrest.common.enums.ParamTypeEnum
;
import
com.gitee.sqlrest.common.enums.ParamTypeEnum
;
import
com.gitee.sqlrest.common.exception.CommonException
;
import
com.gitee.sqlrest.common.exception.ResponseErrorCode
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
org.apache.commons.lang3.StringUtils
;
@Data
@Data
@AllArgsConstructor
@AllArgsConstructor
...
@@ -32,4 +36,29 @@ public class OutParam implements Serializable {
...
@@ -32,4 +36,29 @@ public class OutParam implements Serializable {
@ApiModelProperty
(
"Object类型的子元素"
)
@ApiModelProperty
(
"Object类型的子元素"
)
private
List
<
OutParam
>
children
;
private
List
<
OutParam
>
children
;
public
void
checkValid
()
{
if
(
StringUtils
.
isBlank
(
getName
()))
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
"output parameter name must is not blank"
);
}
if
(
null
==
getType
())
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
"output parameter type must is not empty"
);
}
if
(
getType
()
==
ParamTypeEnum
.
OBJECT
)
{
if
(
null
!=
children
&&
children
.
size
()
>
0
)
{
for
(
OutParam
param
:
children
)
{
if
(
StringUtils
.
isBlank
(
param
.
getName
()))
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
"output parameter name must is not blank"
);
}
}
}
else
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
"Object output param '"
+
getName
()
+
"' must have child parameter."
);
}
}
else
{
children
=
Collections
.
emptyList
();
}
}
}
}
sqlrest-core/src/main/java/com/gitee/sqlrest/core/service/ApiAssignmentService.java
View file @
2f6de5c1
...
@@ -51,6 +51,7 @@ import java.util.HashMap;
...
@@ -51,6 +51,7 @@ import java.util.HashMap;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
...
@@ -213,10 +214,11 @@ public class ApiAssignmentService {
...
@@ -213,10 +214,11 @@ public class ApiAssignmentService {
if
(
pv
.
getType
().
isObject
()
&&
null
!=
pv
.
getChildren
())
{
if
(
pv
.
getType
().
isObject
()
&&
null
!=
pv
.
getChildren
())
{
Map
<
String
,
Object
>
objectMap
=
new
HashMap
<>(
4
);
Map
<
String
,
Object
>
objectMap
=
new
HashMap
<>(
4
);
for
(
BaseParamValue
spv
:
pv
.
getChildren
())
{
for
(
BaseParamValue
spv
:
pv
.
getChildren
())
{
Object
v
=
spv
.
getType
().
getConverter
().
apply
(
spv
.
getValue
());
if
(
spv
.
getIsArray
())
{
if
(
spv
.
getIsArray
())
{
objectMap
.
put
(
spv
.
getName
(),
Arrays
.
asList
(
spv
.
getType
().
getConverter
().
apply
(
spv
.
getValue
())
));
objectMap
.
put
(
spv
.
getName
(),
null
==
v
?
null
:
Arrays
.
asList
(
v
));
}
else
{
}
else
{
objectMap
.
put
(
spv
.
getName
(),
spv
.
getType
().
getConverter
().
apply
(
spv
.
getValue
())
);
objectMap
.
put
(
spv
.
getName
(),
v
);
}
}
}
}
if
(
objectMap
.
size
()
>
0
)
{
if
(
objectMap
.
size
()
>
0
)
{
...
@@ -230,6 +232,7 @@ public class ApiAssignmentService {
...
@@ -230,6 +232,7 @@ public class ApiAssignmentService {
}
else
{
}
else
{
List
<
Object
>
values
=
value
.
stream
().
map
(
ParamValue:
:
getValue
)
List
<
Object
>
values
=
value
.
stream
().
map
(
ParamValue:
:
getValue
)
.
map
(
s
->
type
.
getConverter
().
apply
(
s
))
.
map
(
s
->
type
.
getConverter
().
apply
(
s
))
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
params
.
put
(
paramName
,
values
);
params
.
put
(
paramName
,
values
);
}
}
...
@@ -238,15 +241,14 @@ public class ApiAssignmentService {
...
@@ -238,15 +241,14 @@ public class ApiAssignmentService {
if
(
null
!=
value
.
get
(
0
).
getChildren
())
{
if
(
null
!=
value
.
get
(
0
).
getChildren
())
{
Map
<
String
,
Object
>
objectMap
=
new
HashMap
<>(
4
);
Map
<
String
,
Object
>
objectMap
=
new
HashMap
<>(
4
);
for
(
BaseParamValue
spv
:
value
.
get
(
0
).
getChildren
())
{
for
(
BaseParamValue
spv
:
value
.
get
(
0
).
getChildren
())
{
Object
v
=
spv
.
getType
().
getConverter
().
apply
(
spv
.
getValue
());
if
(
spv
.
getIsArray
())
{
if
(
spv
.
getIsArray
())
{
objectMap
.
put
(
spv
.
getName
(),
Arrays
.
asList
(
spv
.
getType
().
getConverter
().
apply
(
spv
.
getValue
())
));
objectMap
.
put
(
spv
.
getName
(),
null
==
v
?
null
:
Arrays
.
asList
(
v
));
}
else
{
}
else
{
objectMap
.
put
(
spv
.
getName
(),
spv
.
getType
().
getConverter
().
apply
(
spv
.
getValue
())
);
objectMap
.
put
(
spv
.
getName
(),
v
);
}
}
}
}
if
(
objectMap
.
size
()
>
0
)
{
params
.
put
(
paramName
,
objectMap
);
params
.
put
(
paramName
,
objectMap
);
}
}
}
}
else
{
}
else
{
params
.
put
(
paramName
,
type
.
getConverter
().
apply
(
value
.
get
(
0
).
getValue
()));
params
.
put
(
paramName
,
type
.
getConverter
().
apply
(
value
.
get
(
0
).
getValue
()));
...
@@ -336,6 +338,11 @@ public class ApiAssignmentService {
...
@@ -336,6 +338,11 @@ public class ApiAssignmentService {
itemParam
.
checkValid
();
itemParam
.
checkValid
();
}
}
}
}
if
(!
CollectionUtils
.
isEmpty
(
request
.
getOutputs
()))
{
for
(
OutParam
outParam
:
request
.
getOutputs
())
{
outParam
.
checkValid
();
}
}
if
(
null
==
request
.
getDatasourceId
()
||
null
==
dataSourceDao
.
getById
(
request
.
getDatasourceId
()))
{
if
(
null
==
request
.
getDatasourceId
()
||
null
==
dataSourceDao
.
getById
(
request
.
getDatasourceId
()))
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
"Invalid datasourceId or maybe not exist."
);
"Invalid datasourceId or maybe not exist."
);
...
@@ -409,6 +416,11 @@ public class ApiAssignmentService {
...
@@ -409,6 +416,11 @@ public class ApiAssignmentService {
itemParam
.
checkValid
();
itemParam
.
checkValid
();
}
}
}
}
if
(!
CollectionUtils
.
isEmpty
(
request
.
getOutputs
()))
{
for
(
OutParam
outParam
:
request
.
getOutputs
())
{
outParam
.
checkValid
();
}
}
if
(
null
==
request
.
getDatasourceId
()
||
null
==
dataSourceDao
.
getById
(
request
.
getDatasourceId
()))
{
if
(
null
==
request
.
getDatasourceId
()
||
null
==
dataSourceDao
.
getById
(
request
.
getDatasourceId
()))
{
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
"Invalid datasourceId or maybe not exist."
);
"Invalid datasourceId or maybe not exist."
);
...
...
sqlrest-template/src/main/java/com/gitee/sqlrest/template/XmlSqlTemplate.java
View file @
2f6de5c1
...
@@ -58,6 +58,12 @@ public class XmlSqlTemplate {
...
@@ -58,6 +58,12 @@ public class XmlSqlTemplate {
name
=
name
.
replaceAll
(
Pattern
.
quote
(
matcher
.
group
()),
""
);
name
=
name
.
replaceAll
(
Pattern
.
quote
(
matcher
.
group
()),
""
);
matcher
=
pattern
.
matcher
(
name
);
matcher
=
pattern
.
matcher
(
name
);
}
}
int
commaIdx
=
name
.
indexOf
(
","
);
if
(
commaIdx
>
0
)
{
name
=
name
.
substring
(
0
,
commaIdx
);
}
int
idx
=
name
.
indexOf
(
"."
);
int
idx
=
name
.
indexOf
(
"."
);
if
(
idx
>
0
)
{
if
(
idx
>
0
)
{
subName
=
name
;
subName
=
name
;
...
...
sqlrest-template/src/main/resources/script-1.0.dtd
deleted
100644 → 0
View file @
beac5827
<!ELEMENT script (#PCDATA | trim | where | set | foreach | choose | if)*>
<!ELEMENT trim (#PCDATA | trim | where | set | foreach | choose | if)*>
<!ATTLIST trim
prefix CDATA #IMPLIED
prefixOverrides CDATA #IMPLIED
suffix CDATA #IMPLIED
suffixOverrides CDATA #IMPLIED
>
<!ELEMENT where (#PCDATA | trim | where | set | foreach | choose | if)*>
<!ELEMENT set (#PCDATA | trim | where | set | foreach | choose | if)*>
<!ELEMENT foreach (#PCDATA | trim | where | set | foreach | choose | if)*>
<!ATTLIST foreach
collection CDATA #REQUIRED
item CDATA #IMPLIED
index CDATA #IMPLIED
open CDATA #IMPLIED
close CDATA #IMPLIED
separator CDATA #IMPLIED
>
<!ELEMENT choose (when* , otherwise?)>
<!ELEMENT when (#PCDATA | trim | where | set | foreach | choose | if)*>
<!ATTLIST when
test CDATA #REQUIRED
>
<!ELEMENT otherwise (#PCDATA | trim | where | set | foreach | choose | if)*>
<!ELEMENT if (#PCDATA | trim | where | set | foreach | choose | if)*>
<!ATTLIST if
test CDATA #REQUIRED
>
\ No newline at end of file
sqlrest-template/src/test/java/com/gitee/sqlrest/template/TemplateTest.java
View file @
2f6de5c1
...
@@ -210,4 +210,23 @@ public class TemplateTest {
...
@@ -210,4 +210,23 @@ public class TemplateTest {
SqlMeta
sqlMeta
=
template
.
process
(
params
);
SqlMeta
sqlMeta
=
template
.
process
(
params
);
System
.
out
.
println
(
sqlMeta
);
System
.
out
.
println
(
sqlMeta
);
}
}
@Test
public
void
testObjNotRequiredField
()
{
String
sql
=
"SELECT * from employees.departments "
+
"<if test='obj.deptNo != null and obj.deptNo.size() > 0'> "
+
" WHERE dept_no in "
+
" <foreach open=\"(\" close=\")\" collection=\"obj.deptNo\" separator=\",\" item=\"item\" index=\"index\"> "
+
" #{item} "
+
" </foreach> "
+
"</if>"
;
XmlSqlTemplate
template
=
new
XmlSqlTemplate
(
sql
);
System
.
out
.
println
(
template
.
getParameterNames
());
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"obj"
,
obj
);
SqlMeta
sqlMeta
=
template
.
process
(
params
);
System
.
out
.
println
(
sqlMeta
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment