数据库表中MAX ID获取,确保每次调用没有重复工具类(NumberUtil)

下面这个类是获取数据库中一个字段的最大值。配置在数据库中。

public class NoFactory { private final static Logger cLogger = Logger.getLogger(NoFactory.class); protected static final byte cClusterId = 0; protected static final byte cClusterCount = 1; private static final byte[] BLCTRANNOId = new byte[0]; private static int BLCTRANNO; static { try { BLCTRANNO = Integer.parseInt(new ExeSQL().getOneValue("select max(to_number(BLCTRANNO)) from edorrenewalbalanceacc where mod(BLCTRANNO,"+cClusterCount+")="+cClusterId)); } catch (Throwable ex) { cLogger.error("初始化最大号异常!", ex); } } public final static int nextBLCTRANNONo() { synchronized (BLCTRANNOId) { BLCTRANNO += cClusterCount; } return BLCTRANNO; } public final static void setBLCTRANNONo(int pMaxNo) { synchronized (BLCTRANNOId) { BLCTRANNO = pMaxNo - pMaxNo%cClusterCount + cClusterId; } } }

  

posted @ 2013-11-01 21:48  程序员张越  阅读(346)  评论(0编辑  收藏  举报