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
a70b45e6
Commit
a70b45e6
authored
Aug 11, 2020
by
雍欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取序列的方法加锁
parent
7c4a22ae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
VersionListener.java
...java/com/huigou/data/domain/listener/VersionListener.java
+22
-9
GeneralRepositorySuper.java
...va/com/huigou/data/repository/GeneralRepositorySuper.java
+1
-1
No files found.
huigou-data/src/main/java/com/huigou/data/domain/listener/VersionListener.java
View file @
a70b45e6
package
com
.
huigou
.
data
.
domain
.
listener
;
package
com
.
huigou
.
data
.
domain
.
listener
;
import
com.huigou.data.query.executor.SQLExecutorDao
;
import
com.huigou.data.repository.GeneralRepositorySuper
;
import
com.huigou.data.query.model.QueryDescriptor
;
import
com.huigou.domain.IdentifiedEntity
;
import
com.huigou.domain.IdentifiedEntity
;
import
com.huigou.util.ApplicationContextWrapper
;
import
com.huigou.util.ApplicationContextWrapper
;
import
org.springframework.beans.factory.annotation.Configurable
;
import
org.springframework.beans.factory.annotation.Configurable
;
import
org.springframework.util.ReflectionUtils
;
import
javax.persistence.PrePersist
;
import
javax.persistence.PrePersist
;
import
javax.persistence.PreUpdate
;
import
javax.persistence.PreUpdate
;
import
java.lang.reflect.Field
;
@Configurable
@Configurable
public
class
VersionListener
{
public
class
VersionListener
{
@Deprecated
@Deprecated
public
final
static
String
GET_NEXT_SEQ_SQL
=
"SELECT version_seq.nextval from DUAL"
;
public
final
static
String
GET_NEXT_SEQ_SQL
=
"SELECT version_seq.nextval from DUAL"
;
private
final
static
String
VERSION_FIELD_NAME
=
"version"
;
private
Long
getNextId
()
{
private
Long
getNextId
()
{
SQLExecutorDao
sqlExecutor
=
ApplicationContextWrapper
.
getBean
(
"sqlExecutorDao"
,
SQLExecutorDao
.
class
);
GeneralRepositorySuper
generalRepository
=
ApplicationContextWrapper
.
getBean
(
GeneralRepositorySuper
.
class
);
QueryDescriptor
queryDescriptor
=
sqlExecutor
.
getQuery
(
"config/uasp/query/bmp/common.xml"
,
"common"
);
return
generalRepository
.
getVersionNextId
();
return
sqlExecutor
.
getSqlQuery
().
getJDBCDao
().
queryToLong
(
String
.
format
(
queryDescriptor
.
getSqlByName
(
"nextSequence"
),
"version_seq"
));
}
}
@PrePersist
@PrePersist
public
void
beforeCreate
(
IdentifiedEntity
target
)
{
public
void
beforeCreate
(
Object
target
)
{
target
.
setVersion
(
getNextId
()
);
updateVersion
(
target
);
}
}
@PreUpdate
@PreUpdate
public
void
beforeUpdate
(
IdentifiedEntity
target
)
{
public
void
beforeUpdate
(
Object
target
)
{
target
.
setVersion
(
getNextId
());
updateVersion
(
target
);
}
private
void
updateVersion
(
Object
target
)
{
if
(
target
instanceof
IdentifiedEntity
)
{
((
IdentifiedEntity
)
target
).
setVersion
(
getNextId
());
}
else
{
Field
field
=
ReflectionUtils
.
findField
(
target
.
getClass
(),
VERSION_FIELD_NAME
);
if
(
field
!=
null
)
{
field
.
setAccessible
(
true
);
ReflectionUtils
.
setField
(
field
,
target
,
getNextId
());
}
}
}
}
}
}
huigou-data/src/main/java/com/huigou/data/repository/GeneralRepositorySuper.java
View file @
a70b45e6
...
@@ -783,7 +783,7 @@ abstract public class GeneralRepositorySuper {
...
@@ -783,7 +783,7 @@ abstract public class GeneralRepositorySuper {
query
.
executeUpdate
();
query
.
executeUpdate
();
}
}
private
long
getNextId
(
String
sequenceName
)
{
private
synchronized
long
getNextId
(
String
sequenceName
)
{
SQLExecutorDao
sqlExecutor
=
ApplicationContextWrapper
.
getBean
(
"sqlExecutorDao"
,
SQLExecutorDao
.
class
);
SQLExecutorDao
sqlExecutor
=
ApplicationContextWrapper
.
getBean
(
"sqlExecutorDao"
,
SQLExecutorDao
.
class
);
QueryDescriptor
queryDescriptor
=
sqlExecutor
.
getQuery
(
"config/uasp/query/bmp/common.xml"
,
"common"
);
QueryDescriptor
queryDescriptor
=
sqlExecutor
.
getQuery
(
"config/uasp/query/bmp/common.xml"
,
"common"
);
return
sqlExecutor
.
getSqlQuery
().
getJDBCDao
().
queryToLong
(
String
.
format
(
queryDescriptor
.
getSqlByName
(
"nextSequence"
),
sequenceName
));
return
sqlExecutor
.
getSqlQuery
().
getJDBCDao
().
queryToLong
(
String
.
format
(
queryDescriptor
.
getSqlByName
(
"nextSequence"
),
sequenceName
));
...
...
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