Abstract out concepts of DataSourceType and DatabaseConfigInitializer.

Encapsulate data source specific logic into subclasses of DataSourceType
and DatabaseConfigInitializer.  DataSourceType and
DatabaseConfigInitializer are separated because we need them at
different stages (init vs runtime) and they also need to exist in
different projects with different dependencies.

This is a first step toward providing support for different database
platforms as plugins.

Change-Id: I01ea666ef7f682d6137f0e64005d979dd706f67b
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
This commit is contained in:
Sasa Zivkov
2012-06-27 16:44:49 +02:00
committed by Edwin Kempin
parent 05acbe4c0a
commit b53bffe1b9
27 changed files with 798 additions and 222 deletions

View File

@@ -18,6 +18,7 @@ import static org.eclipse.jgit.util.StringUtils.equalsIgnoreCase;
import java.io.Console;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
/** Console based interaction with the invoking user. */
public abstract class ConsoleUI {
@@ -73,6 +74,10 @@ public abstract class ConsoleUI {
/** Prompt the user for a string, suggesting a default, and returning choice. */
public abstract String readString(String def, String fmt, Object... args);
/** Prompt the user to make a choice from an allowed list of values. */
public abstract String readString(String def, Set<String> allowedValues,
String fmt, Object... args);
/** Prompt the user for an integer value, suggesting a default. */
public int readInt(int def, String fmt, Object... args) {
for (;;) {
@@ -161,6 +166,24 @@ public abstract class ConsoleUI {
return r;
}
@Override
public String readString(String def, Set<String> allowedValues, String fmt,
Object... args) {
for (;;) {
String r = readString(def, fmt, args);
if (allowedValues.contains(r.toLowerCase())) {
return r.toLowerCase();
}
if (!"?".equals(r)) {
console.printf("error: '%s' is not a valid choice\n", r);
}
console.printf(" Supported options are:\n");
for (final String v : allowedValues) {
console.printf(" %s\n", v.toString().toLowerCase());
}
}
}
@Override
public String password(String fmt, Object... args) {
final String prompt = String.format(fmt, args);
@@ -241,6 +264,12 @@ public abstract class ConsoleUI {
return def;
}
@Override
public String readString(String def, Set<String> allowedValues, String fmt,
Object... args) {
return def;
}
@Override
public void waitForUser() {
}