⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 poolmanager.java

📁 Java Database connection pool
💻 JAVA
字号:
/* *  PoolMan Java Object Pooling and Caching Library *  Copyright (C) 1999-2001 The Code Studio * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  The full license is located at the root of this distribution *  in the LICENSE file. */package com.codestudio.util;import com.codestudio.PoolManConstants;import java.io.Serializable;import java.util.Enumeration;import java.util.Hashtable;/** * An object that manages several pools of objects. * @see SQLManager */public class PoolManager implements Serializable {    protected Hashtable pools;    protected ObjectPool defaultpool;    protected PoolManager() {        this.pools = new Hashtable(1);        this.defaultpool = null;    }    public Enumeration getAllPoolnames() {        return pools.keys();    }    public ObjectPool getPool(String name) {        if (name == null)            return this.defaultpool;        if (pools.containsKey(name)) {            try {                return (ObjectPool) pools.get(name);            } catch (Exception e) {                e.printStackTrace();            }        }        throw new NullPointerException("ERROR: Could not locate " + name +                                       ". This usually means that the " +                                       PoolManConstants.XML_CONFIG_FILE +                                       " file could not be found, or that it " +				       "does not contain configuration data for a " +				       "pool with a name equal to " + name);    }    public void addPool(String id, ObjectPool newpool) {        if (this.pools.containsKey(id)) {            System.out.println("ERROR: A pool identified by the id " + id +                               " already exists, ignoring it.");        }        else {            this.pools.put(id, newpool);            if (this.defaultpool == null)                this.defaultpool = newpool;        }    }    public void removePool(String id) {        if (pools.containsKey(id)) {            int th = this.defaultpool.hashCode();            int oh = pools.get(id).hashCode();            if (th == oh)                this.defaultpool = null;            pools.remove(id);        }    }    public Object requestObject() {        try {            return defaultpool.checkOut();        } catch (Exception e) {            System.out.println("ERROR: Could not request object, returning NULL:");        }        return null;    }    public Object requestObject(String poolname) {        ObjectPool pool = null;        try {            pool = (ObjectPool) pools.get(poolname);        } catch (NullPointerException ne) {        }        if (pool != null) {            try {                return pool.checkOut();            } catch (Exception e) {                System.out.println("ERROR: Could not request object, returning NULL:");            }        }        return null;    }    public void returnObject(Object o) {        defaultpool.checkIn(o);    }    public void returnObject(Object o, String poolname) {        ObjectPool pool = null;        try {            pool = (ObjectPool) pools.get(poolname);        } catch (NullPointerException ne) {        }        if (pool != null)            pool.checkIn(o);    }    public void destroyPools() {        if (this.pools != null) {            for (Enumeration enum = pools.keys(); enum.hasMoreElements();) {                Object key = enum.nextElement();                ObjectPool pool = (ObjectPool) pools.get(key);                pool.closeAllResources();            }        }    }}

⌨️ 快捷键说明

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