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

📄 localpooldeployer.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.management;// PoolMan Classesimport com.codestudio.util.*;import java.beans.*;import java.util.ArrayList;import java.util.Iterator;import java.util.Properties;public class LocalPoolDeployer implements PoolManDeployer, Runnable {    public void deployConfiguration(PoolManConfiguration config) throws Exception {        startDataSources(config.getDataSources());        startGenericPools(config.getGenericPools());        // Note: there is no admin for the non-JMX PoolMan        // add VM shutdown event handler        try {            // use reflection and catch the Exception to allow PoolMan to work with 1.2 VM's            Class r = Runtime.getRuntime().getClass();            java.lang.reflect.Method m =                    r.getDeclaredMethod("addShutdownHook", new Class[]{Thread.class});            m.invoke(Runtime.getRuntime(), new Object[]{new Thread(this)});        } catch (Exception e) {        }    }    public void run() {        try {            // get SQLManager and closeAllResources            SQLManager.getInstance().destroyPools();            GenericPoolManager.getInstance().destroyPools();        } catch (Exception e) {            System.out.println("Unable to properly shutdown: " + e);        }    }    private void startDataSources(ArrayList datasources) throws Exception {        if (datasources == null)            return;        for (Iterator iter = datasources.iterator(); iter.hasNext();) {            // Get each set of datasource entries            Properties dbprops = (Properties) iter.next();            // create the metadata object            JDBCPoolMetaData metadata = new JDBCPoolMetaData();            BeanInfo beanInfo = Introspector.getBeanInfo(metadata.getClass());            // set attributes based on properties            PropertyDescriptor[] attributes = beanInfo.getPropertyDescriptors();            for (int n = 0; n < attributes.length; n++) {                // get bean attribute name                String attrName = attributes[n].getName();                if (dbprops.containsKey(attrName.toLowerCase())) {                    // get value in props                    String propsVal = dbprops.getProperty(attrName.toLowerCase());                    Class type = attributes[n].getPropertyType();                    // create attribute value of correct type                    PropertyEditor editor = PropertyEditorManager.findEditor(type);                    editor.setAsText(propsVal);                    Object value = editor.getValue();                    // set attribute value on bean                    attributes[n].getWriteMethod().invoke(metadata, new Object[]{value});                }            }            JDBCPool jpool = SQLManager.getInstance().createPool(metadata);            jpool.log("PoolMan Local Pool Deployer: Created JDBC Connection Pool named: " + metadata.getDbname());        }    }    private void startGenericPools(ArrayList genericObjects) throws Exception {        if (genericObjects == null)            return;        for (Iterator iter = genericObjects.iterator(); iter.hasNext();) {            // Get each set of pool entries            Properties props = (Properties) iter.next();            GenericPoolMetaData metadata = new GenericPoolMetaData();            // set attributes based on properties            BeanInfo beanInfo = Introspector.getBeanInfo(metadata.getClass());            // set attributes based on properties            PropertyDescriptor[] attributes = beanInfo.getPropertyDescriptors();            for (int n = 0; n < attributes.length; n++) {                // get attribute name                String attrName = attributes[n].getName();                if (props.containsKey(attrName.toLowerCase())) {                    // get value in props                    String propsVal = props.getProperty(attrName.toLowerCase());                    Class type = attributes[n].getPropertyType();                    // create attribute value of correct type                    PropertyEditor editor = PropertyEditorManager.findEditor(type);                    editor.setAsText(propsVal);                    Object value = editor.getValue();                    attributes[n].getWriteMethod().invoke(metadata, new Object[]{value});                }            }            GenericPool gpool = GenericPoolManager.getInstance().createPool(metadata);            gpool.log("PoolMan Local Pool Deployer: Created Object Pool Named: " + metadata.getName());        }    }}

⌨️ 快捷键说明

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