Skip to content

Commit

Permalink
1.25
Browse files Browse the repository at this point in the history
- do not replace name field in generated Database class
  • Loading branch information
Osiris-Team committed Nov 9, 2023
1 parent 6958b1d commit 36cf296
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.osiris.jsqlgen</groupId>
<artifactId>jSQL-Gen</artifactId>
<version>1.24</version>
<version>1.25</version>
<name>jSQL-Gen</name>

<properties>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/osiris/jsqlgen/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ public <T extends Node> List<File> generateCode(List<Database> databases, File o
File databaseFile = new File(dir + "/Database.java");
String rawUrl = "\"jdbc:mysql://localhost/\"";
String url = "\"jdbc:mysql://localhost/" + db.name+"\"";
String name = "\""+db.name+"\"";
String username = "\"\"";
String password = "\"\"";
if (databaseFile.exists()) {
Expand All @@ -463,6 +464,9 @@ public <T extends Node> List<File> generateCode(List<Database> databases, File o
else if (Objects.equals(var.getName().asString(), "url"))
if(varInit.isStringLiteralExpr()) url = "\""+varInit.asStringLiteralExpr().asString()+"\"";
else url = varInit.toString();
else if (Objects.equals(var.getName().asString(), "name"))
if(varInit.isStringLiteralExpr()) name = "\""+varInit.asStringLiteralExpr().asString()+"\"";
else name = varInit.toString();
else if (Objects.equals(var.getName().asString(), "username"))
if(varInit.isStringLiteralExpr()) username = "\""+varInit.asStringLiteralExpr().asString()+"\"";
else username = varInit.toString();
Expand All @@ -473,7 +477,7 @@ else if (Objects.equals(var.getName().asString(), "password"))
}
}
databaseFile.createNewFile();
JavaCodeGenerator.generateDatabaseFile(db, databaseFile, rawUrl, url, username, password);
JavaCodeGenerator.generateDatabaseFile(db, databaseFile, rawUrl, url, name, username, password);
files.add(databaseFile);
for (Table t : db.tables) {
File javaFile = new File(dir + "/" + t.name + ".java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ public static String generateWhereClass(Table table) {
" }\n";
}

public static void generateDatabaseFile(Database db, File databaseFile, String rawUrl, String url, String username, String password) throws IOException {
public static void generateDatabaseFile(Database db, File databaseFile, String rawUrl, String url, String name, String username, String password) throws IOException {
databaseFile.getParentFile().mkdirs();
databaseFile.createNewFile();
Files.writeString(databaseFile.toPath(), "" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void generate() throws Exception {
db.name = "testDB";
File dir = new File(System.getProperty("user.dir")+"/src/test/java/com/osiris/jsqlgen/testDB");
db.javaProjectDir = dir;
JavaCodeGenerator.generateDatabaseFile(db, new File(dir+"/Database.java"), "\"raw-url\"", "\"url\"", "\"username\"", "\"password\"");
JavaCodeGenerator.generateDatabaseFile(db, new File(dir+"/Database.java"), "\"raw-url\"", "\"url\"", "testDB", "\"username\"", "\"password\"");

Table t = new Table();
db.tables.add(t);
Expand Down

0 comments on commit 36cf296

Please sign in to comment.