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

📄 connectionpropertiesimpl.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Copyright  2002-2007 MySQL AB, 2008 Sun Microsystems 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 java.io.Serializable;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;import com.mysql.jdbc.log.Log;import com.mysql.jdbc.log.StandardLogger;/** * 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 ConnectionPropertiesImpl implements Serializable, ConnectionProperties {		private static final long serialVersionUID = 4257801713007640580L;	class BooleanConnectionProperty extends ConnectionProperty implements Serializable {			private static final long serialVersionUID = 2540132501709159404L;		/**		 * 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, Boolean.valueOf(defaultValueToSet), null, 0,					0, descriptionToSet, sinceVersionToSet, category,					orderInCategory);		}		/**		 * @see com.mysql.jdbc.ConnectionPropertiesImpl.ConnectionProperty#getAllowableValues()		 */		String[] getAllowableValues() {			return new String[] { "true", "false", "yes", "no" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$		}		boolean getValueAsBoolean() {			return ((Boolean) this.valueAsObject).booleanValue();		}		/**		 * @see com.mysql.jdbc.ConnectionPropertiesImpl.ConnectionProperty#hasValueConstraints()		 */		boolean hasValueConstraints() {			return true;		}		/**		 * @see com.mysql.jdbc.ConnectionPropertiesImpl.ConnectionProperty#initializeFrom(java.util.Properties)		 */		void initializeFrom(String extractedValue) throws SQLException {			if (extractedValue != null) {				validateStringValues(extractedValue);				this.valueAsObject = Boolean.valueOf(extractedValue						.equalsIgnoreCase("TRUE") //$NON-NLS-1$						|| extractedValue.equalsIgnoreCase("YES")); //$NON-NLS-1$			} else {				this.valueAsObject = this.defaultValue;			}		}		/**		 * @see com.mysql.jdbc.ConnectionPropertiesImpl.ConnectionProperty#isRangeBased()		 */		boolean isRangeBased() {			return false;		}		void setValue(boolean valueFlag) {			this.valueAsObject = Boolean.valueOf(valueFlag);		}	}	abstract class ConnectionProperty implements Serializable {		String[] allowableValues;		String categoryName;		Object defaultValue;		int lowerBound;		int order;		String propertyName;		String sinceVersion;		int upperBound;		Object valueAsObject;		boolean required;				String description;				public ConnectionProperty() {}				ConnectionProperty(String propertyNameToSet, Object defaultValueToSet,				String[] allowableValuesToSet, int lowerBoundToSet,				int upperBoundToSet, String descriptionToSet,				String sinceVersionToSet, String category, int orderInCategory) {						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()));			}		}		DriverPropertyInfo getAsDriverPropertyInfo() {			DriverPropertyInfo dpi = new DriverPropertyInfo(this.propertyName, null);			dpi.choices = getAllowableValues();			dpi.value = (this.valueAsObject != null) ? this.valueAsObject.toString() : null;			dpi.required = this.required;			dpi.description = this.description;						return dpi;		}				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 '"); //$NON-NLS-1$			errorMessageBuf.append(getPropertyName());			errorMessageBuf.append("' only accepts values of the form: "); //$NON-NLS-1$			if (validateAgainst.length != 0) {				errorMessageBuf.append("'"); //$NON-NLS-1$				errorMessageBuf.append(validateAgainst[0]);				errorMessageBuf.append("'"); //$NON-NLS-1$				for (int i = 1; i < (validateAgainst.length - 1); i++) {					errorMessageBuf.append(", "); //$NON-NLS-1$					errorMessageBuf.append("'"); //$NON-NLS-1$					errorMessageBuf.append(validateAgainst[i]);					errorMessageBuf.append("'"); //$NON-NLS-1$				}				errorMessageBuf.append(" or '"); //$NON-NLS-1$				errorMessageBuf						.append(validateAgainst[validateAgainst.length - 1]);				errorMessageBuf.append("'"); //$NON-NLS-1$			}			errorMessageBuf.append(". The value '"); //$NON-NLS-1$			errorMessageBuf.append(valueToValidate);			errorMessageBuf.append("' is not in this set."); //$NON-NLS-1$			throw SQLError.createSQLException(errorMessageBuf.toString(),					SQLError.SQL_STATE_ILLEGAL_ARGUMENT);		}	}	class IntegerConnectionProperty extends ConnectionProperty implements Serializable {		private static final long serialVersionUID = -3004305481796850832L;		public IntegerConnectionProperty(String propertyNameToSet,				Object defaultValueToSet, String[] allowableValuesToSet,				int lowerBoundToSet, int upperBoundToSet,				String descriptionToSet, String sinceVersionToSet,				String category, int orderInCategory) {

⌨️ 快捷键说明

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