-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jdbc URL string support #34
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,7 @@ public void closePool(){ | |
@Override | ||
public Connection connect(String url, Properties connectionConfig) throws SQLException { | ||
if(this.acceptsURL(url)){ | ||
url = parseAddress(url); | ||
parseUrlProperties(url, connectionConfig); | ||
this.connectionConfig.put("url", url); | ||
String graphSpace = this.connectionConfig.getProperty("graphSpace"); | ||
|
@@ -140,6 +141,50 @@ public Connection connect(String url, Properties connectionConfig) throws SQLExc | |
} | ||
} | ||
|
||
/** | ||
* Parse an extended JDBC url supporting the syntax: | ||
* | ||
* jdbc:nebula://host:port,host:port,.../graphSpace | ||
* | ||
* @param url extended url | ||
* @return the original url 'jdbc:nebula://graphSpace' | ||
* @throws SQLException if the servers are not specified as 'host:port' or 'port' is not an integer | ||
*/ | ||
protected String parseAddress(String url) throws SQLException { | ||
// jdbc:nebula://ip:port,ip:port,.../graphspace | ||
|
||
int b = url.indexOf("//"); | ||
int e = url.indexOf("/", b+2); | ||
if (e == -1) | ||
return url; | ||
|
||
String addresses = url.substring(b+2, e); | ||
url = url.substring(0, b+2) + url.substring(e+1); | ||
|
||
String[] addressesList = addresses.split(","); | ||
List<HostAddress> customizedAddressList = new ArrayList<>(); | ||
|
||
for (String address : addressesList) { | ||
String[] addressInfo = address.split(":"); | ||
if(addressInfo.length != 2){ | ||
throw new SQLException(String.format("url [%s] is invalid, please make sure your url match thr format: \"ip:port\".", url)); | ||
} | ||
String ip = addressInfo[0]; | ||
int port = Integer.parseInt(addressInfo[1]); | ||
customizedAddressList.add(new HostAddress(ip, port)); | ||
} | ||
|
||
// close the current pool that uses '127.0.0.1' (WHY????) | ||
this.nebulaPool.close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it should be refactored. The default client address There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. totally agreed, would be better to remove this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Nicole00 I'm sorry but i saw line 180 the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it will be replaced by customizedAddressList only when user call We can remove the customizedAddressList and put the user address in url, which will be more common. |
||
// set in the pool properties the new 'addressList' | ||
this.poolProperties.put("addressList", customizedAddressList); | ||
// create & initialize a new pool | ||
this.nebulaPool = new NebulaPool(); | ||
this.initNebulaPool(); | ||
|
||
return url; | ||
} | ||
|
||
/** | ||
* get the Properties that used in NebulaDriver's constructor to specify addressList and parameters of {@link NebulaPool}. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"thr" seems to be a typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, thanks! Should be /thr/the/😊