|
@@ -35,39 +35,40 @@ import picocli.CommandLine.Option;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Database install command.
|
|
* Database install command.
|
|
|
|
+ *
|
|
* @author Zoey76
|
|
* @author Zoey76
|
|
* @version 1.0.2
|
|
* @version 1.0.2
|
|
*/
|
|
*/
|
|
@Command(name = "install")
|
|
@Command(name = "install")
|
|
public class DatabaseInstallCommand extends AbstractCommand {
|
|
public class DatabaseInstallCommand extends AbstractCommand {
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-sql", required = true, description = "SQL Files location")
|
|
@Option(names = "-sql", required = true, description = "SQL Files location")
|
|
private String path;
|
|
private String path;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-url", description = "Database URL")
|
|
@Option(names = "-url", description = "Database URL")
|
|
private String url;
|
|
private String url;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-db", description = "Database Name")
|
|
@Option(names = "-db", description = "Database Name")
|
|
private String name;
|
|
private String name;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-u", description = "Database User")
|
|
@Option(names = "-u", description = "Database User")
|
|
private String user;
|
|
private String user;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-p", description = "Database Password")
|
|
@Option(names = "-p", description = "Database Password")
|
|
private String password;
|
|
private String password;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-m", required = true, description = "Database installation mode")
|
|
@Option(names = "-m", required = true, description = "Database installation mode")
|
|
private DatabaseInstallType mode;
|
|
private DatabaseInstallType mode;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-t", required = true, description = "Server Type")
|
|
@Option(names = "-t", required = true, description = "Server Type")
|
|
private ServerType serverType;
|
|
private ServerType serverType;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-c", description = "Custom Tables")
|
|
@Option(names = "-c", description = "Custom Tables")
|
|
private boolean customs;
|
|
private boolean customs;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-mods", description = "Mods Tables")
|
|
@Option(names = "-mods", description = "Mods Tables")
|
|
private boolean mods;
|
|
private boolean mods;
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
// Validate files exists
|
|
// Validate files exists
|
|
@@ -76,55 +77,57 @@ public class DatabaseInstallCommand extends AbstractCommand {
|
|
System.err.println("The path does not exist!");
|
|
System.err.println("The path does not exist!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
final AbstractDatabaseDAO databaseDAO = databaseDAO();
|
|
final AbstractDatabaseDAO databaseDAO = databaseDAO();
|
|
-
|
|
|
|
- databaseDAO.createDatabase();
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if (mode == DatabaseInstallType.FULL) {
|
|
|
|
+ databaseDAO.createDatabase();
|
|
|
|
+ }
|
|
|
|
+
|
|
databaseDAO.createDump();
|
|
databaseDAO.createDump();
|
|
-
|
|
|
|
|
|
+
|
|
databaseDAO.updates(mode, sqlPath);
|
|
databaseDAO.updates(mode, sqlPath);
|
|
-
|
|
|
|
|
|
+
|
|
databaseDAO.basic(sqlPath);
|
|
databaseDAO.basic(sqlPath);
|
|
-
|
|
|
|
|
|
+
|
|
if (customs) {
|
|
if (customs) {
|
|
databaseDAO.custom(sqlPath);
|
|
databaseDAO.custom(sqlPath);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (mods) {
|
|
if (mods) {
|
|
databaseDAO.mods(sqlPath);
|
|
databaseDAO.mods(sqlPath);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
System.out.println("Database installation complete.");
|
|
System.out.println("Database installation complete.");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private AbstractDatabaseDAO databaseDAO() {
|
|
private AbstractDatabaseDAO databaseDAO() {
|
|
switch (serverType) {
|
|
switch (serverType) {
|
|
- case GAME: {
|
|
|
|
- overrideConfigs(Configuration.gameServer());
|
|
|
|
- return new GameServerDatabaseDAO();
|
|
|
|
- }
|
|
|
|
- default:
|
|
|
|
- case LOGIN: {
|
|
|
|
- overrideConfigs(Configuration.loginServer());
|
|
|
|
- return new LoginServerDatabaseDAO();
|
|
|
|
- }
|
|
|
|
|
|
+ case GAME: {
|
|
|
|
+ overrideConfigs(Configuration.gameServer());
|
|
|
|
+ return new GameServerDatabaseDAO();
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ case LOGIN: {
|
|
|
|
+ overrideConfigs(Configuration.loginServer());
|
|
|
|
+ return new LoginServerDatabaseDAO();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void overrideConfigs(Mutable databaseConfiguration) {
|
|
private void overrideConfigs(Mutable databaseConfiguration) {
|
|
if (url != null) {
|
|
if (url != null) {
|
|
databaseConfiguration.setProperty("DatabaseURL", url);
|
|
databaseConfiguration.setProperty("DatabaseURL", url);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (user != null) {
|
|
if (user != null) {
|
|
databaseConfiguration.setProperty("DatabaseUser", user);
|
|
databaseConfiguration.setProperty("DatabaseUser", user);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (password != null) {
|
|
if (password != null) {
|
|
databaseConfiguration.setProperty("DatabasePassword", password);
|
|
databaseConfiguration.setProperty("DatabasePassword", password);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (name != null) {
|
|
if (name != null) {
|
|
databaseConfiguration.setProperty("DatabaseName", name);
|
|
databaseConfiguration.setProperty("DatabaseName", name);
|
|
}
|
|
}
|