Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
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
曲欣亮
common
Commits
6cb16bb0
Commit
6cb16bb0
authored
Dec 12, 2018
by
张永
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://zhangyong@gitlab.egolm.com/key/common.git
parents
627adf37
f0643bdb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
20 deletions
+26
-20
ReflexUtil.java
src/main/java/com/egolm/common/ReflexUtil.java
+2
-1
JdbcTemplate.java
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
+22
-15
ReverseUtil.java
src/main/java/com/egolm/common/jdbc/dialect/ReverseUtil.java
+2
-4
No files found.
src/main/java/com/egolm/common/ReflexUtil.java
View file @
6cb16bb0
...
...
@@ -72,7 +72,7 @@ public class ReflexUtil {
try
{
return
new
PropertyDescriptor
(
field
.
getName
(),
clazz
).
getReadMethod
();
}
catch
(
IntrospectionException
e1
)
{
throw
new
ReflectException
(
"MethodNotFound:"
+
methodName
);
throw
new
ReflectException
(
"MethodNotFound:"
+
methodName
+
" class:"
+
clazz
.
getName
()
+
" field:"
+
field
.
getName
()
);
}
}
}
else
{
...
...
@@ -163,4 +163,5 @@ public class ReflexUtil {
throw
new
ReflectException
(
"GetMethodException"
,
e
);
}
}
}
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
View file @
6cb16bb0
package
com
.
egolm
.
common
.
jdbc
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.sql.CallableStatement
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
...
...
@@ -200,22 +202,21 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
Desc
iSql
=
dialect
.
getDesc
(
obj
.
getClass
());
Map
<
String
,
Object
>
pkFieldMap
=
dialect
.
getFieldValue
(
obj
,
byFields
);
if
(
dialect
.
hasPkValue
(
obj
)
&&
pkFieldMap
!=
null
&&
pkFieldMap
.
size
()
>
0
)
{
List
<
Map
<
String
,
Object
>>
objMaps
=
queryForListByColumn
(
iSql
.
getName
(),
pkFieldMap
);
List
<
Map
<
String
,
Object
>>
objMaps
=
this
.
queryForListByColumn
(
iSql
.
getName
(),
pkFieldMap
);
if
(
objMaps
!=
null
)
{
if
(
objMaps
.
size
()
==
1
)
{
String
[]
columnNames
=
iSql
.
getColumnNames
();
String
[]
fieldNames
=
iSql
.
getFieldNames
();
for
(
int
i
=
0
;
i
<
fieldNames
.
length
;
i
++)
{
String
fieldName
=
fieldNames
[
i
];
Object
fieldObj
=
ReflexUtil
.
readField
(
fieldName
,
obj
);
if
(
fieldObj
==
null
)
{
fieldObj
=
objMaps
.
get
(
0
).
get
(
columnNames
[
i
]);
if
(
fieldObj
!=
null
)
{
ReflexUtil
.
writeField
(
fieldName
,
obj
,
fieldObj
);
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
Field
[]
fields
=
obj
.
getClass
().
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
int
mod
=
field
.
getModifiers
();
if
(!
Modifier
.
isStatic
(
mod
)
&&
!
Modifier
.
isFinal
(
mod
))
{
Object
fieldValue
=
ReflexUtil
.
getFieldValue
(
field
,
obj
);
if
(
fieldValue
!=
null
)
{
map
.
put
(
field
.
getName
(),
fieldValue
);
}
}
}
return
this
.
updateBy
Field
(
obj
,
byFields
);
return
this
.
updateBy
Column
(
iSql
.
getName
(),
iSql
.
getColumnPkNames
(),
map
);
}
else
if
(
objMaps
.
size
()
>
1
)
{
throw
new
MustBeOneRowException
();
}
else
{
...
...
@@ -389,7 +390,7 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
return
this
.
queryForBeans
(
iSql
.
getSql
(),
type
,
iSql
.
getArgs
());
}
public
<
T
>
List
<
T
>
queryForBeansByField
(
T
obj
,
String
...
byFields
)
{
public
<
T
>
List
<
T
>
queryForBeansByField
(
T
obj
,
String
[]
byFields
)
{
@SuppressWarnings
(
"unchecked"
)
Class
<
T
>
type
=
(
Class
<
T
>)
obj
.
getClass
();
Desc
desc
=
dialect
.
getDesc
(
type
);
...
...
@@ -414,12 +415,18 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
}
public
int
[]
batchSave
(
Object
...
objs
)
{
Sql
i
=
dialect
.
batchInsert
(
objs
);
return
this
.
batchUpdate
(
i
.
getSql
(),
i
.
getBachArgs
());
if
(
objs
!=
null
&&
objs
.
length
>
0
)
{
Sql
i
=
dialect
.
batchInsert
(
objs
);
return
this
.
batchUpdate
(
i
.
getSql
(),
i
.
getBachArgs
());
}
return
new
int
[]{
0
};
}
public
int
[]
batchSave
(
List
<?>
objs
)
{
return
this
.
batchSave
(
objs
.
toArray
());
if
(
objs
!=
null
&&
objs
.
size
()
>
0
)
{
return
this
.
batchSave
(
objs
.
toArray
());
}
return
new
int
[]{
0
};
}
public
int
batchSave
(
String
tableName
,
List
<
Map
<
String
,
Object
>>
objs
)
{
...
...
src/main/java/com/egolm/common/jdbc/dialect/ReverseUtil.java
View file @
6cb16bb0
...
...
@@ -2,10 +2,8 @@ package com.egolm.common.jdbc.dialect;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
import
com.egolm.common.DateUtil
;
import
com.egolm.common.FileUtil
;
import
com.egolm.common.StringUtil
;
...
...
@@ -50,8 +48,8 @@ public class ReverseUtil {
sb
.
append
(
"/**"
+
"\n"
);
sb
.
append
(
" * @author "
+
author
+
"\n"
);
sb
.
append
(
" * @since "
+
DateUtil
.
format
(
new
Date
(),
DateUtil
.
FMT_DATE
)
+
"\n"
);
sb
.
append
(
" * @version v-1.0"
+
"\n"
);
//
sb.append(" * @since " + DateUtil.format(new Date(), DateUtil.FMT_DATE) + "\n");
//
sb.append(" * @version v-1.0" + "\n");
sb
.
append
(
" */"
+
"\n"
);
sb
.
append
(
"@Entity(name=\""
+
name
+
"\")"
+
"\n"
);
sb
.
append
(
"public class "
+
StringUtil
.
upperFirst
(
name
)
+
" implements java.io.Serializable {"
+
"\n\n"
+
"\tprivate static final long serialVersionUID = 1L;"
+
"\n\n"
);
...
...
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