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

📄 nonregisteringdriver.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return props.getProperty(DBNAME_PROPERTY_KEY); //$NON-NLS-1$    }    /**     * 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;    }    /**     *     *     * @param url ...     * @param defaults ...     *     * @return ...     *     * @throws java.sql.SQLException ...     */    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, "jdbc:mysql://")) { //$NON-NLS-1$            return null;        }        /*         * 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()) {                StringTokenizer vp = new StringTokenizer(queryParams.nextToken(),                        "="); //$NON-NLS-1$                String param = ""; //$NON-NLS-1$                if (vp.hasMoreTokens()) {                    param = vp.nextToken();                }                String value = ""; //$NON-NLS-1$                if (vp.hasMoreTokens()) {                    value = vp.nextToken();                }                if ((value.length() > 0) && (param.length() > 0)) {                    urlProps.put(param, value);                }            }        }        url = url.substring(13);        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 {            return null;        }        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 new SQLException(                    "Unable to create properties transform instance '" +                    propertiesTransformClassName +                    "' due to underlying exception: " + e.toString(),                    SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);            } catch (IllegalAccessException e) {                throw new SQLException(                    "Unable to create properties transform instance '" +                    propertiesTransformClassName +                    "' due to underlying exception: " + e.toString(),                    SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);            } catch (ClassNotFoundException e) {                throw new SQLException(                    "Unable to create properties transform instance '" +                    propertiesTransformClassName +                    "' due to underlying exception: " + e.toString(),                    SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);            }        }        // 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 new SQLException("Can't find configuration template named '" + configName + "'", SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);        			}        			configProps.load(configAsStream);        		} catch (IOException ioEx) {        			throw new SQLException("Unable to load configuration template '" + configName + "' due to underlying IOException: " + ioEx, SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);        		}        	}        	        	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$    }    //    // return the value of any property this driver knows about    //    /**     * 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);    }    /**     * Parses hostPortPair in the form of [host][:port] into an array, with the     * element of index HOST_NAME_INDEX being the host (or null if not     * specified), and the element of index PORT_NUMBER_INDEX being the port     * (or null if not specified).     *     * @param hostPortPair host and port in form of of [host][:port]     *     * @return array containing host and port as Strings     *     * @throws SQLException if a parse error occurs     */    protected static String[] parseHostPortPair(String hostPortPair)        throws SQLException {        int portIndex = hostPortPair.indexOf(":"); //$NON-NLS-1$        String[] splitValues = new String[2];        String hostname = null;        if (portIndex != -1) {            if ((portIndex + 1) < hostPortPair.length()) {                String portAsString = hostPortPair.substring(portIndex + 1);                hostname = hostPortPair.substring(0, portIndex);                splitValues[HOST_NAME_INDEX] = hostname;                splitValues[PORT_NUMBER_INDEX] = portAsString;            } else {                throw new SQLException(Messages.getString(                        "NonRegisteringDriver.37"), //$NON-NLS-1$                    SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);            }        } else {            splitValues[HOST_NAME_INDEX] = hostPortPair;            splitValues[PORT_NUMBER_INDEX] = null;        }        return splitValues;    }    /**     * Gets the drivers major version number     *     * @return the drivers major version number     */    static int getMajorVersionInternal() {        return safeIntParse("3"); //$NON-NLS-1$    }    /**     * Get the drivers minor version number     *     * @return the drivers minor version number     */    static int getMinorVersionInternal() {        return safeIntParse("1"); //$NON-NLS-1$    }    private static int safeIntParse(String intAsString) {        try {            return Integer.parseInt(intAsString);        } catch (NumberFormatException nfe) {            return 0;        }    }}

⌨️ 快捷键说明

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