package org.openlca.app.db;

import java.util.Objects;

import org.openlca.core.database.derby.DerbyDatabase;

/**
 * Configuration of a local derby database. Derby databases are stored directly
 * in the workspace folder: <workspace>/databases/<database_name>.
 */
public class DerbyConfiguration implements IDatabaseConfiguration {

	private String name;

	@Override
	public DerbyDatabase createInstance() throws Exception {
		DerbyDatabase db = new DerbyDatabase(DatabaseDir.getRootFolder(name));
		return db;
	}

	@Override
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public boolean isLocal() {
		return true;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (obj == this)
			return true;
		if (!getClass().equals(obj.getClass()))
			return false;
		DerbyConfiguration other = (DerbyConfiguration) obj;
		return Objects.equals(this.name, other.name);
	}

	@Override
	public int hashCode() {
		return Objects.hash(name);
	}

}

@@ -22,16 +22,37 @@
 pp.db;%0A%0A
+import java.io.File;%0A
 import j
@@ -377,96 +377,347 @@
 ;%0A%0A%09
-@Override%0A%09public DerbyDatabase createInstance() throws Exception %7B%0A%09%09DerbyDatabase db =
+/**%0A%09 * experimental: An optional full path to the directory that contains the%0A%09 * database. This is currently not an option provided by the user interface.%0A%09 */%0A%09private String folder;%0A%0A%09@Override%0A%09public DerbyDatabase createInstance() throws Exception %7B%0A%09%09if (folder != null) %7B%0A%09%09%09return new DerbyDatabase(new File(folder));%0A%09%09%7D%0A%09%09return
  new
@@ -769,21 +769,8 @@
 ));%0A
-%09%09return db;%0A
 %09%7D%0A%0A

support an optional `folder` path