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
ca07ca28
Commit
ca07ca28
authored
Aug 15, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加tbldbcounter
parent
c70a2719
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
129 additions
and
15 deletions
+129
-15
TblCountermapper.xml
...d-business/src/main/resources/mapper/TblCountermapper.xml
+25
-0
MyBatisDaoSession.java
...com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
+5
-0
CounterImplWithOracleTransaction.java
...pport/mybatis/count/CounterImplWithOracleTransaction.java
+11
-0
CounterImplWithSpringTransaction.java
...pport/mybatis/count/CounterImplWithSpringTransaction.java
+38
-15
CounterService.java
.../brilliance/mda/support/mybatis/count/CounterService.java
+2
-0
TblCounterMapper.java
...ce/mda/support/mybatis/count/mapper/TblCounterMapper.java
+47
-0
IDaoSession.java
...main/java/com/brilliance/mda/runtime/mda/IDaoSession.java
+1
-0
No files found.
gjjs-bd-business/src/main/resources/mapper/TblCountermapper.xml
0 → 100644
View file @
ca07ca28
<?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.count.mapper.TblCounterMapper"
>
<insert
id=
"insertNewCounter"
>
insert into TBLCNT(typ,VAL,STP) values(#{typ},#{start},#{stp})
</insert>
<select
id=
"getCountValWithUpdate"
resultType=
"java.lang.Integer"
>
select VAL from TBLCNT where TYP = #{typ} for update
</select>
<update
id=
"updateCounter"
>
update TBLCNT set VAL = VAL + STP where TYP = #{typ}
</update>
<select
id=
"seqNextval"
resultType=
"java.lang.Integer"
>
select ${value}.nextval from dual
</select>
<select
id=
"dbCounter"
resultType=
"java.lang.Integer"
>
select f_dbcounter(#{seqName}) from dual;
</select>
</mapper>
\ No newline at end of file
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
View file @
ca07ca28
...
@@ -276,6 +276,11 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
...
@@ -276,6 +276,11 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
}
}
@Override
@Override
public
int
tblDbCounter
(
String
seqname
)
{
return
this
.
counter
.
tblDbCounter
(
seqname
);
}
@Override
public
void
dbConnect
()
{
public
void
dbConnect
()
{
sqlSessionTemplate
.
getSqlSessionFactory
().
openSession
(
false
);
sqlSessionTemplate
.
getSqlSessionFactory
().
openSession
(
false
);
}
}
...
...
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/count/CounterImplWithOracleTransaction.java
View file @
ca07ca28
...
@@ -2,6 +2,7 @@ package com.brilliance.mda.support.mybatis.count;
...
@@ -2,6 +2,7 @@ package com.brilliance.mda.support.mybatis.count;
import
com.brilliance.mda.support.mybatis.count.mapper.CounterMapper
;
import
com.brilliance.mda.support.mybatis.count.mapper.CounterMapper
;
import
com.brilliance.mda.support.mybatis.count.mapper.TblCounterMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -19,10 +20,20 @@ public class CounterImplWithOracleTransaction implements CounterService {
...
@@ -19,10 +20,20 @@ public class CounterImplWithOracleTransaction implements CounterService {
@Resource
@Resource
public
CounterMapper
counterMapper
;
public
CounterMapper
counterMapper
;
@Resource
public
TblCounterMapper
tblCounterMapper
;
public
int
dbCounter
(
String
seqname
)
{
public
int
dbCounter
(
String
seqname
)
{
String
seq
=
"SEQ_"
+
seqname
.
toUpperCase
();
String
seq
=
"SEQ_"
+
seqname
.
toUpperCase
();
return
counterMapper
.
seqNextval
(
seq
);
return
counterMapper
.
seqNextval
(
seq
);
}
}
@Override
public
int
tblDbCounter
(
String
seqname
)
{
String
seq
=
"SEQ_"
+
seqname
.
toUpperCase
();
return
tblCounterMapper
.
seqNextval
(
seq
);
}
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/count/CounterImplWithSpringTransaction.java
View file @
ca07ca28
...
@@ -3,6 +3,7 @@ package com.brilliance.mda.support.mybatis.count;
...
@@ -3,6 +3,7 @@ package com.brilliance.mda.support.mybatis.count;
import
com.brilliance.mda.runtime.mda.RuleExecuteException
;
import
com.brilliance.mda.runtime.mda.RuleExecuteException
;
import
com.brilliance.mda.support.mybatis.count.mapper.CounterMapper
;
import
com.brilliance.mda.support.mybatis.count.mapper.CounterMapper
;
import
com.brilliance.mda.support.mybatis.count.mapper.TblCounterMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -20,33 +21,55 @@ public class CounterImplWithSpringTransaction implements CounterService {
...
@@ -20,33 +21,55 @@ public class CounterImplWithSpringTransaction implements CounterService {
@Resource
@Resource
public
CounterMapper
counterMapper
;
public
CounterMapper
counterMapper
;
@Resource
public
TblCounterMapper
tblCounterMapper
;
public
ReentrantLock
lock
=
new
ReentrantLock
();
public
ReentrantLock
lock
=
new
ReentrantLock
();
@Transactional
(
propagation
=
Propagation
.
REQUIRES_NEW
)
@Transactional
(
propagation
=
Propagation
.
REQUIRES_NEW
)
public
int
dbCounter
(
String
seqname
)
public
int
dbCounter
(
String
seqname
)
{
{
Integer
cnt
=
counterMapper
.
getCountValWithUpdate
(
seqname
);
Integer
cnt
=
counterMapper
.
getCountValWithUpdate
(
seqname
);
if
(
cnt
==
null
)
cnt
=
0
;
if
(
cnt
==
null
)
cnt
=
0
;
if
(
cnt
==
0
)
if
(
cnt
==
0
)
{
{
lock
.
lock
();
lock
.
lock
();
try
{
try
{
cnt
=
counterMapper
.
getCountValWithUpdate
(
seqname
);
cnt
=
counterMapper
.
getCountValWithUpdate
(
seqname
);
if
(
cnt
==
null
)
{
if
(
cnt
==
null
)
{
cnt
=
0
;
cnt
=
0
;
counterMapper
.
insertNewCounter
(
seqname
,
1
);
//插入新数
counterMapper
.
insertNewCounter
(
seqname
,
1
);
//插入新数
}
}
else
else
counterMapper
.
updateCounter
(
seqname
);
//计算器增加
counterMapper
.
updateCounter
(
seqname
);
//计算器增加
}
catch
(
Exception
e
)
}
catch
(
Exception
e
)
{
{
throw
(
new
RuleExecuteException
(
"主键生成异常"
,
e
));
throw
(
new
RuleExecuteException
(
"主键生成异常"
,
e
));
}
finally
{
}
finally
{
lock
.
unlock
();
lock
.
unlock
();
}
}
}
}
else
else
counterMapper
.
updateCounter
(
seqname
);
//计算器增加
counterMapper
.
updateCounter
(
seqname
);
//计算器增加
return
cnt
;
return
cnt
;
}
}
@Transactional
(
propagation
=
Propagation
.
REQUIRES_NEW
)
public
int
tblDbCounter
(
String
seqname
)
{
Integer
cnt
=
tblCounterMapper
.
getCountValWithUpdate
(
seqname
);
if
(
cnt
==
null
)
cnt
=
0
;
if
(
cnt
==
0
)
{
lock
.
lock
();
try
{
cnt
=
tblCounterMapper
.
getCountValWithUpdate
(
seqname
);
if
(
cnt
==
null
)
{
cnt
=
0
;
tblCounterMapper
.
insertNewCounter
(
seqname
,
1
);
//插入新数
}
else
tblCounterMapper
.
updateCounter
(
seqname
);
//计算器增加
}
catch
(
Exception
e
)
{
throw
(
new
RuleExecuteException
(
"主键生成异常"
,
e
));
}
finally
{
lock
.
unlock
();
}
}
else
tblCounterMapper
.
updateCounter
(
seqname
);
//计算器增加
return
cnt
;
}
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/count/CounterService.java
View file @
ca07ca28
...
@@ -2,4 +2,6 @@ package com.brilliance.mda.support.mybatis.count;
...
@@ -2,4 +2,6 @@ package com.brilliance.mda.support.mybatis.count;
public
interface
CounterService
{
public
interface
CounterService
{
int
dbCounter
(
String
seqname
);
int
dbCounter
(
String
seqname
);
int
tblDbCounter
(
String
seqname
);
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/count/mapper/TblCounterMapper.java
0 → 100644
View file @
ca07ca28
package
com
.
brilliance
.
mda
.
support
.
mybatis
.
count
.
mapper
;
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.HashMap
;
import
java.util.Map
;
@Component
public
class
TblCounterMapper
{
final
String
FNAME
=
this
.
getClass
().
getName
();
@Autowired
public
SqlSessionTemplate
template
;
public
Integer
getCountValWithUpdate
(
@Param
(
"typ"
)
String
seqName
){
return
template
.
selectOne
(
FNAME
+
".getCountValWithUpdate"
,
seqName
);
}
public
int
insertNewCounter
(
@Param
(
"typ"
)
String
typ
,
@Param
(
"stp"
)
int
stp
){
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"typ"
,
typ
);
map
.
put
(
"start"
,
1
);
map
.
put
(
"stp"
,
stp
);
return
template
.
insert
(
FNAME
+
".insertNewCounter"
,
map
);
}
public
void
updateCounter
(
@Param
(
"typ"
)
String
seqName
){
template
.
selectOne
(
FNAME
+
".updateCounter"
,
seqName
);
}
public
int
seqNextval
(
String
seqName
)
{
return
template
.
selectOne
(
FNAME
+
".seqNextval"
,
seqName
);
}
public
int
dbCounter
(
String
seqName
){
return
template
.
selectOne
(
FNAME
+
".dbCounter"
,
seqName
);
}
}
\ No newline at end of file
gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/IDaoSession.java
View file @
ca07ca28
...
@@ -51,6 +51,7 @@ public interface IDaoSession {
...
@@ -51,6 +51,7 @@ public interface IDaoSession {
*/
*/
int
dbCounter
(
String
seqname
);
int
dbCounter
(
String
seqname
);
int
tblDbCounter
(
String
seqname
);
void
dbConnect
();
void
dbConnect
();
...
...
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