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

📄 connectionproperties.java

📁 mysql的jdbc驱动
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Copyright (C) 2002-2004 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as  published by the Free Software Foundation. There are special exceptions to the terms and conditions of the GPL  as it is applied to this software. View the full text of the  exception in file EXCEPTIONS-CONNECTOR-J in the directory of this  software distribution. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package com.mysql.jdbc;import com.mysql.jdbc.log.Jdk14Logger;import com.mysql.jdbc.log.Log;import com.mysql.jdbc.log.StandardLogger;import java.io.UnsupportedEncodingException;import java.sql.DriverPropertyInfo;import java.sql.SQLException;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Properties;import java.util.TreeMap;import javax.naming.RefAddr;import javax.naming.Reference;import javax.naming.StringRefAddr;/** * Represents configurable properties for Connections and DataSources. Can also * expose properties as JDBC DriverPropertyInfo if required as well. *  * @author Mark Matthews * @version $Id: ConnectionProperties.java,v 1.1.2.2 2005/05/17 14:58:56 *          mmatthews Exp $ */public class ConnectionProperties {	class BooleanConnectionProperty extends ConnectionProperty {		/**		 * DOCUMENT ME!		 * 		 * @param propertyNameToSet		 * @param defaultValueToSet		 * @param descriptionToSet		 *            DOCUMENT ME!		 * @param sinceVersionToSet		 *            DOCUMENT ME!		 */		BooleanConnectionProperty(String propertyNameToSet,				boolean defaultValueToSet, String descriptionToSet,				String sinceVersionToSet, String category, int orderInCategory) {			super(propertyNameToSet, new Boolean(defaultValueToSet), null, 0,					0, descriptionToSet, sinceVersionToSet, category,					orderInCategory);		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#getAllowableValues()		 */		String[] getAllowableValues() {			return new String[] { "true", "false", "yes", "no" };		}		boolean getValueAsBoolean() {			return ((Boolean) this.valueAsObject).booleanValue();		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#hasValueConstraints()		 */		boolean hasValueConstraints() {			return true;		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#initializeFrom(java.util.Properties)		 */		void initializeFrom(String extractedValue) throws SQLException {			if (extractedValue != null) {				validateStringValues(extractedValue);				this.valueAsObject = new Boolean(extractedValue						.equalsIgnoreCase("TRUE")						|| extractedValue.equalsIgnoreCase("YES"));			} else {				this.valueAsObject = this.defaultValue;			}		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#isRangeBased()		 */		boolean isRangeBased() {			return false;		}		void setValue(boolean valueFlag) {			this.valueAsObject = new Boolean(valueFlag);		}	}	abstract class ConnectionProperty extends DriverPropertyInfo {		String[] allowableValues;		String categoryName;		Object defaultValue;		int lowerBound;		int order;		String propertyName;		String sinceVersion;		int upperBound;		Object valueAsObject;		ConnectionProperty(String propertyNameToSet, Object defaultValueToSet,				String[] allowableValuesToSet, int lowerBoundToSet,				int upperBoundToSet, String descriptionToSet,				String sinceVersionToSet, String category, int orderInCategory) {			super(propertyNameToSet, null);			this.description = descriptionToSet;			this.propertyName = propertyNameToSet;			this.defaultValue = defaultValueToSet;			this.valueAsObject = defaultValueToSet;			this.allowableValues = allowableValuesToSet;			this.lowerBound = lowerBoundToSet;			this.upperBound = upperBoundToSet;			this.required = false;			this.sinceVersion = sinceVersionToSet;			this.categoryName = category;			this.order = orderInCategory;		}		String[] getAllowableValues() {			return this.allowableValues;		}		/**		 * @return Returns the categoryName.		 */		String getCategoryName() {			return this.categoryName;		}		Object getDefaultValue() {			return this.defaultValue;		}		int getLowerBound() {			return this.lowerBound;		}		/**		 * @return Returns the order.		 */		int getOrder() {			return this.order;		}		String getPropertyName() {			return this.propertyName;		}		int getUpperBound() {			return this.upperBound;		}		Object getValueAsObject() {			return this.valueAsObject;		}		abstract boolean hasValueConstraints();		void initializeFrom(Properties extractFrom) throws SQLException {			String extractedValue = extractFrom.getProperty(getPropertyName());			extractFrom.remove(getPropertyName());			initializeFrom(extractedValue);		}		void initializeFrom(Reference ref) throws SQLException {			RefAddr refAddr = ref.get(getPropertyName());			if (refAddr != null) {				String refContentAsString = (String) refAddr.getContent();				initializeFrom(refContentAsString);			}		}		abstract void initializeFrom(String extractedValue) throws SQLException;		abstract boolean isRangeBased();		/**		 * @param categoryName		 *            The categoryName to set.		 */		void setCategoryName(String categoryName) {			this.categoryName = categoryName;		}		/**		 * @param order		 *            The order to set.		 */		void setOrder(int order) {			this.order = order;		}		void setValueAsObject(Object obj) {			this.valueAsObject = obj;		}		void storeTo(Reference ref) {			if (getValueAsObject() != null) {				ref.add(new StringRefAddr(getPropertyName(), getValueAsObject()						.toString()));			}		}		/**		 * Synchronizes the state of a ConnectionProperty so that it can be		 * exposed as a DriverPropertyInfo instance.		 */		void syncDriverPropertyInfo() {			this.choices = getAllowableValues();			this.value = (this.valueAsObject != null) ? this.valueAsObject					.toString() : null;		}		void validateStringValues(String valueToValidate) throws SQLException {			String[] validateAgainst = getAllowableValues();			if (valueToValidate == null) {				return;			}			if ((validateAgainst == null) || (validateAgainst.length == 0)) {				return;			}			for (int i = 0; i < validateAgainst.length; i++) {				if ((validateAgainst[i] != null)						&& validateAgainst[i].equalsIgnoreCase(valueToValidate)) {					return;				}			}			StringBuffer errorMessageBuf = new StringBuffer();			errorMessageBuf.append("The connection property '");			errorMessageBuf.append(getPropertyName());			errorMessageBuf.append("' only accepts values of the form: ");			if (validateAgainst.length != 0) {				errorMessageBuf.append("'");				errorMessageBuf.append(validateAgainst[0]);				errorMessageBuf.append("'");				for (int i = 1; i < (validateAgainst.length - 1); i++) {					errorMessageBuf.append(", ");					errorMessageBuf.append("'");					errorMessageBuf.append(validateAgainst[i]);					errorMessageBuf.append("'");				}				errorMessageBuf.append(" or '");				errorMessageBuf						.append(validateAgainst[validateAgainst.length - 1]);				errorMessageBuf.append("'");			}			errorMessageBuf.append(". The value '");			errorMessageBuf.append(valueToValidate);			errorMessageBuf.append("' is not in this set.");			throw new SQLException(errorMessageBuf.toString(),					SQLError.SQL_STATE_ILLEGAL_ARGUMENT);		}	}	class IntegerConnectionProperty extends ConnectionProperty {		int multiplier = 1;		IntegerConnectionProperty(String propertyNameToSet,				int defaultValueToSet, int lowerBoundToSet,				int upperBoundToSet, String descriptionToSet,				String sinceVersionToSet, String category, int orderInCategory) {			super(propertyNameToSet, new Integer(defaultValueToSet), null,					lowerBoundToSet, upperBoundToSet, descriptionToSet,					sinceVersionToSet, category, orderInCategory);		}		/**		 * DOCUMENT ME!		 * 		 * @param propertyNameToSet		 * @param defaultValueToSet		 * @param descriptionToSet		 * @param sinceVersionToSet		 *            DOCUMENT ME!		 */		IntegerConnectionProperty(String propertyNameToSet,				int defaultValueToSet, String descriptionToSet,				String sinceVersionToSet, String category, int orderInCategory) {			this(propertyNameToSet, defaultValueToSet, 0, 0, descriptionToSet,					sinceVersionToSet, category, orderInCategory);		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#getAllowableValues()		 */		String[] getAllowableValues() {			return null;		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#getLowerBound()		 */		int getLowerBound() {			return this.lowerBound;		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#getUpperBound()		 */		int getUpperBound() {			return this.upperBound;		}		int getValueAsInt() {			return ((Integer) this.valueAsObject).intValue();		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#hasValueConstraints()		 */		boolean hasValueConstraints() {			return false;		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#initializeFrom(java.lang.String)		 */		void initializeFrom(String extractedValue) throws SQLException {			if (extractedValue != null) {				try {					// Parse decimals, too					int intValue = Double.valueOf(extractedValue).intValue();					/*					 * if (isRangeBased()) { if ((intValue < getLowerBound()) ||					 * (intValue > getUpperBound())) { throw new					 * SQLException("The connection property '" +					 * getPropertyName() + "' only accepts integer values in the					 * range of " + getLowerBound() + " - " + getUpperBound() + ",					 * the value '" + extractedValue + "' exceeds this range.",					 * SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } }					 */					this.valueAsObject = new Integer(intValue * multiplier);				} catch (NumberFormatException nfe) {					throw new SQLException("The connection property '"							+ getPropertyName()							+ "' only accepts integer values. The value '"							+ extractedValue							+ "' can not be converted to an integer.",							SQLError.SQL_STATE_ILLEGAL_ARGUMENT);				}			} else {				this.valueAsObject = this.defaultValue;			}		}		/**		 * @see com.mysql.jdbc.ConnectionProperties.ConnectionProperty#isRangeBased()		 */		boolean isRangeBased() {			return getUpperBound() != getLowerBound();

⌨️ 快捷键说明

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