All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.danidemi.jlubricant.embeddable.h2.UrlVisitor Maven / Gradle / Ivy

There is a newer version: 0.0.15
Show newest version
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