📄 nonregisteringdriver.java
字号:
"Must specify at least one slave host to connect to for master/slave replication load-balancing functionality", SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE); } masterProps.setProperty(HOST_PROPERTY_KEY, masterHost.toString()); slavesProps.setProperty(HOST_PROPERTY_KEY, slaveHosts.toString()); } return new ReplicationConnection(masterProps, slavesProps); } /** * Returns the database property from <code>props</code> * * @param props * the Properties to look for the database property. * * @return the database name. */ public String database(Properties props) { return props.getProperty(DBNAME_PROPERTY_KEY); //$NON-NLS-1$ } /** * Gets the drivers major version number * * @return the drivers major version number */ public int getMajorVersion() { return getMajorVersionInternal(); } /** * Get the drivers minor version number * * @return the drivers minor version number */ public int getMinorVersion() { return getMinorVersionInternal(); } /** * The getPropertyInfo method is intended to allow a generic GUI tool to * discover what properties it should prompt a human for in order to get * enough information to connect to a database. * * <p> * Note that depending on the values the human has supplied so far, * additional values may become necessary, so it may be necessary to iterate * through several calls to getPropertyInfo * </p> * * @param url * the Url of the database to connect to * @param info * a proposed list of tag/value pairs that will be sent on * connect open. * * @return An array of DriverPropertyInfo objects describing possible * properties. This array may be an empty array if no properties are * required * * @exception SQLException * if a database-access error occurs * * @see java.sql.Driver#getPropertyInfo */ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { if (info == null) { info = new Properties(); } if ((url != null) && url.startsWith(URL_PREFIX)) { //$NON-NLS-1$ info = parseURL(url, info); } DriverPropertyInfo hostProp = new DriverPropertyInfo(HOST_PROPERTY_KEY, //$NON-NLS-1$ info.getProperty(HOST_PROPERTY_KEY)); //$NON-NLS-1$ hostProp.required = true; hostProp.description = Messages.getString("NonRegisteringDriver.3"); //$NON-NLS-1$ DriverPropertyInfo portProp = new DriverPropertyInfo(PORT_PROPERTY_KEY, //$NON-NLS-1$ info.getProperty(PORT_PROPERTY_KEY, "3306")); //$NON-NLS-1$ //$NON-NLS-2$ portProp.required = false; portProp.description = Messages.getString("NonRegisteringDriver.7"); //$NON-NLS-1$ DriverPropertyInfo dbProp = new DriverPropertyInfo(DBNAME_PROPERTY_KEY, //$NON-NLS-1$ info.getProperty(DBNAME_PROPERTY_KEY)); //$NON-NLS-1$ dbProp.required = false; dbProp.description = "Database name"; //$NON-NLS-1$ DriverPropertyInfo userProp = new DriverPropertyInfo(USER_PROPERTY_KEY, //$NON-NLS-1$ info.getProperty(USER_PROPERTY_KEY)); //$NON-NLS-1$ userProp.required = true; userProp.description = Messages.getString("NonRegisteringDriver.13"); //$NON-NLS-1$ DriverPropertyInfo passwordProp = new DriverPropertyInfo( PASSWORD_PROPERTY_KEY, //$NON-NLS-1$ info.getProperty(PASSWORD_PROPERTY_KEY)); //$NON-NLS-1$ passwordProp.required = true; passwordProp.description = Messages .getString("NonRegisteringDriver.16"); //$NON-NLS-1$ DriverPropertyInfo[] dpi = ConnectionPropertiesImpl .exposeAsDriverPropertyInfo(info, 5); dpi[0] = hostProp; dpi[1] = portProp; dpi[2] = dbProp; dpi[3] = userProp; dpi[4] = passwordProp; return dpi; } // // return the value of any property this driver knows about // /** * Returns the hostname property * * @param props * the java.util.Properties instance to retrieve the hostname * from. * * @return the hostname */ public String host(Properties props) { return props.getProperty(HOST_PROPERTY_KEY, "localhost"); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Report whether the driver is a genuine JDBC compliant driver. A driver * may only report "true" here if it passes the JDBC compliance tests, * otherwise it is required to return false. JDBC compliance requires full * support for the JDBC API and full support for SQL 92 Entry Level. * * <p> * MySQL is not SQL92 compliant * </p> * * @return is this driver JDBC compliant? */ public boolean jdbcCompliant() { return false; } public Properties parseURL(String url, Properties defaults) throws java.sql.SQLException { Properties urlProps = (defaults != null) ? new Properties(defaults) : new Properties(); if (url == null) { return null; } if (!StringUtils.startsWithIgnoreCase(url, URL_PREFIX) && !StringUtils.startsWithIgnoreCase(url, MXJ_URL_PREFIX) && !StringUtils.startsWithIgnoreCase(url, LOADBALANCE_URL_PREFIX) && !StringUtils.startsWithIgnoreCase(url, REPLICATION_URL_PREFIX)) { //$NON-NLS-1$ return null; } int beginningOfSlashes = url.indexOf("//"); if (StringUtils.startsWithIgnoreCase(url, MXJ_URL_PREFIX)) { urlProps .setProperty("socketFactory", "com.mysql.management.driverlaunched.ServerLauncherSocketFactory"); } /* * Parse parameters after the ? in the URL and remove them from the * original URL. */ int index = url.indexOf("?"); //$NON-NLS-1$ if (index != -1) { String paramString = url.substring(index + 1, url.length()); url = url.substring(0, index); StringTokenizer queryParams = new StringTokenizer(paramString, "&"); //$NON-NLS-1$ while (queryParams.hasMoreTokens()) { String parameterValuePair = queryParams.nextToken(); int indexOfEquals = StringUtils.indexOfIgnoreCase(0, parameterValuePair, "="); String parameter = null; String value = null; if (indexOfEquals != -1) { parameter = parameterValuePair.substring(0, indexOfEquals); if (indexOfEquals + 1 < parameterValuePair.length()) { value = parameterValuePair.substring(indexOfEquals + 1); } } if ((value != null && value.length() > 0) && (parameter != null && parameter.length() > 0)) { try { urlProps.put(parameter, URLDecoder.decode(value, "UTF-8")); } catch (UnsupportedEncodingException badEncoding) { // punt urlProps.put(parameter, URLDecoder.decode(value)); } catch (NoSuchMethodError nsme) { // punt again urlProps.put(parameter, URLDecoder.decode(value)); } } } } url = url.substring(beginningOfSlashes + 2); String hostStuff = null; int slashIndex = url.indexOf("/"); //$NON-NLS-1$ if (slashIndex != -1) { hostStuff = url.substring(0, slashIndex); if ((slashIndex + 1) < url.length()) { urlProps.put(DBNAME_PROPERTY_KEY, //$NON-NLS-1$ url.substring((slashIndex + 1), url.length())); } } else { hostStuff = url; } if ((hostStuff != null) && (hostStuff.length() > 0)) { urlProps.put(HOST_PROPERTY_KEY, hostStuff); //$NON-NLS-1$ } String propertiesTransformClassName = urlProps .getProperty(PROPERTIES_TRANSFORM_KEY); if (propertiesTransformClassName != null) { try { ConnectionPropertiesTransform propTransformer = (ConnectionPropertiesTransform) Class .forName(propertiesTransformClassName).newInstance(); urlProps = propTransformer.transformProperties(urlProps); } catch (InstantiationException e) { throw SQLError.createSQLException( "Unable to create properties transform instance '" + propertiesTransformClassName + "' due to underlying exception: " + e.toString(), SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE); } catch (IllegalAccessException e) { throw SQLError.createSQLException( "Unable to create properties transform instance '" + propertiesTransformClassName + "' due to underlying exception: " + e.toString(), SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE); } catch (ClassNotFoundException e) { throw SQLError.createSQLException( "Unable to create properties transform instance '" + propertiesTransformClassName + "' due to underlying exception: " + e.toString(), SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE); } } if (Util.isColdFusion() && urlProps.getProperty("autoConfigureForColdFusion", "true").equalsIgnoreCase("true")) { String configs = urlProps.getProperty(USE_CONFIG_PROPERTY_KEY); StringBuffer newConfigs = new StringBuffer(); if (configs != null) { newConfigs.append(configs); newConfigs.append(","); } newConfigs.append("coldFusion"); urlProps.setProperty(USE_CONFIG_PROPERTY_KEY, newConfigs.toString()); } // If we use a config, it actually should get overridden by anything in // the URL or passed-in properties String configNames = null; if (defaults != null) { configNames = defaults.getProperty(USE_CONFIG_PROPERTY_KEY); } if (configNames == null) { configNames = urlProps.getProperty(USE_CONFIG_PROPERTY_KEY); } if (configNames != null) { List splitNames = StringUtils.split(configNames, ",", true); Properties configProps = new Properties(); Iterator namesIter = splitNames.iterator(); while (namesIter.hasNext()) { String configName = (String) namesIter.next(); try { InputStream configAsStream = getClass() .getResourceAsStream( "configs/" + configName + ".properties"); if (configAsStream == null) { throw SQLError .createSQLException( "Can't find configuration template named '" + configName + "'", SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE); } configProps.load(configAsStream); } catch (IOException ioEx) { SQLException sqlEx = SQLError.createSQLException( "Unable to load configuration template '" + configName + "' due to underlying IOException: " + ioEx, SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE); sqlEx.initCause(ioEx); throw sqlEx; } } Iterator propsIter = urlProps.keySet().iterator(); while (propsIter.hasNext()) { String key = propsIter.next().toString(); String property = urlProps.getProperty(key); configProps.setProperty(key, property); } urlProps = configProps; } // Properties passed in should override ones in URL if (defaults != null) { Iterator propsIter = defaults.keySet().iterator(); while (propsIter.hasNext()) { String key = propsIter.next().toString(); String property = defaults.getProperty(key); urlProps.setProperty(key, property); } } return urlProps; } /** * Returns the port number property * * @param props * the properties to get the port number from * * @return the port number */ public int port(Properties props) { return Integer.parseInt(props.getProperty(PORT_PROPERTY_KEY, "3306")); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Returns the given property from <code>props</code> * * @param name * the property name * @param props * the property instance to look in * * @return the property value, or null if not found. */ public String property(String name, Properties props) { return props.getProperty(name); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -