public void setUrl()

in ch-commons-sql/src/main/java/com/cloudhopper/commons/sql/DataSourceConfiguration.java [460:501]


    public void setUrl(String url) throws SQLConfigurationException {
        // make sure the url starts with "jdbc:"
        if (!url.startsWith("jdbc:")) {
            throw new SQLConfigurationException("Invalid JDBC URL. Does not start with 'jdbc:'");
        }

        // attempt to parse the protocol from the JDBC url -- this is the portion
        // after the initial "jdbc:protocol:" -- try to find the next ':' char after the first 5
        int protocolPos = url.indexOf(":", 5);
        if (protocolPos <= 0) {
            throw new SQLConfigurationException("Invalid JDBC URL. Does not start with a protocol that ends in ':' such as 'jdbc:protocol:'");
        }
        String protocol = url.substring(5, protocolPos);

        // attempt to parse the next protocol token
        int subProtocolPos = url.indexOf(":", protocolPos+1);
        String subProtocol = "";
        if (subProtocolPos > 0) {
            subProtocol = url.substring(protocolPos+1, subProtocolPos);
        }

	logger.debug("found protocol {} sub-protocol {} from url {}", protocol, subProtocol, url);

        // attempt to map JDBC url to set the vendor -- this will set the vendor
        // and also the driver if those properties have not yet been set
        if (protocol.equals("mysql")) {
            setVendorIfNotSet(DatabaseVendor.MYSQL);
        } else if (protocol.equals("postgresql")) {
            setVendorIfNotSet(DatabaseVendor.POSTGRESQL);
        } else if (protocol.equals("jtds") && subProtocol.equals("sqlserver")) {
            setVendorIfNotSet(DatabaseVendor.MSSQL);
        } else if (protocol.equals("vertica")) {
	    setVendorIfNotSet(DatabaseVendor.VERTICA);
        } else if (protocol.equals("hsqldb")) {
	    setVendorIfNotSet(DatabaseVendor.HSQLDB);
        } else {
            throw new SQLConfigurationException("Unsupported protocol '" + protocol + (!subProtocol.equals("") ? ":" + subProtocol : "") + "' in JDBC URL. Add mapping to DataSourceFactory?");
        }

        // everything went ok, save the url
        this.url = url;
    }