Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
test
Project
Project
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
邬友楠
test
Commits
01bd2920
Commit
01bd2920
authored
Dec 25, 2019
by
雍欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自定义查询SQL方言
parent
b34ad564
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
66 deletions
+67
-66
QueryXmlModel.java
...ta/src/main/java/com/huigou/data/query/QueryXmlModel.java
+22
-32
QueryXmlManager.java
...ava/com/huigou/uasp/bmp/common/query/QueryXmlManager.java
+41
-30
TreeViewManager.java
.../com/huigou/uasp/bmp/common/treeview/TreeViewManager.java
+4
-4
No files found.
huigou-data/src/main/java/com/huigou/data/query/QueryXmlModel.java
View file @
01bd2920
...
...
@@ -23,11 +23,7 @@ public class QueryXmlModel implements Serializable, ConfigFileVersion {
/**
* 实体对象
*/
private
final
Map
<
String
,
Query
>
querys
;
/**
* @since 1.1.3
*/
private
final
Map
<
String
,
Query
>
dialectQuerys
;
private
final
List
<
Map
<
String
,
Query
>>
querys
;
/**
* 版本
...
...
@@ -36,19 +32,18 @@ public class QueryXmlModel implements Serializable, ConfigFileVersion {
private
List
<
String
>
configFilePaths
;
public
QueryXmlModel
(
QueryMappings
queryMappings
,
QueryMappings
dialectQueryMappings
)
{
if
(
queryMappings
!=
null
)
{
querys
=
Arrays
.
stream
(
queryMappings
.
getQueryArray
())
.
collect
(
Collectors
.
toMap
(
Query:
:
getName
,
query
->
query
));
}
else
{
querys
=
Collections
.
emptyMap
();
}
if
(
dialectQueryMappings
!=
null
)
{
dialectQuerys
=
Arrays
.
stream
(
dialectQueryMappings
.
getQueryArray
())
.
collect
(
Collectors
.
toMap
(
Query:
:
getName
,
query
->
query
));
}
else
{
dialectQuerys
=
Collections
.
emptyMap
();
public
QueryXmlModel
(
QueryMappings
queryMapping
)
{
this
(
Collections
.
singletonList
(
queryMapping
));
}
/**
* @since 1.1.3
*/
public
QueryXmlModel
(
List
<
QueryMappings
>
queryMappings
)
{
querys
=
queryMappings
.
stream
()
.
filter
(
Objects:
:
nonNull
)
.
map
(
queryMapping
->
Arrays
.
stream
(
queryMapping
.
getQueryArray
()).
collect
(
Collectors
.
toMap
(
Query:
:
getName
,
query
->
query
)))
.
collect
(
Collectors
.
toList
());
}
public
String
getName
()
{
...
...
@@ -59,24 +54,15 @@ public class QueryXmlModel implements Serializable, ConfigFileVersion {
this
.
name
=
name
;
}
@Deprecated
public
Map
<
String
,
Query
>
getQuerys
()
{
return
querys
;
}
/**
* @since 1.1.3
*/
public
Map
<
String
,
Query
>
getDialectQuerys
()
{
return
dialectQuerys
;
return
querys
.
get
(
0
);
}
public
Query
getQuery
(
String
name
)
{
// 优先从方言中获取
Query
query
=
dialectQuerys
.
get
(
name
);
if
(
query
==
null
)
{
query
=
querys
.
get
(
name
);
}
return
query
;
return
querys
.
stream
().
map
(
query
->
query
.
get
(
name
))
.
filter
(
Objects:
:
nonNull
)
.
findFirst
().
get
();
}
public
void
setVersion
(
Long
version
)
{
...
...
@@ -93,6 +79,10 @@ public class QueryXmlModel implements Serializable, ConfigFileVersion {
return
configFilePaths
.
get
(
0
);
}
/**
* @deprecated 已被 {@link #setConfigFilePaths(List)} 替代。
*/
@Deprecated
public
void
setConfigFilePath
(
String
configFilePath
)
{
this
.
configFilePaths
=
Collections
.
singletonList
(
configFilePath
);
}
...
...
huigou-uasp/src/main/java/com/huigou/uasp/bmp/common/query/QueryXmlManager.java
View file @
01bd2920
...
...
@@ -2,17 +2,26 @@ package com.huigou.uasp.bmp.common.query;
import
com.huigou.data.query.QueryXmlLoadInterface
;
import
com.huigou.data.query.QueryXmlModel
;
import
com.huigou.exception.ApplicationException
;
import
com.huigou.exception.ResourceLoadException
;
import
com.huigou.uasp.bmp.query.QueryMappingsDocument
;
import
com.huigou.util.ResourceLoadManager
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.xmlbeans.XmlException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.util.Assert
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 查询模型管理类
...
...
@@ -35,43 +44,45 @@ public class QueryXmlManager extends ResourceLoadManager<QueryXmlModel> implemen
*/
@Override
public
QueryXmlModel
loadConfigFile
(
String
path
)
throws
ResourceLoadException
{
InputStream
inputStream
=
null
,
dialectXmlStream
=
null
;
List
<
InputStream
>
xmlStreams
=
Collections
.
emptyList
()
;
try
{
// 默认SQL XML 文件
ClassPathResource
resource
=
getResource
(
path
);
// 方言SQL XML文件
ClassPathResource
dialectXml
=
getResource
(
getDialectXmlPath
(
path
));
Assert
.
isTrue
(
resource
.
exists
()
||
dialectXml
.
exists
(),
"文件不存在"
);
QueryMappingsDocument
.
QueryMappings
queryMappings
=
null
;
if
(
resource
.
exists
())
{
inputStream
=
resource
.
getInputStream
();
queryMappings
=
QueryMappingsDocument
.
Factory
.
parse
(
inputStream
).
getQueryMappings
();
List
<
String
>
paths
=
new
ArrayList
<>(
2
);
// 方言xml放在最前面,从而达到优先使用方言xml的目的
if
(
StringUtils
.
isNotBlank
(
sqlDialect
))
{
paths
.
add
(
getDialectXmlPath
(
path
));
}
QueryMappingsDocument
.
QueryMappings
dialectQueryMappings
=
null
;
if
(
dialectXml
.
exists
())
{
dialectXmlStream
=
dialectXml
.
getInputStream
();
dialectQueryMappings
=
QueryMappingsDocument
.
Factory
.
parse
(
dialectXmlStream
)
.
getQueryMappings
();
paths
.
add
(
path
);
List
<
Resource
>
resources
=
paths
.
stream
()
.
map
(
ClassPathResource:
:
new
)
.
filter
(
Resource:
:
exists
)
.
collect
(
Collectors
.
toList
());
xmlStreams
=
resources
.
stream
()
.
map
(
xml
->
{
try
{
return
xml
.
getInputStream
();
}
catch
(
IOException
ioe
)
{
throw
new
ApplicationException
(
ioe
);
}
})
.
collect
(
Collectors
.
toList
());
QueryXmlModel
model
=
new
QueryXmlModel
(
queryMappings
,
dialectQueryMappings
);
// 文件最后修改时间
long
version
;
if
(
resource
.
exists
()
&&
dialectXml
.
exists
())
{
version
=
resource
.
lastModified
()
>
dialectXml
.
lastModified
()
?
resource
.
lastModified
()
:
dialectXml
.
lastModified
();
}
else
{
version
=
resource
.
exists
()
?
resource
.
lastModified
()
:
dialectXml
.
lastModified
();
List
<
QueryMappingsDocument
.
QueryMappings
>
mappings
=
xmlStreams
.
stream
().
map
(
is
->
{
try
{
return
QueryMappingsDocument
.
Factory
.
parse
(
is
).
getQueryMappings
();
}
catch
(
XmlException
|
IOException
e
)
{
throw
new
ApplicationException
(
e
);
}
model
.
setVersion
(
version
);
model
.
setConfigFilePath
(
path
);
}).
collect
(
Collectors
.
toList
());
QueryXmlModel
model
=
new
QueryXmlModel
(
mappings
);
model
.
setVersion
(
maxLastModified
(
resources
));
model
.
setConfigFilePaths
(
paths
);
return
model
;
}
catch
(
Exception
e
)
{
throw
new
ResourceLoadException
(
String
.
format
(
"读取配置文件[%s]失败:%s"
,
path
,
e
.
getMessage
()));
}
finally
{
IOUtils
.
closeQuietly
(
inputStream
);
IOUtils
.
closeQuietly
(
dialectXmlStream
);
xmlStreams
.
forEach
(
IOUtils:
:
closeQuietly
);
}
}
...
...
huigou-uasp/src/main/java/com/huigou/uasp/bmp/common/treeview/TreeViewManager.java
View file @
01bd2920
...
...
@@ -77,10 +77,10 @@ public class TreeViewManager extends ResourceLoadManager<TreeViewMappingModel> i
}
}).
collect
(
Collectors
.
toList
());
TreeViewMappingModel
m
appingM
odel
=
new
TreeViewMappingModel
(
mappings
);
m
appingM
odel
.
setVersions
(
maxLastModified
(
resources
));
m
appingM
odel
.
setConfigFilePaths
(
paths
);
return
m
appingM
odel
;
TreeViewMappingModel
model
=
new
TreeViewMappingModel
(
mappings
);
model
.
setVersions
(
maxLastModified
(
resources
));
model
.
setConfigFilePaths
(
paths
);
return
model
;
}
catch
(
Exception
e
)
{
throw
new
ResourceLoadException
(
String
.
format
(
"读取配置文件[%s]失败:%s"
,
defaultPath
,
e
.
getMessage
()));
}
finally
{
...
...
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