Commit 42246fae by s_guodong

dbcounter查一条返回多条的兼容处理

parent 007035bd
......@@ -11,7 +11,7 @@
</select>
<update id="updateCounter" >
update TBLCNT set VAL = VAL + STP where TYP = #{typ}
update TBLCNT set VAL = #{val} + STP where TYP = #{typ}
</update>
<select id="seqNextval" resultType="java.lang.Integer" >
......
......@@ -11,7 +11,7 @@
</select>
<update id="updateCounter" >
update CNT set VAL = VAL + STP where NAM = #{nam}
update CNT set VAL = #{val} + STP where NAM = #{nam}
</update>
<select id="seqNextval" resultType="java.lang.Integer" >
......
......@@ -38,14 +38,14 @@ public class CounterImplWithSpringTransaction implements CounterService {
cnt = 0;
counterMapper.insertNewCounter(seqname, 1); //插入新数
} else
counterMapper.updateCounter(seqname); //计算器增加
counterMapper.updateCounter(seqname,cnt); //计算器增加
} catch (Exception e) {
throw (new RuleExecuteException("主键生成异常", e));
} finally {
lock.unlock();
}
} else
counterMapper.updateCounter(seqname); //计算器增加
counterMapper.updateCounter(seqname,cnt); //计算器增加
return cnt;
}
......@@ -62,14 +62,14 @@ public class CounterImplWithSpringTransaction implements CounterService {
cnt = 0;
tblCounterMapper.insertNewCounter(seqname, 1); //插入新数
} else
tblCounterMapper.updateCounter(seqname); //计算器增加
tblCounterMapper.updateCounter(seqname,cnt); //计算器增加
} catch (Exception e) {
throw (new RuleExecuteException("主键生成异常", e));
} finally {
lock.unlock();
}
} else
tblCounterMapper.updateCounter(seqname); //计算器增加
tblCounterMapper.updateCounter(seqname,cnt); //计算器增加
return cnt;
}
}
package com.brilliance.mda.support.mybatis.count.mapper;
import java.util.HashMap;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class CounterMapper{
public class CounterMapper {
final String FNAME = this.getClass().getName();
......@@ -19,29 +20,36 @@ public class CounterMapper{
public SqlSessionTemplate template;
public Integer getCountValWithUpdate(@Param("nam") String seqName){
return template.selectOne(FNAME+".getCountValWithUpdate",seqName);
public Integer getCountValWithUpdate(@Param("nam") String seqName) {
List<Integer> lst = template.selectList(FNAME + ".getCountValWithUpdate", seqName);
if (lst.isEmpty()) {
return null;
}
return Collections.max(lst);
}
public int insertNewCounter(@Param("nam") String nam, @Param("stp") int stp){
public int insertNewCounter(@Param("nam") String nam, @Param("stp") int stp) {
Map<String, Object> map = new HashMap<>();
map.put("nam", nam);
map.put("start",1);
map.put("start", 1);
map.put("stp", stp);
return template.insert(FNAME+".insertNewCounter",map);
return template.insert(FNAME + ".insertNewCounter", map);
}
public void updateCounter(@Param("nam") String seqName){
template.selectOne(FNAME+".updateCounter",seqName);
public void updateCounter(@Param("nam") String seqName, @Param("val") int val) {
Map<String, Object> map = new HashMap<>();
map.put("nam", seqName);
map.put("val", val);
template.selectList(FNAME + ".updateCounter", map);
}
public int seqNextval(String seqName) {
return template.selectOne(FNAME+".seqNextval",seqName);
return template.selectOne(FNAME + ".seqNextval", seqName);
}
public int dbCounter(String seqName){
return template.selectOne(FNAME+".dbCounter",seqName);
public int dbCounter(String seqName) {
return template.selectOne(FNAME + ".dbCounter", seqName);
}
}
\ No newline at end of file
......@@ -5,7 +5,9 @@ import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -18,29 +20,35 @@ public class TblCounterMapper {
public SqlSessionTemplate template;
public Integer getCountValWithUpdate(@Param("typ") String seqName){
return template.selectOne(FNAME+".getCountValWithUpdate",seqName);
public Integer getCountValWithUpdate(@Param("typ") String seqName) {
List<Integer> lst = template.selectList(FNAME + ".getCountValWithUpdate", seqName);
if (lst.isEmpty()) {
return null;
}
return Collections.max(lst);
}
public int insertNewCounter(@Param("typ") String typ, @Param("stp") int stp){
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("start", 1);
map.put("stp", stp);
return template.insert(FNAME+".insertNewCounter",map);
return template.insert(FNAME + ".insertNewCounter", map);
}
public void updateCounter(@Param("typ") String seqName){
template.selectOne(FNAME+".updateCounter",seqName);
public void updateCounter(@Param("typ") String seqName, @Param("val") int val) {
Map<String, Object> map = new HashMap<>();
map.put("typ", seqName);
map.put("val", val);
template.selectList(FNAME + ".updateCounter", map);
}
public int seqNextval(String seqName) {
return template.selectOne(FNAME+".seqNextval",seqName);
return template.selectOne(FNAME + ".seqNextval", seqName);
}
public int dbCounter(String seqName){
return template.selectOne(FNAME+".dbCounter",seqName);
public int dbCounter(String seqName) {
return template.selectOne(FNAME + ".dbCounter", seqName);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment