Chinaunix首页 | 论坛 | 博客
  • 博客访问: 274023
  • 博文数量: 757
  • 博客积分: 40040
  • 博客等级: 大将
  • 技术积分: 4935
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 12:37
文章分类

全部博文(757)

文章存档

2011年(1)

2008年(756)

我的朋友

分类:

2008-09-09 12:39:03

   package sequence;

    import java.util.HashMap;
    import java.util.Map;
    import java.sql.SQLException;

    /**
    * Created by IntelliJ IDEA.

    * User: leizhimin

    * Date: 2008-4-2 15:21:30

    * Note: 实现的Sequence工具
    */
    public class SequenceUtils {
        private static SequenceUtils _instance = new SequenceUtils();
        private Map keyMap = new HashMap(20); //Sequence载体容器
        private static final int POOL_SIZE = 10;      //Sequence值缓存大小

        /**
         * 禁止外部实例化
         */
        private SequenceUtils() {
        }

        /**
         * 获取SequenceUtils的单例对象
         * @return SequenceUtils的单例对象
         */
        public static SequenceUtils getInstance() {
            return _instance;
        }

        /**
         * 获取下一个Sequence键值
         * @param keyName Sequence名称
         * @return 下一个Sequence键值
         */
        public synchronized long getNextKeyValue(String keyName) {
            KeyInfo keyInfo = null;
            Long keyObject = null;
            try {
                if (keyMap.containsKey(keyName)) {
                    keyInfo = keyMap.get(keyName);
                } else {
                    keyInfo = new KeyInfo(keyName, POOL_SIZE);
                    keyMap.put(keyName, keyInfo);
                }
                keyObject = keyInfo.getNextKey();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return keyObject;
        }
    }


--------------------next---------------------

阅读(285) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~