Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sso
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
曲欣亮
sso
Commits
820edb78
Commit
820edb78
authored
Jul 05, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加公共工具CommonService, 使用乐观锁,用于生成全局唯一ID
parent
1f539600
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
0 deletions
+93
-0
XRException.java
src/main/java/com/egolm/sso/config/XRException.java
+31
-0
CommonService.java
src/main/java/com/egolm/sso/service/CommonService.java
+7
-0
CommonServiceImpl.java
...in/java/com/egolm/sso/service/impl/CommonServiceImpl.java
+50
-0
MaterialMasterServiceImpl.java
...com/egolm/sso/service/impl/MaterialMasterServiceImpl.java
+5
-0
No files found.
src/main/java/com/egolm/sso/config/XRException.java
0 → 100644
View file @
820edb78
package
com
.
egolm
.
sso
.
config
;
public
class
XRException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
1L
;
public
XRException
(
String
msg
)
{
super
(
msg
);
}
public
XRException
(
String
msg
,
Throwable
e
)
{
super
(
msg
,
e
);
}
public
XRException
(
String
msg
,
int
code
)
{
super
(
msg
);
}
public
XRException
(
String
msg
,
int
code
,
Throwable
e
)
{
super
(
msg
,
e
);
}
public
static
void
assertNotBlank
(
String
message
,
Object
...
objs
)
{
for
(
Object
obj
:
objs
)
{
if
(
obj
==
null
||
obj
.
toString
().
trim
().
equals
(
""
))
{
throw
new
XRException
((
message
==
null
||
message
.
trim
().
equals
(
""
))
?
"对象不能为空"
:
message
);
}
}
}
}
src/main/java/com/egolm/sso/service/CommonService.java
0 → 100644
View file @
820edb78
package
com
.
egolm
.
sso
.
service
;
public
interface
CommonService
{
public
Long
getNextval
(
String
sName
);
}
src/main/java/com/egolm/sso/service/impl/CommonServiceImpl.java
0 → 100644
View file @
820edb78
package
com
.
egolm
.
sso
.
service
.
impl
;
import
java.text.MessageFormat
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.EmptyResultDataAccessException
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
com.egolm.sso.config.XRException
;
import
com.egolm.sso.service.CommonService
;
@Service
public
class
CommonServiceImpl
implements
CommonService
{
@Autowired
private
JdbcTemplate
jdbcTemplate
;
public
Long
getNextval
(
String
sName
)
{
try
{
Map
<
String
,
Object
>
seqMap
=
jdbcTemplate
.
queryForMap
(
"select * from sequence where name = ?"
,
sName
);
Integer
id
=
(
Integer
)
seqMap
.
get
(
"id"
);
Long
step
=
(
Long
)
seqMap
.
get
(
"step"
);
Long
max
=
(
Long
)
seqMap
.
get
(
"max"
);
Long
min
=
(
Long
)
seqMap
.
get
(
"min"
);
Long
value
=
(
Long
)
seqMap
.
get
(
"value"
);
Long
nextValue
=
value
+
step
;
if
(
value
>
max
||
value
<
min
)
{
throw
new
XRException
(
MessageFormat
.
format
(
"序列已超出许可范围[{0}]"
,
sName
));
}
else
{
String
sql
=
"update sequence set value = ? where id = ? and value < ?"
;
int
count
=
jdbcTemplate
.
update
(
sql
,
nextValue
,
id
,
nextValue
);
if
(
count
==
1
)
{
return
value
;
}
else
if
(
count
==
0
)
{
return
this
.
getNextval
(
sName
);
}
else
{
throw
new
XRException
(
MessageFormat
.
format
(
"序列错误[{0}]"
,
sName
));
}
}
}
catch
(
EmptyResultDataAccessException
e
)
{
String
sql
=
"insert into sequence (name, max, min, step, value) values (?, ?, ?, ?, ?)"
;
jdbcTemplate
.
update
(
sql
,
sName
,
Long
.
MAX_VALUE
,
1L
,
1L
,
1L
);
return
this
.
getNextval
(
sName
);
}
}
}
src/main/java/com/egolm/sso/service/impl/MaterialMasterServiceImpl.java
View file @
820edb78
...
...
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Component
;
import
com.egolm.sso.service.CommonService
;
import
com.egolm.sso.service.MaterialMasterService
;
@Component
...
...
@@ -15,8 +16,12 @@ public class MaterialMasterServiceImpl implements MaterialMasterService {
@Autowired
JdbcTemplate
jdbcTemplate
;
@Autowired
CommonService
common
;
@Override
public
void
execute
(
String
xml
)
{
System
.
out
.
println
(
common
.
getNextval
(
"Test"
));
System
.
out
.
println
(
xml
);
}
...
...
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