1 Commits
1.6.2 ... 1.7.2

5 changed files with 86 additions and 12 deletions

View File

@@ -8,7 +8,7 @@
使用方法: 使用方法:
+ 在项目中放置jar包的地方把seq-1.6.2.jar、seq-1.6.2-sources.jar、seq-1.6.2-pom.xml复制过去 + 在项目中放置jar包的地方把seq-1.7.2.jar、seq-1.7.2-sources.jar、seq-1.7.2-pom.xml复制过去
+ 在pom.xml中增加以下内容然后执行maven命令mvn clean + 在pom.xml中增加以下内容然后执行maven命令mvn clean
```xml ```xml
@@ -18,7 +18,7 @@
<dependency> <dependency>
<groupId>com.yanghuanglin</groupId> <groupId>com.yanghuanglin</groupId>
<artifactId>seq</artifactId> <artifactId>seq</artifactId>
<version>1.6.2</version> <version>1.7.2</version>
<exclusions> <exclusions>
<!-- 如若你项目中有引用spring-jdbc则需要排除seq的jdbc依赖 --> <!-- 如若你项目中有引用spring-jdbc则需要排除seq的jdbc依赖 -->
<exclusion> <exclusion>
@@ -50,13 +50,13 @@
</goals> </goals>
<configuration> <configuration>
<!-- ${project.basedir}表示当前项目的根目录 --> <!-- ${project.basedir}表示当前项目的根目录 -->
<file>${project.basedir}/lib/seq-1.6.2.jar</file> <file>${project.basedir}/lib/seq-1.7.2.jar</file>
<pomFile>${project.basedir}/lib/seq-1.6.2-pom.xml</pomFile> <pomFile>${project.basedir}/lib/seq-1.7.2-pom.xml</pomFile>
<sources>${project.basedir}/lib/seq-1.6.2-sources.jar</sources> <sources>${project.basedir}/lib/seq-1.7.2-sources.jar</sources>
<repositoryLayout>default</repositoryLayout> <repositoryLayout>default</repositoryLayout>
<groupId>com.yanghuanglin</groupId> <groupId>com.yanghuanglin</groupId>
<artifactId>seq</artifactId> <artifactId>seq</artifactId>
<version>1.6.2</version> <version>1.7.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<generatePom>true</generatePom> <generatePom>true</generatePom>
</configuration> </configuration>
@@ -461,6 +461,17 @@ public interface Generator {
*/ */
boolean lock(Sequences sequences); boolean lock(Sequences sequences);
/**
* 忽略{@link Sequences#getSeq()} ,仅通过{@link Sequences#getKey()}和{@link Sequences#getType()}来锁定序号。
* <p/>
* 如果ignoreSeq为false则等价于{@link #lock(Sequences)}
*
* @param sequences 需要锁定的序号
* @param ignoreSeq 是否忽略序号
* @return 锁定结果
*/
boolean lock(Sequences sequences, boolean ignoreSeq);
/** /**
* 释放所有未使用的序号 * 释放所有未使用的序号
* <p/> * <p/>
@@ -499,6 +510,16 @@ public interface Generator {
*/ */
void release(Sequences sequences); void release(Sequences sequences);
/**
* 忽略{@link Sequences#getSeq()}来释放指定序号。一般用于业务对象删除后,对应序号需要回收使用时。
* <p/>
* 如果ignoreSeq为false则等价于{@link #release(Sequences)}
*
* @param sequences 需要释放的序号。一般是一个通过{@link Sequences#setKey(String)}、{@link Sequences#setType(String)}、{@link Sequences#setSeq(Long)}三方法一起手动构建或通过{@link Sequences#Sequences(String, String, Long)}构造方法构建的实例对象
* @param ignoreSeq 是否忽略序号
*/
void release(Sequences sequences, boolean ignoreSeq);
/** /**
* 清空所有闲置序号和未锁定序号 * 清空所有闲置序号和未锁定序号
*/ */
@@ -524,4 +545,5 @@ public interface Generator {
void clearBefore(Date end); void clearBefore(Date end);
} }
``` ```

View File

@@ -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.6.2</version> <version>1.7.2</version>
<name>seq</name> <name>seq</name>
<description>seq</description> <description>seq</description>
<properties> <properties>

View File

@@ -33,10 +33,15 @@ public class SequencesUnlockDaoImpl implements SequencesUnlockDao {
@Override @Override
public boolean delete(SequencesUnlock sequencesUnlock) { public boolean delete(SequencesUnlock sequencesUnlock) {
String sql = "delete from `%s_unlock` where `%s`=? and `%s`=? and `%s`=?"; String sql = "delete from `%s_unlock` where `%s`=? and `%s`=?";
sql = String.format(sql, tableConfig.getTable(), tableConfig.getKeyColumn(), tableConfig.getTypeColumn(), tableConfig.getSeqColumn()); sql = String.format(sql, tableConfig.getTable(), tableConfig.getKeyColumn(), tableConfig.getTypeColumn());
int result = this.jdbcTemplate.update(sql, sequencesUnlock.getKey(), sequencesUnlock.getType(), sequencesUnlock.getSeq()); if (sequencesUnlock.getSeq() != null) {
return result != 0; sql += " and `%s`=?";
sql = String.format(sql, tableConfig.getSeqColumn());
return this.jdbcTemplate.update(sql, sequencesUnlock.getKey(), sequencesUnlock.getType(), sequencesUnlock.getSeq()) != 0;
} else {
return this.jdbcTemplate.update(sql, sequencesUnlock.getKey(), sequencesUnlock.getType()) != 0;
}
} }
@Override @Override

View File

@@ -167,6 +167,17 @@ public interface Generator {
*/ */
boolean lock(Sequences sequences); boolean lock(Sequences sequences);
/**
* 忽略{@link Sequences#getSeq()} ,仅通过{@link Sequences#getKey()}和{@link Sequences#getType()}来锁定序号。
* <p/>
* 如果ignoreSeq为false则等价于{@link #lock(Sequences)}
*
* @param sequences 需要锁定的序号
* @param ignoreSeq 是否忽略序号
* @return 锁定结果
*/
boolean lock(Sequences sequences, boolean ignoreSeq);
/** /**
* 释放所有未使用的序号 * 释放所有未使用的序号
* <p/> * <p/>
@@ -205,6 +216,16 @@ public interface Generator {
*/ */
void release(Sequences sequences); void release(Sequences sequences);
/**
* 忽略{@link Sequences#getSeq()}来释放指定序号。一般用于业务对象删除后,对应序号需要回收使用时。
* <p/>
* 如果ignoreSeq为false则等价于{@link #release(Sequences)}
*
* @param sequences 需要释放的序号。一般是一个通过{@link Sequences#setKey(String)}、{@link Sequences#setType(String)}、{@link Sequences#setSeq(Long)}三方法一起手动构建或通过{@link Sequences#Sequences(String, String, Long)}构造方法构建的实例对象
* @param ignoreSeq 是否忽略序号
*/
void release(Sequences sequences, boolean ignoreSeq);
/** /**
* 清空所有闲置序号和未锁定序号 * 清空所有闲置序号和未锁定序号
*/ */

View File

@@ -111,7 +111,7 @@ public class SequencesGenerator implements Generator {
@Override @Override
public synchronized String generate(String key, String type, Integer minLength) { public synchronized String generate(String key, String type, Integer minLength) {
Sequences sequences = this.generate(key, type); Sequences sequences = generate(key, type);
if (sequences == null) if (sequences == null)
return null; return null;
return sequences.format(minLength); return sequences.format(minLength);
@@ -242,6 +242,18 @@ public class SequencesGenerator implements Generator {
return sequencesUnlockDao.delete(condition); return sequencesUnlockDao.delete(condition);
} }
@Override
public synchronized boolean lock(Sequences sequences, boolean ignoreSeq) {
if (!ignoreSeq)
return lock(sequences);
if (sequences == null)
return true;
SequencesUnlock condition = new SequencesUnlock(sequences);
condition.setSeq(null);
//将使用中表的对应数据删除,空闲表中数据在生成时会删除,因此这里不需要处理该表
return sequencesUnlockDao.delete(condition);
}
@Override @Override
public synchronized void release() { public synchronized void release() {
//列出所有使用中表存在的序号 //列出所有使用中表存在的序号
@@ -292,6 +304,20 @@ public class SequencesGenerator implements Generator {
sequencesUnusedDao.save(new SequencesUnused(sequences, new Date())); sequencesUnusedDao.save(new SequencesUnused(sequences, new Date()));
} }
@Override
public synchronized void release(Sequences sequences, boolean ignoreSeq) {
if (!ignoreSeq) {
release(sequences);
return;
}
if (sequences == null)
return;
SequencesUnlock sequencesUnlock = new SequencesUnlock(sequences);
sequencesUnlock.setSeq(null);
sequencesUnlockDao.delete(sequencesUnlock);
//由于忽略了序号因此不需要将未使用序号放到SequencesUnused里面
}
@Override @Override
public synchronized void clear() { public synchronized void clear() {
sequencesUnlockDao.deleteAll(); sequencesUnlockDao.deleteAll();