@Override public boolean acceptsURL(String url) throws SQLException { if (url.startsWith(PhoenixRuntime.JDBC_PROTOCOL)) { // A connection string of "jdbc:phoenix" is supported, since // all the connection information can potentially be gotten // out of the HBase config file if (url.length() == PhoenixRuntime.JDBC_PROTOCOL.length()) { return true; } // Same as above, except for "jdbc:phoenix;prop=<value>..." if (PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR == url.charAt(PhoenixRuntime.JDBC_PROTOCOL.length())) { return true; } if (PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR == url.charAt(PhoenixRuntime.JDBC_PROTOCOL.length())) { int protoLength = PhoenixRuntime.JDBC_PROTOCOL.length() + 1; // A connection string of "jdbc:phoenix:" matches this driver, // but will end up as a MALFORMED_CONNECTION_URL exception later. if (url.length() == protoLength) { return true; } // A connection string of the form "jdbc:phoenix://" means that // the driver is remote which isn't supported, so return false. if (!url.startsWith(DNC_JDBC_PROTOCOL_SUFFIX, protoLength)) { return true; } } } return false; }
protected static ConnectionInfo create(String url) throws SQLException { StringTokenizer tokenizer = new StringTokenizer( url == null ? "" : url.substring(PhoenixRuntime.JDBC_PROTOCOL.length()), DELIMITERS, true); int i = 0; boolean isMalformedUrl = false; String[] tokens = new String[3]; String token = null; while (tokenizer.hasMoreTokens() && !(token = tokenizer.nextToken()).equals(TERMINATOR) && tokenizer.hasMoreTokens() && i < tokens.length) { token = tokenizer.nextToken(); // This would mean we have an empty string for a token which is illegal if (DELIMITERS.contains(token)) { isMalformedUrl = true; break; } tokens[i++] = token; } Integer port = null; if (!isMalformedUrl) { if (tokenizer.hasMoreTokens() && !TERMINATOR.equals(token)) { isMalformedUrl = true; } else if (i > 1) { try { port = Integer.parseInt(tokens[1]); isMalformedUrl = port < 0; } catch (NumberFormatException e) { // If we have 3 tokens, then the second one must be a port. // If we only have 2 tokens, the second one might be the root node: // Assume that is the case if we get a NumberFormatException if (!(isMalformedUrl = i == 3)) { tokens[2] = tokens[1]; } } } } if (isMalformedUrl) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.MALFORMED_CONNECTION_URL) .setMessage(url) .build() .buildException(); } return new ConnectionInfo(tokens[0], port, tokens[2]); }