sequence.java

来自「一个很好的开源项目管理系统源代码」· Java 代码 · 共 84 行

JAVA
84
字号
package net.java.workeffort.service.support;import net.java.workeffort.infrastructure.sequence.ISequence;import net.java.workeffort.service.ISequenceService;/** * The sequence generator. * <p> * Thread and cluster save sequence generater which will work for all databases. * <p> * Will load a block of sequences and hand them out. When the block runs out of * sequences it will hit the database to get the next block of sequences. The * block size for each sequence is configured using Spring. * <p> * Note that there will be gaps in the sequence. This will happen any time you * bounce the application server. Also in a clustered environment the inserted * records will have sequences out of order (Unless you have the block size set * to 0) because each node in the cluster gets its own block of sequences. * @author Antony Joseph */public class Sequence implements ISequence {    private long currentKeyValue = -1; // not populated indicator.    private long maxBlockKeyValue;    private String name;    private int blockSize;    private ISequenceService sequenceService;    public synchronized Long getNextId() {        if (currentKeyValue < maxBlockKeyValue && currentKeyValue != -1)            return new Long(++currentKeyValue);        else {            currentKeyValue = (sequenceService.getNextBlockSequenceId(name,                    new Integer(blockSize))).longValue();            maxBlockKeyValue = currentKeyValue + blockSize;            return new Long(currentKeyValue);        }    }    /**     * @return Returns the blockSize.     */    public int getBlockSize() {        return blockSize;    }    /**     * @param blockSize The blockSize to set.     */    public void setBlockSize(int blockSize) {        this.blockSize = blockSize;    }    /**     * @return Returns the sequenceService.     */    public ISequenceService getSequenceService() {        return sequenceService;    }    /**     * @param sequenceService The sequenceService to set. IOC     */    public void setSequenceService(ISequenceService sequenceService) {        this.sequenceService = sequenceService;    }    /**     * @return Returns the name.     */    public String getName() {        return name;    }    /**     * @param name The name to set. IOC     */    public void setName(String name) {        this.name = name;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?