📄 torqueclassicdatasource.java
字号:
package org.apache.torque.pool;/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Turbine" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */import java.io.PrintWriter;import java.io.Serializable;import java.sql.Connection;import java.sql.SQLException;import java.util.HashMap;import java.util.Hashtable;import java.util.Map;import java.util.Properties;import javax.naming.BinaryRefAddr;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.Name;import javax.naming.NamingException;import javax.naming.RefAddr;import javax.naming.Reference;import javax.naming.Referenceable;import javax.naming.StringRefAddr;import javax.naming.spi.ObjectFactory;import javax.sql.ConnectionPoolDataSource;import javax.sql.DataSource;import org.apache.commons.lang.SerializationUtils;/** * Torque's default connection pool DataSource * * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a> * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> * @version $Id: TorqueClassicDataSource.java,v 1.11 2003/08/18 21:48:11 mpoeschl Exp $ * @deprecated as of version 3.1 */public class TorqueClassicDataSource implements DataSource, Referenceable, Serializable, ObjectFactory{ /** Pools keyed by username. */ private static Map pools = new HashMap(); /** Counter used to create an internal unique name od the Data Source */ private static int cpdsCounter; /** DataSource Name used to find the ConnectionPoolDataSource */ private String dataSourceName; /** Description */ private String description; /** Login TimeOut in seconds */ private int loginTimeout; /** Pool Data Source that is used to fetch connections */ private ConnectionPoolDataSource cpds; /** Log stream */ private PrintWriter logWriter; /** Environment that may be used to set up a jndi initial context. */ private Properties jndiEnvironment; /** Maximum Number of Connections cached in this Data Source */ private int defaultMaxConnections; /** * Maximum Number of Connections for a specified User in this Data * Source */ private Properties perUserMaxConnections; /** Maximum lifetime of a database connection */ private int maxExpiryTime; /** * time to wait when initiating a connection * for the database to respond */ private int connectionWaitTimeout; /** Interval (in seconds) that the monitor thread reports the pool state */ private int logInterval; /** Do connections from this pool are auto-committing? */ private boolean defaultAutoCommit; /** Are connections from this pool read-only? */ private boolean defaultReadOnly; /** * Default no-arg constructor for Serialization */ public TorqueClassicDataSource() { defaultAutoCommit = true; } // Properties /** * Get the number of database connections to cache per user. * This value is used for any username which is not specified * in perUserMaxConnections. The default is 1. * * @return value of maxConnections. */ public int getDefaultMaxConnections() { return defaultMaxConnections; } /** * Set the number of database connections to cache per user. * This value is used for any username which is not specified * in perUserMaxConnections. The default is 1. * * @param v Value to assign to maxConnections. */ public void setDefaultMaxConnections(int v) { this.defaultMaxConnections = v; } /** * Get the number of database connections to cache per user. The keys * are usernames and the value is the maximum connections. Any username * specified here will override the value of defaultMaxConnections. * * @return value of perUserMaxConnections. */ public Properties getPerUserMaxConnections() { return perUserMaxConnections; } /** * Set the number of database connections to cache per user. The keys * are usernames and the value is the maximum connections. Any username * specified here will override the value of defaultMaxConnections. * * @param v Value to assign to perUserMaxConnections. */ public void setPerUserMaxConnections(Properties v) { this.perUserMaxConnections = v; } /** * Get the amount of time (in seconds) that database connections * will be cached. The default is 3600 (1 hour). * * @return value of expiryTime. */ public int getMaxExpiryTime() { return maxExpiryTime; } /** * Set the amount of time (in seconds) that database connections * will be cached. The default is 3600 (1 hour). * * @param v Value to assign to expiryTime. */ public void setMaxExpiryTime(int v) { this.maxExpiryTime = v; } /** * Get the amount of time (in seconds) a connection request will * have to wait before a time out occurs and an error is thrown. * The default is 10 seconds. * * @return value of connectionWaitTimeout. */ public int getConnectionWaitTimeout() { return connectionWaitTimeout; } /** * Eet the amount of time (in seconds) a connection request will * have to wait before a time out occurs and an error is thrown. * The default is 10 seconds. * * @param v Value to assign to connectionWaitTimeout. */ public void setConnectionWaitTimeout(int v) { this.connectionWaitTimeout = v; } /** * Get the interval (in seconds) between which the ConnectionPool logs * the status of it's Connections. Default is 0 which indicates no * logging. * * @return value of logInterval. */ public int getLogInterval() { return logInterval; } /** * Set the interval (in seconds) between which the ConnectionPool logs * the status of it's Connections. Default is 0 which indicates no * logging. * * @param v Value to assign to logInterval. */ public void setLogInterval(int v) { this.logInterval = v; } /** * Get the value of defaultAutoCommit, which defines the state of * connections handed out from this pool. The value can be changed * on the Connection using Connection.setAutoCommit(boolean). * The default is true. * * @return value of defaultAutoCommit. */ public boolean isDefaultAutoCommit() { return defaultAutoCommit; } /** * Set the value of defaultAutoCommit, which defines the state of * connections handed out from this pool. The value can be changed * on the Connection using Connection.setAutoCommit(boolean). * The default is true. * * @param v Value to assign to defaultAutoCommit. */ public void setDefaultAutoCommit(boolean v) { this.defaultAutoCommit = v; } /** * Get the value of defaultReadOnly, which defines the state of * connections handed out from this pool. The value can be changed * on the Connection using Connection.setReadOnly(boolean). * The default is false. * * @return value of defaultReadOnly. */ public boolean isDefaultReadOnly() { return defaultReadOnly; } /** * Set the value of defaultReadOnly, which defines the state of * connections handed out from this pool. The value can be changed * on the Connection using Connection.setReadOnly(boolean). * The default is false. * * @param v Value to assign to defaultReadOnly. */ public void setDefaultReadOnly(boolean v) { this.defaultReadOnly = v; } /** * Get the name of the ConnectionPoolDataSource which backs this pool. * This name is used to look up the datasource from a jndi service * provider. * * @return value of dataSourceName. */ public String getDataSourceName() { return dataSourceName; } /** * Set the name of the ConnectionPoolDataSource which backs this pool. * This name is used to look up the datasource from a jndi service * provider. * * @param v Value to assign to dataSourceName. */ public void setDataSourceName(String v) { if (getConnectionPoolDataSource() != null) { throw new IllegalStateException("connectionPoolDataSource property" + " already has a value. Both dataSourceName and " + "connectionPoolDataSource properties cannot be set."); } this.dataSourceName = v; } /** * Get the description. This property is defined by jdbc as for use with * GUI (or other) tools that might deploy the datasource. It serves no
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -