Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
5473de9f
Commit
5473de9f
authored
Jun 15, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set project charsets
parent
dc6a4638
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/biz/BizIdColumnField.java
...framework/autoconfigure/mybatis/biz/BizIdColumnField.java
+8
-2
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/biz/BizIdInjectInterceptor.java
...ork/autoconfigure/mybatis/biz/BizIdInjectInterceptor.java
+10
-2
No files found.
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/biz/BizIdColumnField.java
View file @
5473de9f
...
@@ -20,6 +20,8 @@ public class BizIdColumnField {
...
@@ -20,6 +20,8 @@ public class BizIdColumnField {
private
final
String
columnName
;
private
final
String
columnName
;
private
final
Class
<?>
fieldType
;
private
final
MethodHandle
bizIdFieldGetterMethodHandle
;
private
final
MethodHandle
bizIdFieldGetterMethodHandle
;
private
final
MethodHandle
bizIdFieldSetterMethodHandle
;
private
final
MethodHandle
bizIdFieldSetterMethodHandle
;
...
@@ -27,8 +29,8 @@ public class BizIdColumnField {
...
@@ -27,8 +29,8 @@ public class BizIdColumnField {
public
BizIdColumnField
(
Class
<?>
entityClass
,
Field
bizIdField
)
{
public
BizIdColumnField
(
Class
<?>
entityClass
,
Field
bizIdField
)
{
this
.
annotation
=
bizIdField
.
getAnnotation
(
BizId
.
class
);
this
.
annotation
=
bizIdField
.
getAnnotation
(
BizId
.
class
);
this
.
columnName
=
BizIdHelper
.
getColumnName
(
entityClass
,
bizIdField
,
this
.
annotation
);
this
.
columnName
=
BizIdHelper
.
getColumnName
(
entityClass
,
bizIdField
,
this
.
annotation
);
this
.
fieldType
=
bizIdField
.
getType
();
try
{
try
{
Class
<?>
fieldType
=
bizIdField
.
getType
();
Lookup
lookup
=
privateLookupIn
(
entityClass
,
lookup
());
Lookup
lookup
=
privateLookupIn
(
entityClass
,
lookup
());
this
.
bizIdFieldGetterMethodHandle
=
lookup
.
findGetter
(
entityClass
,
bizIdField
.
getName
(),
fieldType
);
this
.
bizIdFieldGetterMethodHandle
=
lookup
.
findGetter
(
entityClass
,
bizIdField
.
getName
(),
fieldType
);
this
.
bizIdFieldSetterMethodHandle
=
lookup
.
findSetter
(
entityClass
,
bizIdField
.
getName
(),
fieldType
);
this
.
bizIdFieldSetterMethodHandle
=
lookup
.
findSetter
(
entityClass
,
bizIdField
.
getName
(),
fieldType
);
...
@@ -54,4 +56,8 @@ public class BizIdColumnField {
...
@@ -54,4 +56,8 @@ public class BizIdColumnField {
}
}
}
}
}
public
Class
<?>
getFieldType
()
{
return
fieldType
;
}
}
\ No newline at end of file
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/biz/BizIdInjectInterceptor.java
View file @
5473de9f
package
com.schbrain.framework.autoconfigure.mybatis.biz
;
package
com.schbrain.framework.autoconfigure.mybatis.biz
;
import
cn.hutool.core.convert.Convert
;
import
com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
;
import
com.schbrain.common.exception.BaseException
;
import
org.apache.ibatis.executor.Executor
;
import
org.apache.ibatis.executor.Executor
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.mapping.SqlCommandType
;
import
org.apache.ibatis.mapping.SqlCommandType
;
...
@@ -32,9 +34,15 @@ public class BizIdInjectInterceptor implements InnerInterceptor {
...
@@ -32,9 +34,15 @@ public class BizIdInjectInterceptor implements InnerInterceptor {
if
(
bizIdType
==
BizIdType
.
ID_WORKER
)
{
if
(
bizIdType
==
BizIdType
.
ID_WORKER
)
{
Object
bizIdValue
=
bizColumnField
.
getValue
(
entity
);
Object
bizIdValue
=
bizColumnField
.
getValue
(
entity
);
if
(
bizIdValue
==
null
)
{
if
(
bizIdValue
==
null
)
{
bizColumnField
.
setValue
(
entity
,
bizIdType
.
generateBizId
(
entity
));
Object
generatedBizId
=
bizIdType
.
generateBizId
(
entity
);
Class
<?>
bizIdFieldType
=
bizColumnField
.
getFieldType
();
Object
convertedBizId
=
Convert
.
convertQuietly
(
bizIdFieldType
,
generatedBizId
,
null
);
if
(
convertedBizId
==
null
)
{
throw
new
BaseException
(
String
.
format
(
"Cannot convert generated bizId value %s; From %s to %s"
,
generatedBizId
,
generatedBizId
.
getClass
(),
bizIdFieldType
));
}
bizColumnField
.
setValue
(
entity
,
convertedBizId
);
}
}
}
}
}
}
}
}
\ No newline at end of file
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