com.danidemi.jlubricant.embeddable.h2.UrlVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jlubricant-embeddable-h2 Show documentation
Show all versions of jlubricant-embeddable-h2 Show documentation
An Embeddable running the H2 database http://www.h2database.com.
package com.danidemi.jlubricant.embeddable.h2;
import java.util.HashMap;
import java.util.Map;
public class UrlVisitor implements Visitor {
private String name;
private String storage;
private String protocol;
private Map params;
public UrlVisitor() {
params = new HashMap();
}
@Override
public void visit(H2DatabaseDescription h2DatabaseDescription) {
this.name = h2DatabaseDescription.getDbName();
}
@Override
public void visit(H2Storage h2Storage) {
this.storage = h2Storage.getStorageSpecifier();
}
public void visit(H2Dbms h2Ddms) {
protocol = h2Ddms.getProtocol();
}
public String jdbcUrl() {
String url = "jdbc:h2:"
+ protocol
+ "://localhost/"
+ storage
+ ":" + name;
for (Map.Entry entry : params.entrySet()) {
url = url + ";" + entry.getKey() + "=" + entry.getValue();
}
return url;
}
public UrlVisitor withParam(String string, String string2) {
this.params.put(string, string2);
return this;
}
public UrlVisitor onlyIfDatabaseExists() {
withParam("IFEXISTS", "TRUE");
return this;
}
public UrlVisitor keepDbOpen() {
withParam("DB_CLOSE_DELAY", "-1");
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy