Skip to content

Commit

Permalink
refac[litemall-db]: 采用乐观锁更新操作
Browse files Browse the repository at this point in the history
  • Loading branch information
linlinjava committed Sep 3, 2018
1 parent 4926211 commit f52dcd3
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public int countSelective(String name, String content, Integer page, Integer siz
return (int) adMapper.countByExample(example);
}

public void updateById(LitemallAd ad) {
adMapper.updateByPrimaryKeySelective(ad);
public int updateById(LitemallAd ad) {
return adMapper.updateWithVersionByPrimaryKeySelective(ad.getVersion(), ad);
}

public void deleteById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public int countSelective(String username, Integer page, Integer size, String so
return (int)adminMapper.countByExample(example);
}

public void updateById(LitemallAdmin admin) {
adminMapper.updateByPrimaryKeySelective(admin);
public int updateById(LitemallAdmin admin) {
return adminMapper.updateWithVersionByPrimaryKeySelective(admin.getVersion(), admin);
}

public void deleteById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public int countSelective(String id, String name, Integer page, Integer size, St
return (int) brandMapper.countByExample(example);
}

public void updateById(LitemallBrand brand) {
brandMapper.updateByPrimaryKeySelective(brand);
public int updateById(LitemallBrand brand) {
return brandMapper.updateWithVersionByPrimaryKeySelective(brand.getVersion(), brand);
}

public void deleteById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public void add(LitemallCart cart) {
cartMapper.insertSelective(cart);
}

public void update(LitemallCart cart) {
cartMapper.updateByPrimaryKey(cart);
public int update(LitemallCart cart) {
return cartMapper.updateWithVersionByPrimaryKeySelective(cart.getVersion(), cart);
}

public List<LitemallCart> queryByUid(int userId) {
Expand All @@ -42,12 +42,6 @@ public List<LitemallCart> queryByUidAndChecked(Integer userId) {
return cartMapper.selectByExample(example);
}

public List<LitemallCart> queryByUidAndSid(int userId, String sessionId) {
LitemallCartExample example = new LitemallCartExample();
example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
return cartMapper.selectByExample(example);
}

public int delete(List<Integer> productIdList, int userId) {
LitemallCartExample example = new LitemallCartExample();
example.or().andUserIdEqualTo(userId).andProductIdIn(productIdList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public int countSelective(String id, String name, Integer page, Integer size, St
return (int)categoryMapper.countByExample(example);
}

public void updateById(LitemallCategory category) {
categoryMapper.updateByPrimaryKeySelective(category);
public int updateById(LitemallCategory category) {
return categoryMapper.updateWithVersionByPrimaryKeySelective(category.getVersion(), category);
}

public void deleteById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ else if(showType == 1){
example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false);
}
else{
Assert.state(false, "showType不支持");
throw new RuntimeException("showType不支持");
}
PageHelper.startPage(offset, limit);
return commentMapper.selectByExample(example);
Expand All @@ -55,21 +55,15 @@ else if(showType == 1){
example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false);
}
else{
Assert.state(false, "");
throw new RuntimeException("showType不支持");
}
return (int)commentMapper.countByExample(example);
}

public Integer save(LitemallComment comment) {
public int save(LitemallComment comment) {
return commentMapper.insertSelective(comment);
}


public void update(LitemallComment comment) {
commentMapper.updateByPrimaryKeySelective(comment);
}


public List<LitemallComment> querySelective(String userId, String valueId, Integer page, Integer size, String sort, String order) {
LitemallCommentExample example = new LitemallCommentExample();
example.setOrderByClause(LitemallComment.Column.addTime.desc());
Expand Down Expand Up @@ -106,19 +100,8 @@ public int countSelective(String userId, String valueId, Integer page, Integer s
return (int)commentMapper.countByExample(example);
}

public void updateById(LitemallComment comment) {
commentMapper.updateByPrimaryKeySelective(comment);
}

public void deleteById(Integer id) {
commentMapper.logicalDeleteByPrimaryKey(id);
}

public void add(LitemallComment comment) {
commentMapper.insertSelective(comment);
}

public LitemallComment findById(Integer id) {
return commentMapper.selectByPrimaryKey(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ public List<LitemallGoodsAttribute> queryByGid(Integer goodsId) {
return goodsAttributeMapper.selectByExample(example);
}

public void updateById(LitemallGoodsAttribute goodsAttribute) {
goodsAttributeMapper.updateByPrimaryKeySelective(goodsAttribute);
}

public void deleteById(Integer id) {
goodsAttributeMapper.logicalDeleteByPrimaryKey(id);
}

public void add(LitemallGoodsAttribute goodsAttribute) {
goodsAttributeMapper.insertSelective(goodsAttribute);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ public Integer queryOnSale() {
return (int) goodsMapper.countByExample(example);
}

public void updateById(LitemallGoods goods) {
goodsMapper.updateByPrimaryKeySelective(goods);
public int updateById(LitemallGoods goods) {
return goodsMapper.updateWithVersionByPrimaryKeySelective(goods.getVersion(), goods);
}

public void deleteById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ public LitemallGoodsSpecification findById(Integer id) {
return goodsSpecificationMapper.selectByPrimaryKey(id);
}

public void updateById(LitemallGoodsSpecification goodsSpecification) {
goodsSpecificationMapper.updateByPrimaryKeySelective(goodsSpecification);
}

public void deleteById(Integer id) {
goodsSpecificationMapper.logicalDeleteByPrimaryKey(id);
}

public void deleteByGid(Integer gid) {
LitemallGoodsSpecificationExample example = new LitemallGoodsSpecificationExample();
example.or().andGoodsIdEqualTo(gid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void delete(Integer id) {
mapper.logicalDeleteByPrimaryKey(id);
}

public void update(LitemallGrouponRules grouponRules) {
mapper.updateByPrimaryKeySelective(grouponRules);
public int update(LitemallGrouponRules grouponRules) {
return mapper.updateWithVersionByPrimaryKeySelective(grouponRules.getVersion(), grouponRules);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public int countGroupon(Integer grouponId) {
return (int) mapper.countByExample(example);
}

public void update(LitemallGroupon groupon) {
mapper.updateByPrimaryKey(groupon);
public int update(LitemallGroupon groupon) {
return mapper.updateWithVersionByPrimaryKeySelective(groupon.getVersion(), groupon);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public int countSelective(String question, Integer page, Integer size, String so
return (int)issueMapper.countByExample(example);
}

public void updateById(LitemallIssue issue) {
issueMapper.updateByPrimaryKeySelective(issue);
public int updateById(LitemallIssue issue) {
return issueMapper.updateWithVersionByPrimaryKeySelective(issue.getVersion(), issue);
}

public LitemallIssue findById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ public class LitemallKeywordService {
@Resource
private LitemallKeywordMapper keywordsMapper;

public List<LitemallKeyword> queryDefaults() {
LitemallKeywordExample example = new LitemallKeywordExample();
example.or().andIsDefaultEqualTo(true).andDeletedEqualTo(false);
return keywordsMapper.selectByExample(example);
}

public LitemallKeyword queryDefault() {
LitemallKeywordExample example = new LitemallKeywordExample();
example.or().andIsDefaultEqualTo(true).andDeletedEqualTo(false);
Expand Down Expand Up @@ -85,8 +79,8 @@ public LitemallKeyword findById(Integer id) {
return keywordsMapper.selectByPrimaryKey(id);
}

public void updateById(LitemallKeyword keywords) {
keywordsMapper.updateByPrimaryKeySelective(keywords);
public int updateById(LitemallKeyword keywords) {
return keywordsMapper.updateWithVersionByPrimaryKeySelective(keywords.getVersion(), keywords);
}

public void deleteById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public int add(LitemallOrder order) {
return orderMapper.insertSelective(order);
}

public List<LitemallOrder> query(Integer userId) {
LitemallOrderExample example = new LitemallOrderExample();
example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
return orderMapper.selectByExample(example);
}

public int count(Integer userId) {
LitemallOrderExample example = new LitemallOrderExample();
example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
Expand All @@ -42,21 +36,15 @@ public LitemallOrder findById(Integer orderId) {
private String getRandomNum(Integer num) {
String base = "0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < num; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();
}

public LitemallOrder queryByOrderSn(Integer userId, String orderSn){
LitemallOrderExample example = new LitemallOrderExample();
example.or().andUserIdEqualTo(userId).andOrderSnEqualTo(orderSn).andDeletedEqualTo(false);
return orderMapper.selectOneByExample(example);
}

public int countByOrderSn(Integer userId, String orderSn){
private int countByOrderSn(Integer userId, String orderSn){
LitemallOrderExample example = new LitemallOrderExample();
example.or().andUserIdEqualTo(userId).andOrderSnEqualTo(orderSn).andDeletedEqualTo(false);
return (int)orderMapper.countByExample(example);
Expand Down Expand Up @@ -97,7 +85,7 @@ public int countByOrderStatus(Integer userId, List<Short> orderStatus) {
}

public int update(LitemallOrder order) {
return orderMapper.updateByPrimaryKeySelective(order);
return orderMapper.updateWithVersionByPrimaryKeySelective(order.getVersion(), order);
}

public List<LitemallOrder> querySelective(Integer userId, String orderSn, List<Short> orderStatusArray, Integer page, Integer size, String sort, String order) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public LitemallProduct findById(Integer id) {
return productMapper.selectByPrimaryKey(id);
}

public void updateById(LitemallProduct product) {
productMapper.updateByPrimaryKeySelective(product);
public int updateById(LitemallProduct product) {
return productMapper.updateWithVersionByPrimaryKeySelective(product.getVersion(), product);
}

public void deleteById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,16 @@ public void add(LitemallStorage storageInfo) {
storageMapper.insertSelective(storageInfo);
}

public LitemallStorage findByName(String filename) {
LitemallStorageExample example = new LitemallStorageExample();
example.or().andNameEqualTo(filename).andDeletedEqualTo(false);
return storageMapper.selectOneByExample(example);
}

public LitemallStorage findByKey(String key) {
LitemallStorageExample example = new LitemallStorageExample();
example.or().andKeyEqualTo(key).andDeletedEqualTo(false);
return storageMapper.selectOneByExample(example);
}

public void update(LitemallStorage storageInfo) {
storageMapper.updateByPrimaryKeySelective(storageInfo);
public int update(LitemallStorage storageInfo) {
return storageMapper.updateWithVersionByPrimaryKeySelective(storageInfo.getVersion(), storageInfo);
}


public LitemallStorage findById(Integer id) {
return storageMapper.selectByPrimaryKey(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,9 @@ public class LitemallSystemConfigService {
@Resource
private LitemallSystemMapper systemMapper;

public void add(LitemallSystem litemallSystem) {
systemMapper.insert(litemallSystem);
}

public List<LitemallSystem> queryAll() {
LitemallSystemExample example = new LitemallSystemExample();
example.or();
return systemMapper.selectByExample(example);
}

public LitemallSystem queryByKeyName(String keyName, String groupName) {
LitemallSystemExample example = new LitemallSystemExample();
example.or().andKeyNameEqualTo(keyName);
return systemMapper.selectOneByExample(example);
}

public void deleteById(Integer id) {
systemMapper.deleteByPrimaryKey(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public int countSelective(String title, String subtitle, Integer page, Integer s
return (int) topicMapper.countByExample(example);
}

public void updateById(LitemallTopic topic) {
public int updateById(LitemallTopic topic) {
LitemallTopicExample example = new LitemallTopicExample();
example.or().andIdEqualTo(topic.getId());
topicMapper.updateByExampleWithBLOBs(topic, example);
return topicMapper.updateWithVersionByExampleWithBLOBs(topic.getVersion(), topic, example);
}

public void deleteById(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void updateUserFormId(LitemallUserFormid userFormid) {
//更新或者删除缓存
if (userFormid.getIsprepay() && userFormid.getUseamount() > 1) {
userFormid.setUseamount(userFormid.getUseamount() - 1);
formidMapper.updateByPrimaryKey(userFormid);
formidMapper.updateWithVersionByPrimaryKey(userFormid.getVersion(), userFormid);
} else {
formidMapper.deleteByPrimaryKey(userFormid.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public void add(LitemallUser user) {
userMapper.insertSelective(user);
}

public void update(LitemallUser user) {
userMapper.updateByPrimaryKeySelective(user);
public int update(LitemallUser user) {
return userMapper.updateWithVersionByPrimaryKeySelective(user.getVersion(), user);
}

public List<LitemallUser> querySelective(String username, String mobile, Integer page, Integer size, String sort, String order) {
Expand Down

0 comments on commit f52dcd3

Please sign in to comment.