|
@@ -28,16 +28,15 @@ import com.l2jserver.cli.util.SQLFilter;
|
|
|
|
|
|
/**
|
|
|
* Database DAO.
|
|
|
- *
|
|
|
* @author Zoey76
|
|
|
* @version 1.0.0
|
|
|
*/
|
|
|
public abstract class AbstractDatabaseDAO extends AbstractDAO {
|
|
|
-
|
|
|
+
|
|
|
AbstractDatabaseDAO(ServerConfiguration server) {
|
|
|
super(server);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void mods(File sqlPath) {
|
|
|
final var modsPath = new File(sqlPath, "mods");
|
|
|
if (modsPath.exists()) {
|
|
@@ -45,7 +44,7 @@ public abstract class AbstractDatabaseDAO extends AbstractDAO {
|
|
|
runSQLFiles(modsPath.listFiles(new SQLFilter()));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void custom(File sqlPath) {
|
|
|
final var customPath = new File(sqlPath, "custom");
|
|
|
if (customPath.exists()) {
|
|
@@ -53,60 +52,60 @@ public abstract class AbstractDatabaseDAO extends AbstractDAO {
|
|
|
runSQLFiles(customPath.listFiles(new SQLFilter()));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void basic(File sqlPath) {
|
|
|
System.out.println("Installing basic SQL scripts...");
|
|
|
final var files = sqlPath.listFiles(new SQLFilter());
|
|
|
runSQLFiles(files);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected void updates(DatabaseInstallType mode, String cleanup, File sqlPath) {
|
|
|
final var userPreferences = Preferences.userRoot();
|
|
|
final var updatePath = new File(sqlPath, "updates");
|
|
|
final var updatePreferences = getDatabase() + "_update";
|
|
|
-
|
|
|
+
|
|
|
switch (mode) {
|
|
|
- case FULL: {
|
|
|
- System.out.println("Executing cleanup script...");
|
|
|
-
|
|
|
- runSQLFiles(new File(sqlPath, cleanup));
|
|
|
-
|
|
|
- if (updatePath.exists()) {
|
|
|
- final var sb = new StringBuilder();
|
|
|
- for (var sqlFile : updatePath.listFiles(new SQLFilter())) {
|
|
|
- sb.append(sqlFile.getName() + ';');
|
|
|
+ case FULL: {
|
|
|
+ System.out.println("Executing cleanup script...");
|
|
|
+
|
|
|
+ runSQLFiles(new File(sqlPath, cleanup));
|
|
|
+
|
|
|
+ if (updatePath.exists()) {
|
|
|
+ final var sb = new StringBuilder();
|
|
|
+ for (var sqlFile : updatePath.listFiles(new SQLFilter())) {
|
|
|
+ sb.append(sqlFile.getName() + ';');
|
|
|
+ }
|
|
|
+ userPreferences.put(updatePreferences, sb.toString());
|
|
|
}
|
|
|
- userPreferences.put(updatePreferences, sb.toString());
|
|
|
+ break;
|
|
|
}
|
|
|
- break;
|
|
|
- }
|
|
|
- case UPDATE: {
|
|
|
- System.out.println("Installing update SQL scripts...");
|
|
|
- final var updated = userPreferences.get(updatePreferences, "");
|
|
|
- if (updatePath.exists()) {
|
|
|
- for (var sqlFile : updatePath.listFiles(new SQLFilter())) {
|
|
|
- if (!updated.contains(sqlFile.getName())) {
|
|
|
- try {
|
|
|
- System.out.println("Installing " + sqlFile.getName() + "...");
|
|
|
- executeSQLScript(sqlFile);
|
|
|
- } catch (Exception ex) {
|
|
|
- System.err.println("There has been an error executing SQL update!");
|
|
|
- ex.printStackTrace();
|
|
|
- return;
|
|
|
+ case UPDATE: {
|
|
|
+ System.out.println("Installing update SQL scripts...");
|
|
|
+ final var updated = userPreferences.get(updatePreferences, "");
|
|
|
+ if (updatePath.exists()) {
|
|
|
+ for (var sqlFile : updatePath.listFiles(new SQLFilter())) {
|
|
|
+ if (!updated.contains(sqlFile.getName())) {
|
|
|
+ try {
|
|
|
+ System.out.println("Installing " + sqlFile.getName() + "...");
|
|
|
+ executeSQLScript(sqlFile);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ System.err.println("There has been an error executing SQL update!");
|
|
|
+ ex.printStackTrace();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ userPreferences.put(updatePreferences, updated + sqlFile.getName() + ";");
|
|
|
}
|
|
|
- userPreferences.put(updatePreferences, updated + sqlFile.getName() + ";");
|
|
|
}
|
|
|
}
|
|
|
+ break;
|
|
|
}
|
|
|
- break;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void updates(DatabaseInstallType mode, File sqlPath) {
|
|
|
updates(mode, "cleanup/cleanup.sql", sqlPath);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void runSQLFiles(File... sqlFiles) {
|
|
|
Arrays.sort(sqlFiles);
|
|
|
|