Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
Overview
Overview
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
s_guodong
gjjs-bd-common
Commits
30b251f4
Commit
30b251f4
authored
Mar 04, 2024
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lock和unlock的实现
parent
68d67c7f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
1 deletions
+99
-1
lckmapper.xml
gjjs-bd-business/src/main/resources/mapper/lckmapper.xml
+18
-0
DBLocker.java
...ain/java/com/brilliance/mda/support/mybatis/DBLocker.java
+33
-1
LckMapper.java
...ava/com/brilliance/mda/support/mybatis/lck/LckMapper.java
+48
-0
No files found.
gjjs-bd-business/src/main/resources/mapper/lckmapper.xml
0 → 100644
View file @
30b251f4
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.brilliance.mda.support.mybatis.lck.LckMapper"
>
<insert
id=
"insert"
>
insert into LCK(NAM,TXT,DATTIM) values(#{nam},#{key},#{date})
</insert>
<select
id=
"select"
resultType=
"java.util.Map"
>
select * from LCK where TXT = #{key}
</select>
<select
id=
"delete"
resultType=
"java.lang.Integer"
>
delete from LCK where TXT = #{key}
</select>
</mapper>
\ No newline at end of file
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/DBLocker.java
View file @
30b251f4
package
com
.
brilliance
.
mda
.
support
.
mybatis
;
package
com
.
brilliance
.
mda
.
support
.
mybatis
;
import
com.brilliance.mda.runtime.mda.Constants
;
import
com.brilliance.mda.runtime.mda.ILocker
;
import
com.brilliance.mda.runtime.mda.ILocker
;
import
com.brilliance.mda.runtime.mda.LockInfo
;
import
com.brilliance.mda.runtime.mda.LockInfo
;
import
com.brilliance.mda.runtime.mda.driver.MdaEnv
;
import
com.brilliance.mda.support.mybatis.lck.LckMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
@Component
@Component
public
class
DBLocker
implements
ILocker
{
public
class
DBLocker
implements
ILocker
{
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
DBLocker
.
class
);
@Autowired
private
LckMapper
lckMapper
;
@Override
@Override
public
boolean
lock
(
Serializable
key
)
{
public
boolean
lock
(
Serializable
key
)
{
...
@@ -26,14 +39,33 @@ public class DBLocker implements ILocker {
...
@@ -26,14 +39,33 @@ public class DBLocker implements ILocker {
}
}
@Override
@Override
public
LockInfo
lock
(
String
userName
,
Serializable
key
)
{
public
LockInfo
lock
(
String
lockName
,
Serializable
key
)
{
Date
date
=
new
Date
();
try
{
lckMapper
.
insert
(
lockName
,
key
.
toString
(),
date
);
}
catch
(
Exception
e
)
{
log
.
warn
(
"获取锁失败,key:{}已经被锁定"
,
key
);
MdaEnv
.
getContext
().
setErrorCode
(
Constants
.
ERROR_LOCKED
);
return
null
;
}
List
<
Map
>
list
=
lckMapper
.
select
(
key
.
toString
());
if
(
list
.
size
()
>
1
)
{
log
.
warn
(
"获取锁失败,key:{}已经被锁定"
,
key
);
MdaEnv
.
getContext
().
setErrorCode
(
Constants
.
ERROR_LOCKED
);
return
null
;
return
null
;
}
}
return
new
LockInfo
(
date
,
key
.
toString
());
}
@Override
@Override
public
boolean
unlock
(
Serializable
key
)
{
public
boolean
unlock
(
Serializable
key
)
{
try
{
lckMapper
.
delete
(
key
.
toString
());
}
catch
(
Exception
e
)
{
return
false
;
return
false
;
}
}
return
true
;
}
@Override
@Override
public
boolean
unlock
(
String
lockname
,
Serializable
key
)
{
public
boolean
unlock
(
String
lockname
,
Serializable
key
)
{
...
...
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/lck/LckMapper.java
0 → 100644
View file @
30b251f4
package
com
.
brilliance
.
mda
.
support
.
mybatis
.
lck
;
import
org.apache.ibatis.annotations.Param
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
LckMapper
{
final
String
FNAME
=
this
.
getClass
().
getName
();
@Autowired
public
SqlSessionTemplate
template
;
public
Integer
insert
(
@Param
(
"nam"
)
String
nam
,
@Param
(
"key"
)
String
key
,
@Param
(
"date"
)
Date
date
)
{
// // INSERT INTO LCK(NAM,TXT,DATTIM) VALUES(?,?,?)
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"nam"
,
nam
);
map
.
put
(
"key"
,
key
);
map
.
put
(
"date"
,
date
);
return
template
.
insert
(
FNAME
+
".insert"
,
map
);
}
public
List
<
Map
>
select
(
@Param
(
"key"
)
String
key
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"key"
,
key
);
return
template
.
selectList
(
FNAME
+
".select"
,
map
);
}
public
Integer
delete
(
@Param
(
"key"
)
String
key
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"key"
,
key
);
return
template
.
delete
(
FNAME
+
".delete"
,
map
);
}
}
\ 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