增加手动释放指定序号功能
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.yanghuanglin</groupId>
|
<groupId>com.yanghuanglin</groupId>
|
||||||
<artifactId>seq</artifactId>
|
<artifactId>seq</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.1.0</version>
|
||||||
<name>seq</name>
|
<name>seq</name>
|
||||||
<description>seq</description>
|
<description>seq</description>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ public interface SequencesUnusedDao {
|
|||||||
*/
|
*/
|
||||||
boolean delete(SequencesUnused sequencesUnused);
|
boolean delete(SequencesUnused sequencesUnused);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存空闲序号
|
||||||
|
*/
|
||||||
|
boolean save(SequencesUnused sequencesUnused);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量保存空闲序号
|
* 批量保存空闲序号
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||||||
* @author yanghuanglin
|
* @author yanghuanglin
|
||||||
* @since 2022/1/28
|
* @since 2022/1/28
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("SqlResolve")
|
||||||
public class SequencesDaoImpl implements SequencesDao {
|
public class SequencesDaoImpl implements SequencesDao {
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final TableConfig tableConfig;
|
private final TableConfig tableConfig;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.List;
|
|||||||
* @author yanghuanglin
|
* @author yanghuanglin
|
||||||
* @since 2022/1/28
|
* @since 2022/1/28
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("SqlResolve")
|
||||||
public class SequencesUnlockDaoImpl implements SequencesUnlockDao {
|
public class SequencesUnlockDaoImpl implements SequencesUnlockDao {
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final TableConfig tableConfig;
|
private final TableConfig tableConfig;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.util.List;
|
|||||||
* @author yanghuanglin
|
* @author yanghuanglin
|
||||||
* @since 2022/1/28
|
* @since 2022/1/28
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("SqlResolve")
|
||||||
public class SequencesUnusedDaoImpl implements SequencesUnusedDao {
|
public class SequencesUnusedDaoImpl implements SequencesUnusedDao {
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final TableConfig tableConfig;
|
private final TableConfig tableConfig;
|
||||||
@@ -55,6 +56,14 @@ public class SequencesUnusedDaoImpl implements SequencesUnusedDao {
|
|||||||
return result != 0;
|
return result != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean save(SequencesUnused sequencesUnused) {
|
||||||
|
String sql = "insert into `%s_ununsed`(`%s`,`%s`,`%s`) values(?,?,?)";
|
||||||
|
sql = String.format(sql, tableConfig.getTable(), tableConfig.getKeyColumn(), tableConfig.getTypeColumn(), tableConfig.getSeqColumn());
|
||||||
|
int result = this.jdbcTemplate.update(sql, sequencesUnused.getKey(), sequencesUnused.getType(), sequencesUnused.getSeq());
|
||||||
|
return result != 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean saveBatch(List<SequencesUnused> sequencesUnusedList) {
|
public boolean saveBatch(List<SequencesUnused> sequencesUnusedList) {
|
||||||
String sql = "insert into `%s_ununsed`(`%s`,`%s`,`%s`) values(?,?,?)";
|
String sql = "insert into `%s_ununsed`(`%s`,`%s`,`%s`) values(?,?,?)";
|
||||||
|
|||||||
@@ -111,4 +111,11 @@ public interface Generator {
|
|||||||
* @param end 结束时间
|
* @param end 结束时间
|
||||||
*/
|
*/
|
||||||
void release(Date begin, Date end);
|
void release(Date begin, Date end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放指定序号。一般用于业务对象删除后,对应序号需要回收使用时。
|
||||||
|
*
|
||||||
|
* @param sequences 需要释放的序号。一般是一个通过{@link Sequences#setKey(String)}、{@link Sequences#setType(String)}、{@link Sequences#setSeq(Long)}三方法一起手动构建或通过{@link Sequences#Sequences(String, String, Long)}构造方法构建的实例对象
|
||||||
|
*/
|
||||||
|
void release(Sequences sequences);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,22 +2,25 @@ package com.yanghuanglin.seq.generator.impl;
|
|||||||
|
|
||||||
import com.yanghuanglin.seq.config.GeneratorConfig;
|
import com.yanghuanglin.seq.config.GeneratorConfig;
|
||||||
import com.yanghuanglin.seq.dao.SequencesDao;
|
import com.yanghuanglin.seq.dao.SequencesDao;
|
||||||
import com.yanghuanglin.seq.dao.SequencesUnusedDao;
|
|
||||||
import com.yanghuanglin.seq.dao.SequencesUnlockDao;
|
import com.yanghuanglin.seq.dao.SequencesUnlockDao;
|
||||||
|
import com.yanghuanglin.seq.dao.SequencesUnusedDao;
|
||||||
import com.yanghuanglin.seq.dao.impl.SequencesDaoImpl;
|
import com.yanghuanglin.seq.dao.impl.SequencesDaoImpl;
|
||||||
import com.yanghuanglin.seq.dao.impl.SequencesUnusedDaoImpl;
|
|
||||||
import com.yanghuanglin.seq.dao.impl.SequencesUnlockDaoImpl;
|
import com.yanghuanglin.seq.dao.impl.SequencesUnlockDaoImpl;
|
||||||
import com.yanghuanglin.seq.po.Sequences;
|
import com.yanghuanglin.seq.dao.impl.SequencesUnusedDaoImpl;
|
||||||
import com.yanghuanglin.seq.po.SequencesUnused;
|
|
||||||
import com.yanghuanglin.seq.po.SequencesUnlock;
|
|
||||||
import com.yanghuanglin.seq.generator.Generator;
|
import com.yanghuanglin.seq.generator.Generator;
|
||||||
|
import com.yanghuanglin.seq.po.Sequences;
|
||||||
|
import com.yanghuanglin.seq.po.SequencesUnlock;
|
||||||
|
import com.yanghuanglin.seq.po.SequencesUnused;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.jdbc.support.JdbcTransactionManager;
|
import org.springframework.jdbc.support.JdbcTransactionManager;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class SequencesGenerator implements Generator {
|
public class SequencesGenerator implements Generator {
|
||||||
private final TransactionTemplate transactionTemplate;
|
private final TransactionTemplate transactionTemplate;
|
||||||
@@ -185,4 +188,10 @@ public class SequencesGenerator implements Generator {
|
|||||||
//删除指定时间段内使用中表的数据
|
//删除指定时间段内使用中表的数据
|
||||||
sequencesUnlockDao.deleteByDate(begin, end);
|
sequencesUnlockDao.deleteByDate(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void release(Sequences sequences) {
|
||||||
|
sequencesUnlockDao.delete(new SequencesUnlock(sequences));
|
||||||
|
sequencesUnusedDao.save(new SequencesUnused(sequences));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ public class Sequences {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Sequences(String key, String type, Long seq) {
|
||||||
|
this.key = key;
|
||||||
|
this.type = type;
|
||||||
|
this.seq = seq;
|
||||||
|
}
|
||||||
|
|
||||||
public Sequences(SequencesUnused sequencesUnused) {
|
public Sequences(SequencesUnused sequencesUnused) {
|
||||||
this.key = sequencesUnused.getKey();
|
this.key = sequencesUnused.getKey();
|
||||||
this.type = sequencesUnused.getType();
|
this.type = sequencesUnused.getType();
|
||||||
|
|||||||
Reference in New Issue
Block a user