一、前言
关于informa源码包中de.nava.informa.impl.basic.IdGeneratorIF、de.nava.informa.impl.basic.IdGenerator序列定义接口及实现类,通过System.currentTimeMillis()随机数取绝对值+100000L组合成序列id主键,详情参见源码说明部分。
二、源码说明
1.IdGeneratorIF接口
package de.nava.informa.core;@b@@b@public abstract interface IdGeneratorIF@b@{@b@ public abstract long getId();@b@}
2.IdGenerator实现类
package de.nava.informa.impl.basic;@b@@b@import de.nava.informa.core.IdGeneratorIF;@b@import java.util.Random;@b@@b@public class IdGenerator@b@ implements IdGeneratorIF@b@{@b@ private static IdGenerator instance;@b@ private static transient Random rand;@b@@b@ public static IdGenerator getInstance()@b@ {@b@ if (instance == null)@b@ instance = new IdGenerator();@b@@b@ return instance;@b@ }@b@@b@ public long getId() {@b@ return (100000L + Math.abs(rand.nextInt()));@b@ }@b@@b@ private IdGenerator()@b@ {@b@ rand = new Random(System.currentTimeMillis());@b@ }@b@}