Skip to content

Commit

Permalink
JDBC URL中不再支持"mem:"前缀,用参数PERSISTENT取代
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Mar 22, 2017
1 parent 1d4ce22 commit 7129c14
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 deletions.
27 changes: 7 additions & 20 deletions lealone-common/src/main/java/org/lealone/db/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ private static boolean isKnownSetting(String s) {
private String nameNormalized;
private boolean remote;
private boolean ssl;
private boolean persistent;
private boolean embedded;
private String servers;

private SessionFactory sessionFactory;

private boolean isClient;
private Boolean persistent; // 首次调用isPersistent()时才初始化

public ConnectionInfo() {
}
Expand All @@ -118,15 +118,8 @@ public ConnectionInfo(String url, String dbName) { // 用于server端, 不需要
this.dbName = dbName;

checkURL();

persistent = true;
embedded = false;

url = url.substring(Constants.URL_PREFIX.length());
if (url.startsWith(Constants.URL_MEM)) {
persistent = false;
url = url.substring(Constants.URL_MEM.length());
}
// server端接收到的URL不可能是嵌入式的
if (url.startsWith(Constants.URL_EMBED)) {
throw DbException.throwInternalError("Server backend URL: " + this.url);
Expand Down Expand Up @@ -236,15 +229,9 @@ private void readAndRemoveSettingsFromURL() {
}

private void parseURL() {
boolean mem = false;
remote = true;
dbName = url.substring(Constants.URL_PREFIX.length());

if (dbName.startsWith(Constants.URL_MEM)) {
dbName = dbName.substring(Constants.URL_MEM.length());
mem = true;
}

if (dbName.startsWith(Constants.URL_TCP)) {
dbName = dbName.substring(Constants.URL_TCP.length());
} else if (dbName.startsWith(Constants.URL_SSL)) {
Expand All @@ -255,8 +242,6 @@ private void parseURL() {
embedded = true;
dbName = dbName.substring(Constants.URL_EMBED.length());
dbName = parseShortName();
if (!mem)
persistent = true;
} else {
throw getFormatException();
}
Expand All @@ -280,7 +265,7 @@ private void parseURL() {
* @param dir the new base directory
*/
public void setBaseDir(String dir) {
if (persistent) {
if (isPersistent()) {
String absDir = FileUtils.unwrap(FileUtils.toRealPath(dir));
boolean absolute = FileUtils.isAbsolute(dbName);
String n;
Expand Down Expand Up @@ -330,7 +315,10 @@ public boolean isRemote() {
* @return true if it is
*/
public boolean isPersistent() {
return persistent;
if (persistent == null) {
persistent = getProperty("PERSISTENT", true);
}
return persistent.booleanValue();
}

public boolean isEmbedded() {
Expand Down Expand Up @@ -440,7 +428,7 @@ public String removeProperty(String key, String defaultValue) {
}

public String getDatabaseName() {
if (persistent) {
if (isPersistent()) {
String name = dbName;
if (nameNormalized == null) {
if (!FileUtils.isAbsolute(name)) {
Expand Down Expand Up @@ -741,7 +729,6 @@ public ConnectionInfo copy(String newServer) {
ci.nameNormalized = nameNormalized;
ci.remote = remote;
ci.ssl = ssl;
ci.persistent = persistent;
ci.embedded = embedded;
ci.servers = newServer;
ci.sessionFactory = sessionFactory;
Expand Down
3 changes: 1 addition & 2 deletions lealone-common/src/main/java/org/lealone/db/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ public class Constants {
* The database URL prefix of this database.
*/
public static final String URL_PREFIX = "jdbc:lealone:";
public static final String URL_MEM = "mem:";
public static final String URL_TCP = "tcp:";
public static final String URL_SSL = "ssl:";
public static final String URL_EMBED = "embed:";
Expand Down Expand Up @@ -346,7 +345,7 @@ public class Constants {
* The database URL format in simplified Backus-Naur form.
*/
public static final String URL_FORMAT = URL_PREFIX
+ "[{mem:}] { {embed:}name | {tcp|ssl|rs}:[//] {server[:port][,server2[:port2]...]}/name }"
+ "{ {embed:}dbName | {tcp|ssl}:[//] {server[:port][,server2[:port2]...]}/dbName }"
+ " {[;key=value...] | [?key=value][&key2=value2...]}";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public synchronized Database createEmbeddedDatabase(String name, ConnectionInfo
for (Entry<Object, Object> e : ci.getProperties().entrySet()) {
parameters.put(e.getKey().toString(), e.getValue().toString());
}
parameters.put("PERSISTENT", ci.isPersistent() ? "true" : "false");
int id = INSTANCE.allocateObjectId();
db = new Database(id, name, parameters);
db.setRunMode(RunMode.EMBEDDED);
Expand Down
5 changes: 3 additions & 2 deletions lealone-test/src/test/java/org/lealone/test/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ public synchronized String getURL(String dbName) {
StringBuilder url = new StringBuilder(100);

url.append(Constants.URL_PREFIX);
if (inMemory)
url.append(Constants.URL_MEM);
if (inMemory) {
addConnectionParameter("PERSISTENT", "false");
}

if (embedded) {
url.append(Constants.URL_EMBED);
Expand Down

0 comments on commit 7129c14

Please sign in to comment.