提交 8638d106 authored 作者: Thomas Mueller's avatar Thomas Mueller

Database URLs can now be re-mapped to another URL using the system property…

Database URLs can now be re-mapped to another URL using the system property "h2.urlMap", which points to a properties file with database URL mappings.
上级 4852c0fc
......@@ -11,13 +11,11 @@ import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException;
import org.h2.message.TraceSystem;
import org.h2.upgrade.DbUpgrade;
import org.h2.util.SortedProperties;
/*## Java 1.7 begin ##
import java.util.logging.Logger;
......@@ -64,17 +62,6 @@ public class Driver implements java.sql.Driver {
if (!acceptsURL(url)) {
return null;
}
String urlMap = SysProperties.URL_MAP;
if (urlMap != null && urlMap.length() > 0) {
SortedProperties prop = SortedProperties.loadProperties(urlMap);
String url2 = prop.getProperty(url);
if (url2 == null) {
prop.put(url, "");
prop.store(urlMap);
} else {
url = url2;
}
}
if (url.equals(DEFAULT_URL)) {
return DEFAULT_CONNECTION.get();
}
......
......@@ -6,6 +6,7 @@
*/
package org.h2.engine;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
......@@ -21,6 +22,7 @@ import org.h2.store.fs.RecordingFileSystem;
import org.h2.util.IOUtils;
import org.h2.util.New;
import org.h2.util.RecoverTester;
import org.h2.util.SortedProperties;
import org.h2.util.StringUtils;
import org.h2.util.Utils;
......@@ -66,6 +68,7 @@ public class ConnectionInfo implements Cloneable {
* @param info the connection properties
*/
public ConnectionInfo(String u, Properties info) {
u = remapURL(u);
this.originalURL = u;
if (!u.startsWith(Constants.START_URL)) {
throw DbException.getInvalidValueException("url", u);
......@@ -599,4 +602,24 @@ public class ConnectionInfo implements Cloneable {
return DbSettings.getInstance(s);
}
private static String remapURL(String url) {
String urlMap = SysProperties.URL_MAP;
if (urlMap != null && urlMap.length() > 0) {
try {
SortedProperties prop;
prop = SortedProperties.loadProperties(urlMap);
String url2 = prop.getProperty(url);
if (url2 == null) {
prop.put(url, "");
prop.store(urlMap);
} else {
return url2;
}
} catch (IOException e) {
throw DbException.convert(e);
}
}
return url;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论