Wasted a few hours without testing

This commit is contained in:
Willem Cazander 2022-10-17 00:10:53 +02:00
parent 53748cae84
commit 4a140b3459
8 changed files with 79 additions and 35 deletions

View file

@ -1,7 +1,6 @@
package love.distributedrebirth.gdxapp4d.app.mmdoc;
import java.io.File;
import java.sql.SQLException;
import java.util.Map.Entry;
import java.util.function.Consumer;
@ -26,7 +25,7 @@ public class MMDocDeskApp extends AbstractDeskApp implements DeskAppRenderer {
private final NativeFileChooser fileChooser;
private final NativeFileChooserConfiguration fileChooserConfig;
private final MMDocManager docManager = new MMDocManager();
private final MMDocManager docManager;
private final ImString dbHost = new ImString();
private final ImString dbName = new ImString();
private final ImString dbUser = new ImString();
@ -39,6 +38,8 @@ public class MMDocDeskApp extends AbstractDeskApp implements DeskAppRenderer {
fileChooserConfig = new NativeFileChooserConfiguration();
fileChooserConfig.directory = Gdx.files.absolute(System.getProperty("user.home"));
fileChooserConfig.title = "Choose file";
docManager = new MMDocManager();
docManager.loadDrivers();
}
public void create() {
@ -75,25 +76,24 @@ public class MMDocDeskApp extends AbstractDeskApp implements DeskAppRenderer {
result = "Added CSV file";
}));
}
ImGui.sameLine();
if (ImGui.button("Add PG")) {
try {
docManager.addDocModelJdbcPg(dbHost.get(), dbName.get(), dbUser.get(), dbPass.get());
result = "Added PG DB";
} catch (SQLException e) {
e.printStackTrace();
result = e.getMessage();
try {
ImGui.sameLine();
if (ImGui.button("Add Mariadb")) {
docManager.addDocModelJdbcMy(dbHost.get(), dbName.get(), dbUser.get(), dbPass.get());
result = "Added MariaDB";
}
}
if (ImGui.button("Generate")) {
try {
ImGui.sameLine();
if (ImGui.button("Add Postgresql")) {
docManager.addDocModelJdbcPg(dbHost.get(), dbName.get(), dbUser.get(), dbPass.get());
result = "Added Postgresqk DB";
}
if (ImGui.button("Generate")) {
docManager.generate(new File(docTarget.get()));
result = "done";
} catch (Exception e) {
e.printStackTrace();
result = e.getMessage();
}
} catch (Exception e) {
e.printStackTrace();
result = e.getMessage();
}
ImGui.sameLine();
ImGui.text("Result: "+result);

View file

@ -14,15 +14,22 @@ public class MMDocManager {
private final DocModelDataStore dms = new DocModelDataStore();
public void loadDrivers() { // mariadb has to be forced to load in ogsi bundle, pg works fine(no osgi info)
try {
Class.forName(org.postgresql.Driver.class.getName());
//Class.forName(org.h2.Driver.class.getName());
//Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver.class.getName());
Class.forName(org.mariadb.jdbc.Driver.class.getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public DocModelDataStore getDataStore() {
return dms;
}
public void generate(File targetPath) throws Exception {
Class.forName(org.postgresql.Driver.class.getName());
//Class.forName(org.h2.Driver.class.getName());
//Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver.class.getName());
try {
DocModelWriter writer = new DocModelWriter(dms);
writer.writeModelDoc(targetPath);