Skip to content

Commit

Permalink
jsqlgen
Browse files Browse the repository at this point in the history
  • Loading branch information
Osiris-Team committed Nov 5, 2023
1 parent f3d94e4 commit 5bb6ea7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/main/java/com/osiris/jsqlgen/payhook/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

Expand All @@ -27,22 +28,27 @@ public class Database{

public static void create() {

// Do the below to avoid "No suitable driver found..." exception
String driverClassName = "com.mysql.cj.jdbc.Driver";
// Do the below to avoid "No suitable driver found..." exception
String[] driversClassNames = new String[]{"com.mysql.cj.jdbc.Driver", "com.mysql.jdbc.Driver",
"oracle.jdbc.OracleDriver", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "org.postgresql.Driver",
"org.sqlite.JDBC", "org.h2.Driver", "com.ibm.db2.jcc.DB2Driver", "org.apache.derby.jdbc.ClientDriver",
"org.mariadb.jdbc.Driver", "org.apache.derby.jdbc.ClientDriver"};
Class<?> driverClass = null;
Exception lastException = null;
for (int i = 0; i < driversClassNames.length; i++) {
String driverClassName = driversClassNames[i];
try {
Class<?> driverClass = Class.forName(driverClassName);
driverClass = Class.forName(driverClassName);
Objects.requireNonNull(driverClass);
} catch (ClassNotFoundException e) {
try {
driverClassName = "com.mysql.jdbc.Driver"; // Try deprecated driver as fallback
Class<?> driverClass = Class.forName(driverClassName);
Objects.requireNonNull(driverClass);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
System.err.println("Failed to find critical database driver class: "+driverClassName+" program will exit.");
System.exit(1);
}
} catch (Exception e) {
lastException = e;
}
}
if(driverClass == null){
if(lastException != null) lastException.printStackTrace();
System.err.println("Failed to find critical database driver class, program will exit! Searched classes: "+ Arrays.toString(driversClassNames));
System.exit(1);
}

// Create database if not exists
try(Connection c = DriverManager.getConnection(Database.rawUrl, Database.username, Database.password);
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/osiris/jsqlgen/payhook_structure.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,52 @@
"isDebug": false,
"isNoExceptions": true,
"isCache": false
},
{
"name": "PendingPaymentCancel",
"columns": [
{
"name": "id",
"nameQuoted": "`id`",
"definition": "INT NOT NULL PRIMARY KEY"
},
{
"name": "paymentId",
"nameQuoted": "`paymentId`",
"definition": "INT NOT NULL"
},
{
"name": "timestampCancel",
"nameQuoted": "`timestampCancel`",
"definition": "BIGINT NOT NULL"
}
],
"isDebug": false,
"isNoExceptions": true,
"isCache": false
},
{
"name": "WebhookEndpoint",
"columns": [
{
"name": "id",
"nameQuoted": "`id`",
"definition": "INT NOT NULL PRIMARY KEY"
},
{
"name": "url",
"nameQuoted": "`url`",
"definition": "TEXT NOT NULL"
},
{
"name": "stripeWebhookSecret",
"nameQuoted": "`stripeWebhookSecret`",
"definition": "TEXT NOT NULL"
}
],
"isDebug": false,
"isNoExceptions": true,
"isCache": false
}
],
"javaProjectDir": "D:\\Coding\\JAVA\\PayHook"
Expand Down

0 comments on commit 5bb6ea7

Please sign in to comment.