Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
ebdf7799
Commit
ebdf7799
authored
Dec 10, 2019
by
Elune
Browse files
代码优化
parent
aa2da4e2
Changes
5
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/utils/QueryHelp.java
View file @
ebdf7799
...
...
@@ -13,9 +13,9 @@ import java.util.*;
* @date 2019-6-4 14:59:48
*/
@Slf4j
@SuppressWarnings
({
"unchecked"
,
"all"
})
public
class
QueryHelp
{
@SuppressWarnings
(
"all"
)
public
static
<
R
,
Q
>
Predicate
getPredicate
(
Root
<
R
>
root
,
Q
query
,
CriteriaBuilder
cb
)
{
List
<
Predicate
>
list
=
new
ArrayList
<>();
...
...
eladmin-generator/src/main/java/me/zhengjie/service/impl/GeneratorServiceImpl.java
View file @
ebdf7799
...
...
@@ -32,7 +32,7 @@ import java.util.Map;
* @date 2019-01-02
*/
@Service
@SuppressWarnings
(
"all"
)
@SuppressWarnings
(
{
"unchecked"
,
"all"
}
)
public
class
GeneratorServiceImpl
implements
GeneratorService
{
@PersistenceContext
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/util/DataTypeEnum.java
View file @
ebdf7799
...
...
@@ -18,43 +18,60 @@
*/
package
me.zhengjie.modules.mnt.util
;
import
lombok.extern.slf4j.Slf4j
;
/**
* @author /
*/
@Slf4j
@SuppressWarnings
({
"unchecked"
,
"all"
})
public
enum
DataTypeEnum
{
/** mysql */
MYSQL
(
"mysql"
,
"mysql"
,
"com.mysql.jdbc.Driver"
,
"`"
,
"`"
,
"'"
,
"'"
),
/** oracle */
ORACLE
(
"oracle"
,
"oracle"
,
"oracle.jdbc.driver.OracleDriver"
,
"\""
,
"\""
,
"\""
,
"\""
),
/** sql server */
SQLSERVER
(
"sqlserver"
,
"sqlserver"
,
"com.microsoft.sqlserver.jdbc.SQLServerDriver"
,
"\""
,
"\""
,
"\""
,
"\""
),
/** h2 */
H2
(
"h2"
,
"h2"
,
"org.h2.Driver"
,
"`"
,
"`"
,
"\""
,
"\""
),
/** phoenix */
PHOENIX
(
"phoenix"
,
"hbase phoenix"
,
"org.apache.phoenix.jdbc.PhoenixDriver"
,
""
,
""
,
"\""
,
"\""
),
/** mongo */
MONGODB
(
"mongo"
,
"mongodb"
,
"mongodb.jdbc.MongoDriver"
,
"`"
,
"`"
,
"\""
,
"\""
),
/** sql4es */
ELASTICSEARCH
(
"sql4es"
,
"elasticsearch"
,
"nl.anchormen.sql4es.jdbc.ESDriver"
,
""
,
""
,
"'"
,
"'"
),
/** presto */
PRESTO
(
"presto"
,
"presto"
,
"com.facebook.presto.jdbc.PrestoDriver"
,
""
,
""
,
"\""
,
"\""
),
/** moonbox */
MOONBOX
(
"moonbox"
,
"moonbox"
,
"moonbox.jdbc.MbDriver"
,
"`"
,
"`"
,
"`"
,
"`"
),
/** cassandra */
CASSANDRA
(
"cassandra"
,
"cassandra"
,
"com.github.adejanovski.cassandra.jdbc.CassandraDriver"
,
""
,
""
,
"'"
,
"'"
),
/** click house */
CLICKHOUSE
(
"clickhouse"
,
"clickhouse"
,
"ru.yandex.clickhouse.ClickHouseDriver"
,
""
,
""
,
"\""
,
"\""
),
/** kylin */
KYLIN
(
"kylin"
,
"kylin"
,
"org.apache.kylin.jdbc.Driver"
,
"\""
,
"\""
,
"\""
,
"\""
),
/** vertica */
VERTICA
(
"vertica"
,
"vertica"
,
"com.vertica.jdbc.Driver"
,
""
,
""
,
"'"
,
"'"
),
/** sap */
HANA
(
"sap"
,
"sap hana"
,
"com.sap.db.jdbc.Driver"
,
""
,
""
,
"'"
,
"'"
),
/** impala */
IMPALA
(
"impala"
,
"impala"
,
"com.cloudera.impala.jdbc41.Driver"
,
""
,
""
,
"'"
,
"'"
);
private
String
feature
;
private
String
desc
;
private
String
driver
;
...
...
@@ -63,7 +80,7 @@ public enum DataTypeEnum {
private
String
aliasPrefix
;
private
String
aliasSuffix
;
private
static
final
String
jdbcUrlPrefix
=
"jdbc:"
;
private
static
final
String
JDBC_URL_PREFIX
=
"jdbc:"
;
DataTypeEnum
(
String
feature
,
String
desc
,
String
driver
,
String
keywordPrefix
,
String
keywordSuffix
,
String
aliasPrefix
,
String
aliasSuffix
)
{
this
.
feature
=
feature
;
...
...
@@ -78,7 +95,7 @@ public enum DataTypeEnum {
public
static
DataTypeEnum
urlOf
(
String
jdbcUrl
)
{
String
url
=
jdbcUrl
.
toLowerCase
().
trim
();
for
(
DataTypeEnum
dataTypeEnum
:
values
())
{
if
(
url
.
startsWith
(
jdbcUrlPrefix
+
dataTypeEnum
.
feature
))
{
if
(
url
.
startsWith
(
JDBC_URL_PREFIX
+
dataTypeEnum
.
feature
))
{
try
{
Class
<?>
aClass
=
Class
.
forName
(
dataTypeEnum
.
getDriver
());
if
(
null
==
aClass
)
{
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/util/SqlUtils.java
View file @
ebdf7799
...
...
@@ -5,14 +5,17 @@ import com.alibaba.druid.pool.DruidDataSource;
import
com.alibaba.druid.util.StringUtils
;
import
com.google.common.collect.Lists
;
import
lombok.extern.slf4j.Slf4j
;
import
javax.sql.DataSource
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.sql.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author /
*/
@Slf4j
public
class
SqlUtils
{
...
...
@@ -36,17 +39,17 @@ public class SqlUtils {
/**
* 获取数据源
*
* @param jdbcUrl
* @param userName
* @param password
* @return
* @param jdbcUrl
/
* @param userName
/
* @param password
/
* @return
DataSource
*/
private
static
DataSource
getDataSource
(
String
jdbcUrl
,
String
userName
,
String
password
)
{
String
key
=
getKey
(
jdbcUrl
,
userName
,
password
);
if
(!
map
.
containsKey
(
key
)
||
null
==
map
.
get
(
key
))
{
DruidDataSource
druidDataSource
=
new
DruidDataSource
();
String
className
=
null
;
String
className
;
try
{
className
=
DriverManager
.
getDriver
(
jdbcUrl
.
trim
()).
getClass
().
getName
();
}
catch
(
SQLException
e
)
{
...
...
@@ -98,11 +101,10 @@ public class SqlUtils {
Connection
connection
=
null
;
try
{
connection
=
dataSource
.
getConnection
();
}
catch
(
Exception
e
)
{
connection
=
null
;
}
}
catch
(
Exception
ignored
)
{}
try
{
if
(
null
==
connection
||
connection
.
isClosed
()
||
!
connection
.
isValid
(
5
))
{
int
timeOut
=
5
;
if
(
null
==
connection
||
connection
.
isClosed
()
||
!
connection
.
isValid
(
timeOut
))
{
log
.
info
(
"connection is closed or invalid, retry get connection!"
);
connection
=
dataSource
.
getConnection
();
}
...
...
@@ -117,10 +119,9 @@ public class SqlUtils {
if
(
null
!=
connection
)
{
try
{
connection
.
close
();
connection
=
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
"connection close error
"
,
e
.
getMessage
());
log
.
error
(
"connection close error
:"
+
e
.
getMessage
());
}
}
}
...
...
@@ -130,7 +131,6 @@ public class SqlUtils {
if
(
rs
!=
null
)
{
try
{
rs
.
close
();
rs
=
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -145,7 +145,7 @@ public class SqlUtils {
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
info
(
"Get connection failed:"
,
e
.
getMessage
());
log
.
info
(
"Get connection failed:"
+
e
.
getMessage
());
}
finally
{
releaseConnection
(
connection
);
}
...
...
@@ -168,9 +168,8 @@ public class SqlUtils {
/**
* 批量执行sql
* @param connection
* @param sqlList
* @return
* @param connection /
* @param sqlList /
*/
public
static
void
batchExecute
(
Connection
connection
,
List
<
String
>
sqlList
)
throws
SQLException
{
Statement
st
=
connection
.
createStatement
();
...
...
@@ -185,18 +184,16 @@ public class SqlUtils {
/**
* 将文件中的sql语句以;为单位读取到列表中
* @param sqlFile
* @return
* @throws Exception
* @param sqlFile
/
* @return
/
* @throws Exception
e
*/
private
static
List
<
String
>
readSqlList
(
File
sqlFile
)
throws
Exception
{
List
<
String
>
sqlList
=
Lists
.
newArrayList
();
StringBuilder
sb
=
new
StringBuilder
();
BufferedReader
reader
=
null
;
try
{
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
sqlFile
),
"UTF-8"
));
String
tmp
=
null
;
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
sqlFile
),
StandardCharsets
.
UTF_8
)))
{
String
tmp
;
while
((
tmp
=
reader
.
readLine
())
!=
null
)
{
log
.
info
(
"line:{}"
,
tmp
);
if
(
tmp
.
endsWith
(
";"
))
{
...
...
@@ -210,11 +207,6 @@ public class SqlUtils {
if
(!
""
.
endsWith
(
sb
.
toString
().
trim
()))
{
sqlList
.
add
(
sb
.
toString
());
}
}
finally
{
try
{
reader
.
close
();
}
catch
(
IOException
e1
)
{
}
}
return
sqlList
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DictDetailServiceImpl.java
View file @
ebdf7799
...
...
@@ -39,7 +39,7 @@ public class DictDetailServiceImpl implements DictDetailService {
@Override
@Cacheable
public
Map
queryAll
(
DictDetailQueryCriteria
criteria
,
Pageable
pageable
)
{
public
Map
<
String
,
Object
>
queryAll
(
DictDetailQueryCriteria
criteria
,
Pageable
pageable
)
{
Page
<
DictDetail
>
page
=
dictDetailRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
dictDetailMapper:
:
toDto
));
}
...
...
Write
Preview
Supports
Markdown
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