diff --git a/src/main/java/com/osiris/jsqlgen/payhook/Database.java b/src/main/java/com/osiris/jsqlgen/payhook/Database.java index 6f07e18..b66c7f2 100644 --- a/src/main/java/com/osiris/jsqlgen/payhook/Database.java +++ b/src/main/java/com/osiris/jsqlgen/payhook/Database.java @@ -17,12 +17,15 @@ It holds the database credentials (set by you at first run of jSQL-Gen).
- Ensures optimal performance (cpu and memory usage) for any type of database from small to huge, with millions of queries per second. - Connection status is checked before doing a query (since it could be closed or timed out and thus result in errors).*/ public class Database{ -public static String rawUrl = com.osiris.payhook.PayHook.databaseRawUrl; public static String url = com.osiris.payhook.PayHook.databaseUrl; +public static String rawUrl = com.osiris.payhook.PayHook.databaseRawUrl; public static String name = com.osiris.payhook.PayHook.databaseName; public static String username = com.osiris.payhook.PayHook.databaseUsername; public static String password = com.osiris.payhook.PayHook.databasePassword; -private static final List availableConnections = new ArrayList<>(); +/** +* Use synchronized on this before doing changes to it. +*/ +public static final List availableConnections = new ArrayList<>(); static{create();} // Create database if not exists @@ -65,18 +68,19 @@ public static void create() { public static Connection getCon() { synchronized (availableConnections){ try{ + Connection availableCon = null; if (!availableConnections.isEmpty()) { List removableConnections = new ArrayList<>(0); for (Connection con : availableConnections) { - if (con.isValid(1)) return con; - else removableConnections.add(con); + if (!con.isValid(1)) {con.close(); removableConnections.add(con);} + else {availableCon = con; removableConnections.add(con); break;} } for (Connection removableConnection : removableConnections) { - removableConnection.close(); - availableConnections.remove(removableConnection); // Remove invalid connections + availableConnections.remove(removableConnection); // Remove invalid or used connections } } - return DriverManager.getConnection(Database.url, Database.username, Database.password); + if (availableCon != null) return availableCon; + else return DriverManager.getConnection(Database.url, Database.username, Database.password); } catch (Exception e) { throw new RuntimeException(e); } @@ -88,4 +92,22 @@ public static void freeCon(Connection connection) { availableConnections.add(connection); } } -} + /** + * Gets the raw database url without database name.
+ * Before: "jdbc:mysql://localhost/my_database"
+ * After: "jdbc:mysql://localhost"
+ */ + public static String getRawDbUrlFrom(String databaseUrl) { + int index = 0; + int count = 0; + for (int i = 0; i < databaseUrl.length(); i++) { + char c = databaseUrl.charAt(i); + if(c == '/'){ + index = i; + count++; + } + if(count == 3) break; + } + if(count != 3) return databaseUrl; // Means there is less than 3 "/", thus may already be raw url, or totally wrong url + return databaseUrl.substring(0, index); + }} diff --git a/src/main/java/com/osiris/jsqlgen/payhook/Payment.java b/src/main/java/com/osiris/jsqlgen/payhook/Payment.java index 688b3e0..b7d3be7 100644 --- a/src/main/java/com/osiris/jsqlgen/payhook/Payment.java +++ b/src/main/java/com/osiris/jsqlgen/payhook/Payment.java @@ -21,7 +21,7 @@ NO EXCEPTIONS is enabled which makes it possible to use this methods outside of try/catch blocks because SQL errors will be caught and thrown as runtime exceptions instead.
*/ public class Payment{ -private static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); +public static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); static { try{ Connection con = Database.getCon(); @@ -246,11 +246,11 @@ public static Payment get(int id) { if that statement is null, returns all the contents of this table. */ public static List get(String where, Object... whereValues) { -Connection con = Database.getCon(); String sql = "SELECT `id`,`userId`,`charge`,`currency`,`interval`,`url`,`productId`,`productName`,`productQuantity`,`timestampCreated`,`timestampExpires`,`timestampAuthorized`,`timestampCancelled`,`timestampRefunded`,`stripeSessionId`,`stripeSubscriptionId`,`stripePaymentIntentId`,`paypalOrderId`,`paypalSubscriptionId`,`paypalCaptureId`" + " FROM `payment`" + (where != null ? where : ""); List list = new ArrayList<>(); +Connection con = Database.getCon(); try (PreparedStatement ps = con.prepareStatement(sql)) { if(where!=null && whereValues!=null) for (int i = 0; i < whereValues.length; i++) { @@ -338,6 +338,8 @@ public static void getLazy(Consumer> onResultReceived, Consumer whereId() { +return new WHERE("`id`"); } -public static WHERE whereUserId() { -return new WHERE("`userId`"); +public static WHERE whereUserId() { +return new WHERE("`userId`"); } -public static WHERE whereCharge() { -return new WHERE("`charge`"); +public static WHERE whereCharge() { +return new WHERE("`charge`"); } -public static WHERE whereCurrency() { -return new WHERE("`currency`"); +public static WHERE whereCurrency() { +return new WHERE("`currency`"); } -public static WHERE whereInterval() { -return new WHERE("`interval`"); +public static WHERE whereInterval() { +return new WHERE("`interval`"); } -public static WHERE whereUrl() { -return new WHERE("`url`"); +public static WHERE whereUrl() { +return new WHERE("`url`"); } -public static WHERE whereProductId() { -return new WHERE("`productId`"); +public static WHERE whereProductId() { +return new WHERE("`productId`"); } -public static WHERE whereProductName() { -return new WHERE("`productName`"); +public static WHERE whereProductName() { +return new WHERE("`productName`"); } -public static WHERE whereProductQuantity() { -return new WHERE("`productQuantity`"); +public static WHERE whereProductQuantity() { +return new WHERE("`productQuantity`"); } -public static WHERE whereTimestampCreated() { -return new WHERE("`timestampCreated`"); +public static WHERE whereTimestampCreated() { +return new WHERE("`timestampCreated`"); } -public static WHERE whereTimestampExpires() { -return new WHERE("`timestampExpires`"); +public static WHERE whereTimestampExpires() { +return new WHERE("`timestampExpires`"); } -public static WHERE whereTimestampAuthorized() { -return new WHERE("`timestampAuthorized`"); +public static WHERE whereTimestampAuthorized() { +return new WHERE("`timestampAuthorized`"); } -public static WHERE whereTimestampCancelled() { -return new WHERE("`timestampCancelled`"); +public static WHERE whereTimestampCancelled() { +return new WHERE("`timestampCancelled`"); } -public static WHERE whereTimestampRefunded() { -return new WHERE("`timestampRefunded`"); +public static WHERE whereTimestampRefunded() { +return new WHERE("`timestampRefunded`"); } -public static WHERE whereStripeSessionId() { -return new WHERE("`stripeSessionId`"); +public static WHERE whereStripeSessionId() { +return new WHERE("`stripeSessionId`"); } -public static WHERE whereStripeSubscriptionId() { -return new WHERE("`stripeSubscriptionId`"); +public static WHERE whereStripeSubscriptionId() { +return new WHERE("`stripeSubscriptionId`"); } -public static WHERE whereStripePaymentIntentId() { -return new WHERE("`stripePaymentIntentId`"); +public static WHERE whereStripePaymentIntentId() { +return new WHERE("`stripePaymentIntentId`"); } -public static WHERE wherePaypalOrderId() { -return new WHERE("`paypalOrderId`"); +public static WHERE wherePaypalOrderId() { +return new WHERE("`paypalOrderId`"); } -public static WHERE wherePaypalSubscriptionId() { -return new WHERE("`paypalSubscriptionId`"); +public static WHERE wherePaypalSubscriptionId() { +return new WHERE("`paypalSubscriptionId`"); } -public static WHERE wherePaypalCaptureId() { -return new WHERE("`paypalCaptureId`"); +public static WHERE wherePaypalCaptureId() { +return new WHERE("`paypalCaptureId`"); } -public static class WHERE { +public static class WHERE { /** * Remember to prepend WHERE on the final SQL statement. * This is not done by this class due to performance reasons.

@@ -557,7 +559,7 @@ public List get() { if(!whereObjects.isEmpty()) return Payment.get(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return Payment.get(where+orderBy+limitBuilder.toString(), (Object[]) null); + return Payment.get(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -572,7 +574,7 @@ public int count() { if(!whereObjects.isEmpty()) return Payment.count(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return Payment.count(where+orderBy+limitBuilder.toString(), (Object[]) null); + return Payment.count(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -587,13 +589,13 @@ public void remove() { if(!whereObjects.isEmpty()) Payment.remove(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - Payment.remove(where+orderBy+limitBuilder.toString(), (Object[]) null); + Payment.remove(where+orderBy+limitBuilder.toString(), (T[]) null); } /** * AND (...)
*/ - public WHERE and(WHERE where) { + public WHERE and(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("AND (").append(sql).append(") "); @@ -606,7 +608,7 @@ public WHERE and(WHERE where) { /** * OR (...)
*/ - public WHERE or(WHERE where) { + public WHERE or(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("OR (").append(sql).append(") "); @@ -619,7 +621,7 @@ public WHERE or(WHERE where) { /** * columnName = ?
*/ - public WHERE is(Object obj) { + public WHERE is(T obj) { sqlBuilder.append(columnName).append(" = ? "); whereObjects.add(obj); return this; @@ -630,9 +632,9 @@ public WHERE is(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_in.asp */ - public WHERE is(Object... objects) { + public WHERE is(T... objects) { String s = ""; - for (Object obj : objects) { + for (T obj : objects) { s += "?,"; whereObjects.add(obj); } @@ -644,7 +646,7 @@ public WHERE is(Object... objects) { /** * columnName <> ?
*/ - public WHERE isNot(Object obj) { + public WHERE isNot(T obj) { sqlBuilder.append(columnName).append(" <> ? "); whereObjects.add(obj); return this; @@ -653,7 +655,7 @@ public WHERE isNot(Object obj) { /** * columnName IS NULL
*/ - public WHERE isNull() { + public WHERE isNull() { sqlBuilder.append(columnName).append(" IS NULL "); return this; } @@ -661,7 +663,7 @@ public WHERE isNull() { /** * columnName IS NOT NULL
*/ - public WHERE isNotNull() { + public WHERE isNotNull() { sqlBuilder.append(columnName).append(" IS NOT NULL "); return this; } @@ -671,7 +673,7 @@ public WHERE isNotNull() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE like(Object obj) { + public WHERE like(T obj) { sqlBuilder.append(columnName).append(" LIKE ? "); whereObjects.add(obj); return this; @@ -682,7 +684,7 @@ public WHERE like(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE notLike(Object obj) { + public WHERE notLike(T obj) { sqlBuilder.append(columnName).append(" NOT LIKE ? "); whereObjects.add(obj); return this; @@ -691,7 +693,7 @@ public WHERE notLike(Object obj) { /** * columnName > ?
*/ - public WHERE biggerThan(Object obj) { + public WHERE biggerThan(T obj) { sqlBuilder.append(columnName).append(" > ? "); whereObjects.add(obj); return this; @@ -700,7 +702,7 @@ public WHERE biggerThan(Object obj) { /** * columnName < ?
*/ - public WHERE smallerThan(Object obj) { + public WHERE smallerThan(T obj) { sqlBuilder.append(columnName).append(" < ? "); whereObjects.add(obj); return this; @@ -709,7 +711,7 @@ public WHERE smallerThan(Object obj) { /** * columnName >= ?
*/ - public WHERE biggerOrEqual(Object obj) { + public WHERE biggerOrEqual(T obj) { sqlBuilder.append(columnName).append(" >= ? "); whereObjects.add(obj); return this; @@ -718,7 +720,7 @@ public WHERE biggerOrEqual(Object obj) { /** * columnName <= ?
*/ - public WHERE smallerOrEqual(Object obj) { + public WHERE smallerOrEqual(T obj) { sqlBuilder.append(columnName).append(" <= ? "); whereObjects.add(obj); return this; @@ -727,7 +729,7 @@ public WHERE smallerOrEqual(Object obj) { /** * columnName BETWEEN ? AND ?
*/ - public WHERE between(Object obj1, Object obj2) { + public WHERE between(T obj1, T obj2) { sqlBuilder.append(columnName).append(" BETWEEN ? AND ? "); whereObjects.add(obj1); whereObjects.add(obj2); @@ -739,7 +741,7 @@ public WHERE between(Object obj1, Object obj2) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE smallestFirst() { + public WHERE smallestFirst() { orderByBuilder.append(columnName + " ASC, "); return this; } @@ -749,7 +751,7 @@ public WHERE smallestFirst() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE biggestFirst() { + public WHERE biggestFirst() { orderByBuilder.append(columnName + " DESC, "); return this; } @@ -759,7 +761,7 @@ public WHERE biggestFirst() { * * @see https://www.w3schools.com/mysql/mysql_limit.asp */ - public WHERE limit(int num) { + public WHERE limit(int num) { limitBuilder.append("LIMIT ").append(num + " "); return this; } diff --git a/src/main/java/com/osiris/jsqlgen/payhook/PaymentWarning.java b/src/main/java/com/osiris/jsqlgen/payhook/PaymentWarning.java index c670d3c..54a28d8 100644 --- a/src/main/java/com/osiris/jsqlgen/payhook/PaymentWarning.java +++ b/src/main/java/com/osiris/jsqlgen/payhook/PaymentWarning.java @@ -18,7 +18,7 @@ NO EXCEPTIONS is enabled which makes it possible to use this methods outside of try/catch blocks because SQL errors will be caught and thrown as runtime exceptions instead.
*/ public class PaymentWarning{ -private static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); +public static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); static { try{ Connection con = Database.getCon(); @@ -140,11 +140,11 @@ public static PaymentWarning get(int id) { if that statement is null, returns all the contents of this table. */ public static List get(String where, Object... whereValues) { -Connection con = Database.getCon(); String sql = "SELECT `id`,`paymentId`,`message`" + " FROM `paymentwarning`" + (where != null ? where : ""); List list = new ArrayList<>(); +Connection con = Database.getCon(); try (PreparedStatement ps = con.prepareStatement(sql)) { if(where!=null && whereValues!=null) for (int i = 0; i < whereValues.length; i++) { @@ -215,6 +215,8 @@ public static void getLazy(Consumer> onResultReceived, Cons }).start(); } +public static int count(){ return count(null, null); } + public static int count(String where, Object... whereValues) { String sql = "SELECT COUNT(`id`) AS recordCount FROM `paymentwarning`" + (where != null ? where : ""); @@ -238,9 +240,9 @@ Searches the provided object in the database (by its id), @throws Exception when failed to find by id or other SQL issues. */ public static void update(PaymentWarning obj) { +String sql = "UPDATE `paymentwarning` SET `id`=?,`paymentId`=?,`message`=? WHERE id="+obj.id; Connection con = Database.getCon(); -try (PreparedStatement ps = con.prepareStatement( - "UPDATE `paymentwarning` SET `id`=?,`paymentId`=?,`message`=? WHERE id="+obj.id)) { +try (PreparedStatement ps = con.prepareStatement(sql)) { ps.setInt(1, obj.id); ps.setInt(2, obj.paymentId); ps.setString(3, obj.message); @@ -253,9 +255,9 @@ public static void update(PaymentWarning obj) { Adds the provided object to the database (note that the id is not checked for duplicates). */ public static void add(PaymentWarning obj) { +String sql = "INSERT INTO `paymentwarning` (`id`,`paymentId`,`message`) VALUES (?,?,?)"; Connection con = Database.getCon(); -try (PreparedStatement ps = con.prepareStatement( - "INSERT INTO `paymentwarning` (`id`,`paymentId`,`message`) VALUES (?,?,?)")) { +try (PreparedStatement ps = con.prepareStatement(sql)) { ps.setInt(1, obj.id); ps.setInt(2, obj.paymentId); ps.setString(3, obj.message); @@ -293,9 +295,9 @@ public static void remove(String where, Object... whereValues) { } public static void removeAll() { - Connection con = Database.getCon(); - try (PreparedStatement ps = con.prepareStatement( - "DELETE FROM `paymentwarning`")) { +String sql = "DELETE FROM `paymentwarning`"; +Connection con = Database.getCon(); + try (PreparedStatement ps = con.prepareStatement(sql)) { ps.executeUpdate(); }catch(Exception e){throw new RuntimeException(e);} finally{Database.freeCon(con);} @@ -307,16 +309,16 @@ public PaymentWarning clone(){ public String toPrintString(){ return ""+"id="+this.id+" "+"paymentId="+this.paymentId+" "+"message="+this.message+" "; } -public static WHERE whereId() { -return new WHERE("`id`"); +public static WHERE whereId() { +return new WHERE("`id`"); } -public static WHERE wherePaymentId() { -return new WHERE("`paymentId`"); +public static WHERE wherePaymentId() { +return new WHERE("`paymentId`"); } -public static WHERE whereMessage() { -return new WHERE("`message`"); +public static WHERE whereMessage() { +return new WHERE("`message`"); } -public static class WHERE { +public static class WHERE { /** * Remember to prepend WHERE on the final SQL statement. * This is not done by this class due to performance reasons.

@@ -349,7 +351,7 @@ public List get() { if(!whereObjects.isEmpty()) return PaymentWarning.get(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return PaymentWarning.get(where+orderBy+limitBuilder.toString(), (Object[]) null); + return PaymentWarning.get(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -364,7 +366,7 @@ public int count() { if(!whereObjects.isEmpty()) return PaymentWarning.count(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return PaymentWarning.count(where+orderBy+limitBuilder.toString(), (Object[]) null); + return PaymentWarning.count(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -379,13 +381,13 @@ public void remove() { if(!whereObjects.isEmpty()) PaymentWarning.remove(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - PaymentWarning.remove(where+orderBy+limitBuilder.toString(), (Object[]) null); + PaymentWarning.remove(where+orderBy+limitBuilder.toString(), (T[]) null); } /** * AND (...)
*/ - public WHERE and(WHERE where) { + public WHERE and(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("AND (").append(sql).append(") "); @@ -398,7 +400,7 @@ public WHERE and(WHERE where) { /** * OR (...)
*/ - public WHERE or(WHERE where) { + public WHERE or(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("OR (").append(sql).append(") "); @@ -411,7 +413,7 @@ public WHERE or(WHERE where) { /** * columnName = ?
*/ - public WHERE is(Object obj) { + public WHERE is(T obj) { sqlBuilder.append(columnName).append(" = ? "); whereObjects.add(obj); return this; @@ -422,9 +424,9 @@ public WHERE is(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_in.asp */ - public WHERE is(Object... objects) { + public WHERE is(T... objects) { String s = ""; - for (Object obj : objects) { + for (T obj : objects) { s += "?,"; whereObjects.add(obj); } @@ -436,7 +438,7 @@ public WHERE is(Object... objects) { /** * columnName <> ?
*/ - public WHERE isNot(Object obj) { + public WHERE isNot(T obj) { sqlBuilder.append(columnName).append(" <> ? "); whereObjects.add(obj); return this; @@ -445,7 +447,7 @@ public WHERE isNot(Object obj) { /** * columnName IS NULL
*/ - public WHERE isNull() { + public WHERE isNull() { sqlBuilder.append(columnName).append(" IS NULL "); return this; } @@ -453,7 +455,7 @@ public WHERE isNull() { /** * columnName IS NOT NULL
*/ - public WHERE isNotNull() { + public WHERE isNotNull() { sqlBuilder.append(columnName).append(" IS NOT NULL "); return this; } @@ -463,7 +465,7 @@ public WHERE isNotNull() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE like(Object obj) { + public WHERE like(T obj) { sqlBuilder.append(columnName).append(" LIKE ? "); whereObjects.add(obj); return this; @@ -474,7 +476,7 @@ public WHERE like(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE notLike(Object obj) { + public WHERE notLike(T obj) { sqlBuilder.append(columnName).append(" NOT LIKE ? "); whereObjects.add(obj); return this; @@ -483,7 +485,7 @@ public WHERE notLike(Object obj) { /** * columnName > ?
*/ - public WHERE biggerThan(Object obj) { + public WHERE biggerThan(T obj) { sqlBuilder.append(columnName).append(" > ? "); whereObjects.add(obj); return this; @@ -492,7 +494,7 @@ public WHERE biggerThan(Object obj) { /** * columnName < ?
*/ - public WHERE smallerThan(Object obj) { + public WHERE smallerThan(T obj) { sqlBuilder.append(columnName).append(" < ? "); whereObjects.add(obj); return this; @@ -501,7 +503,7 @@ public WHERE smallerThan(Object obj) { /** * columnName >= ?
*/ - public WHERE biggerOrEqual(Object obj) { + public WHERE biggerOrEqual(T obj) { sqlBuilder.append(columnName).append(" >= ? "); whereObjects.add(obj); return this; @@ -510,7 +512,7 @@ public WHERE biggerOrEqual(Object obj) { /** * columnName <= ?
*/ - public WHERE smallerOrEqual(Object obj) { + public WHERE smallerOrEqual(T obj) { sqlBuilder.append(columnName).append(" <= ? "); whereObjects.add(obj); return this; @@ -519,7 +521,7 @@ public WHERE smallerOrEqual(Object obj) { /** * columnName BETWEEN ? AND ?
*/ - public WHERE between(Object obj1, Object obj2) { + public WHERE between(T obj1, T obj2) { sqlBuilder.append(columnName).append(" BETWEEN ? AND ? "); whereObjects.add(obj1); whereObjects.add(obj2); @@ -531,7 +533,7 @@ public WHERE between(Object obj1, Object obj2) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE smallestFirst() { + public WHERE smallestFirst() { orderByBuilder.append(columnName + " ASC, "); return this; } @@ -541,7 +543,7 @@ public WHERE smallestFirst() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE biggestFirst() { + public WHERE biggestFirst() { orderByBuilder.append(columnName + " DESC, "); return this; } @@ -551,7 +553,7 @@ public WHERE biggestFirst() { * * @see https://www.w3schools.com/mysql/mysql_limit.asp */ - public WHERE limit(int num) { + public WHERE limit(int num) { limitBuilder.append("LIMIT ").append(num + " "); return this; } diff --git a/src/main/java/com/osiris/jsqlgen/payhook/PendingPaymentCancel.java b/src/main/java/com/osiris/jsqlgen/payhook/PendingPaymentCancel.java index 60530be..20de1f1 100644 --- a/src/main/java/com/osiris/jsqlgen/payhook/PendingPaymentCancel.java +++ b/src/main/java/com/osiris/jsqlgen/payhook/PendingPaymentCancel.java @@ -18,7 +18,7 @@ NO EXCEPTIONS is enabled which makes it possible to use this methods outside of try/catch blocks because SQL errors will be caught and thrown as runtime exceptions instead.
*/ public class PendingPaymentCancel{ -private static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); +public static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); static { try{ Connection con = Database.getCon(); @@ -109,11 +109,11 @@ public static PendingPaymentCancel get(int id) { if that statement is null, returns all the contents of this table. */ public static List get(String where, Object... whereValues) { -Connection con = Database.getCon(); String sql = "SELECT `id`,`paymentId`,`timestampCancel`" + " FROM `pendingpaymentcancel`" + (where != null ? where : ""); List list = new ArrayList<>(); +Connection con = Database.getCon(); try (PreparedStatement ps = con.prepareStatement(sql)) { if(where!=null && whereValues!=null) for (int i = 0; i < whereValues.length; i++) { @@ -184,6 +184,8 @@ public static void getLazy(Consumer> onResultReceived }).start(); } +public static int count(){ return count(null, null); } + public static int count(String where, Object... whereValues) { String sql = "SELECT COUNT(`id`) AS recordCount FROM `pendingpaymentcancel`" + (where != null ? where : ""); @@ -207,9 +209,9 @@ Searches the provided object in the database (by its id), @throws Exception when failed to find by id or other SQL issues. */ public static void update(PendingPaymentCancel obj) { +String sql = "UPDATE `pendingpaymentcancel` SET `id`=?,`paymentId`=?,`timestampCancel`=? WHERE id="+obj.id; Connection con = Database.getCon(); -try (PreparedStatement ps = con.prepareStatement( - "UPDATE `pendingpaymentcancel` SET `id`=?,`paymentId`=?,`timestampCancel`=? WHERE id="+obj.id)) { +try (PreparedStatement ps = con.prepareStatement(sql)) { ps.setInt(1, obj.id); ps.setInt(2, obj.paymentId); ps.setLong(3, obj.timestampCancel); @@ -222,9 +224,9 @@ public static void update(PendingPaymentCancel obj) { Adds the provided object to the database (note that the id is not checked for duplicates). */ public static void add(PendingPaymentCancel obj) { +String sql = "INSERT INTO `pendingpaymentcancel` (`id`,`paymentId`,`timestampCancel`) VALUES (?,?,?)"; Connection con = Database.getCon(); -try (PreparedStatement ps = con.prepareStatement( - "INSERT INTO `pendingpaymentcancel` (`id`,`paymentId`,`timestampCancel`) VALUES (?,?,?)")) { +try (PreparedStatement ps = con.prepareStatement(sql)) { ps.setInt(1, obj.id); ps.setInt(2, obj.paymentId); ps.setLong(3, obj.timestampCancel); @@ -262,9 +264,9 @@ public static void remove(String where, Object... whereValues) { } public static void removeAll() { - Connection con = Database.getCon(); - try (PreparedStatement ps = con.prepareStatement( - "DELETE FROM `pendingpaymentcancel`")) { +String sql = "DELETE FROM `pendingpaymentcancel`"; +Connection con = Database.getCon(); + try (PreparedStatement ps = con.prepareStatement(sql)) { ps.executeUpdate(); }catch(Exception e){throw new RuntimeException(e);} finally{Database.freeCon(con);} @@ -276,16 +278,16 @@ public PendingPaymentCancel clone(){ public String toPrintString(){ return ""+"id="+this.id+" "+"paymentId="+this.paymentId+" "+"timestampCancel="+this.timestampCancel+" "; } -public static WHERE whereId() { -return new WHERE("`id`"); +public static WHERE whereId() { +return new WHERE("`id`"); } -public static WHERE wherePaymentId() { -return new WHERE("`paymentId`"); +public static WHERE wherePaymentId() { +return new WHERE("`paymentId`"); } -public static WHERE whereTimestampCancel() { -return new WHERE("`timestampCancel`"); +public static WHERE whereTimestampCancel() { +return new WHERE("`timestampCancel`"); } -public static class WHERE { +public static class WHERE { /** * Remember to prepend WHERE on the final SQL statement. * This is not done by this class due to performance reasons.

@@ -318,7 +320,7 @@ public List get() { if(!whereObjects.isEmpty()) return PendingPaymentCancel.get(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return PendingPaymentCancel.get(where+orderBy+limitBuilder.toString(), (Object[]) null); + return PendingPaymentCancel.get(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -333,7 +335,7 @@ public int count() { if(!whereObjects.isEmpty()) return PendingPaymentCancel.count(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return PendingPaymentCancel.count(where+orderBy+limitBuilder.toString(), (Object[]) null); + return PendingPaymentCancel.count(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -348,13 +350,13 @@ public void remove() { if(!whereObjects.isEmpty()) PendingPaymentCancel.remove(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - PendingPaymentCancel.remove(where+orderBy+limitBuilder.toString(), (Object[]) null); + PendingPaymentCancel.remove(where+orderBy+limitBuilder.toString(), (T[]) null); } /** * AND (...)
*/ - public WHERE and(WHERE where) { + public WHERE and(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("AND (").append(sql).append(") "); @@ -367,7 +369,7 @@ public WHERE and(WHERE where) { /** * OR (...)
*/ - public WHERE or(WHERE where) { + public WHERE or(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("OR (").append(sql).append(") "); @@ -380,7 +382,7 @@ public WHERE or(WHERE where) { /** * columnName = ?
*/ - public WHERE is(Object obj) { + public WHERE is(T obj) { sqlBuilder.append(columnName).append(" = ? "); whereObjects.add(obj); return this; @@ -391,9 +393,9 @@ public WHERE is(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_in.asp */ - public WHERE is(Object... objects) { + public WHERE is(T... objects) { String s = ""; - for (Object obj : objects) { + for (T obj : objects) { s += "?,"; whereObjects.add(obj); } @@ -405,7 +407,7 @@ public WHERE is(Object... objects) { /** * columnName <> ?
*/ - public WHERE isNot(Object obj) { + public WHERE isNot(T obj) { sqlBuilder.append(columnName).append(" <> ? "); whereObjects.add(obj); return this; @@ -414,7 +416,7 @@ public WHERE isNot(Object obj) { /** * columnName IS NULL
*/ - public WHERE isNull() { + public WHERE isNull() { sqlBuilder.append(columnName).append(" IS NULL "); return this; } @@ -422,7 +424,7 @@ public WHERE isNull() { /** * columnName IS NOT NULL
*/ - public WHERE isNotNull() { + public WHERE isNotNull() { sqlBuilder.append(columnName).append(" IS NOT NULL "); return this; } @@ -432,7 +434,7 @@ public WHERE isNotNull() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE like(Object obj) { + public WHERE like(T obj) { sqlBuilder.append(columnName).append(" LIKE ? "); whereObjects.add(obj); return this; @@ -443,7 +445,7 @@ public WHERE like(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE notLike(Object obj) { + public WHERE notLike(T obj) { sqlBuilder.append(columnName).append(" NOT LIKE ? "); whereObjects.add(obj); return this; @@ -452,7 +454,7 @@ public WHERE notLike(Object obj) { /** * columnName > ?
*/ - public WHERE biggerThan(Object obj) { + public WHERE biggerThan(T obj) { sqlBuilder.append(columnName).append(" > ? "); whereObjects.add(obj); return this; @@ -461,7 +463,7 @@ public WHERE biggerThan(Object obj) { /** * columnName < ?
*/ - public WHERE smallerThan(Object obj) { + public WHERE smallerThan(T obj) { sqlBuilder.append(columnName).append(" < ? "); whereObjects.add(obj); return this; @@ -470,7 +472,7 @@ public WHERE smallerThan(Object obj) { /** * columnName >= ?
*/ - public WHERE biggerOrEqual(Object obj) { + public WHERE biggerOrEqual(T obj) { sqlBuilder.append(columnName).append(" >= ? "); whereObjects.add(obj); return this; @@ -479,7 +481,7 @@ public WHERE biggerOrEqual(Object obj) { /** * columnName <= ?
*/ - public WHERE smallerOrEqual(Object obj) { + public WHERE smallerOrEqual(T obj) { sqlBuilder.append(columnName).append(" <= ? "); whereObjects.add(obj); return this; @@ -488,7 +490,7 @@ public WHERE smallerOrEqual(Object obj) { /** * columnName BETWEEN ? AND ?
*/ - public WHERE between(Object obj1, Object obj2) { + public WHERE between(T obj1, T obj2) { sqlBuilder.append(columnName).append(" BETWEEN ? AND ? "); whereObjects.add(obj1); whereObjects.add(obj2); @@ -500,7 +502,7 @@ public WHERE between(Object obj1, Object obj2) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE smallestFirst() { + public WHERE smallestFirst() { orderByBuilder.append(columnName + " ASC, "); return this; } @@ -510,7 +512,7 @@ public WHERE smallestFirst() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE biggestFirst() { + public WHERE biggestFirst() { orderByBuilder.append(columnName + " DESC, "); return this; } @@ -520,7 +522,7 @@ public WHERE biggestFirst() { * * @see https://www.w3schools.com/mysql/mysql_limit.asp */ - public WHERE limit(int num) { + public WHERE limit(int num) { limitBuilder.append("LIMIT ").append(num + " "); return this; } diff --git a/src/main/java/com/osiris/jsqlgen/payhook/Product.java b/src/main/java/com/osiris/jsqlgen/payhook/Product.java index 004a3d9..f855f23 100644 --- a/src/main/java/com/osiris/jsqlgen/payhook/Product.java +++ b/src/main/java/com/osiris/jsqlgen/payhook/Product.java @@ -21,7 +21,7 @@ NO EXCEPTIONS is enabled which makes it possible to use this methods outside of try/catch blocks because SQL errors will be caught and thrown as runtime exceptions instead.
*/ public class Product{ -private static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); +public static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); static { try{ Connection con = Database.getCon(); @@ -185,11 +185,11 @@ public static Product get(int id) { if that statement is null, returns all the contents of this table. */ public static List get(String where, Object... whereValues) { -Connection con = Database.getCon(); String sql = "SELECT `id`,`charge`,`currency`,`name`,`description`,`paymentInterval`,`paypalProductId`,`paypalPlanId`,`stripeProductId`,`stripePriceId`" + " FROM `product`" + (where != null ? where : ""); List list = new ArrayList<>(); +Connection con = Database.getCon(); try (PreparedStatement ps = con.prepareStatement(sql)) { if(where!=null && whereValues!=null) for (int i = 0; i < whereValues.length; i++) { @@ -267,6 +267,8 @@ public static void getLazy(Consumer> onResultReceived, Consumer whereId() { +return new WHERE("`id`"); } -public static WHERE whereCharge() { -return new WHERE("`charge`"); +public static WHERE whereCharge() { +return new WHERE("`charge`"); } -public static WHERE whereCurrency() { -return new WHERE("`currency`"); +public static WHERE whereCurrency() { +return new WHERE("`currency`"); } -public static WHERE whereName() { -return new WHERE("`name`"); +public static WHERE whereName() { +return new WHERE("`name`"); } -public static WHERE whereDescription() { -return new WHERE("`description`"); +public static WHERE whereDescription() { +return new WHERE("`description`"); } -public static WHERE wherePaymentInterval() { -return new WHERE("`paymentInterval`"); +public static WHERE wherePaymentInterval() { +return new WHERE("`paymentInterval`"); } -public static WHERE wherePaypalProductId() { -return new WHERE("`paypalProductId`"); +public static WHERE wherePaypalProductId() { +return new WHERE("`paypalProductId`"); } -public static WHERE wherePaypalPlanId() { -return new WHERE("`paypalPlanId`"); +public static WHERE wherePaypalPlanId() { +return new WHERE("`paypalPlanId`"); } -public static WHERE whereStripeProductId() { -return new WHERE("`stripeProductId`"); +public static WHERE whereStripeProductId() { +return new WHERE("`stripeProductId`"); } -public static WHERE whereStripePriceId() { -return new WHERE("`stripePriceId`"); +public static WHERE whereStripePriceId() { +return new WHERE("`stripePriceId`"); } -public static class WHERE { +public static class WHERE { /** * Remember to prepend WHERE on the final SQL statement. * This is not done by this class due to performance reasons.

@@ -436,7 +438,7 @@ public List get() { if(!whereObjects.isEmpty()) return Product.get(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return Product.get(where+orderBy+limitBuilder.toString(), (Object[]) null); + return Product.get(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -451,7 +453,7 @@ public int count() { if(!whereObjects.isEmpty()) return Product.count(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return Product.count(where+orderBy+limitBuilder.toString(), (Object[]) null); + return Product.count(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -466,13 +468,13 @@ public void remove() { if(!whereObjects.isEmpty()) Product.remove(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - Product.remove(where+orderBy+limitBuilder.toString(), (Object[]) null); + Product.remove(where+orderBy+limitBuilder.toString(), (T[]) null); } /** * AND (...)
*/ - public WHERE and(WHERE where) { + public WHERE and(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("AND (").append(sql).append(") "); @@ -485,7 +487,7 @@ public WHERE and(WHERE where) { /** * OR (...)
*/ - public WHERE or(WHERE where) { + public WHERE or(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("OR (").append(sql).append(") "); @@ -498,7 +500,7 @@ public WHERE or(WHERE where) { /** * columnName = ?
*/ - public WHERE is(Object obj) { + public WHERE is(T obj) { sqlBuilder.append(columnName).append(" = ? "); whereObjects.add(obj); return this; @@ -509,9 +511,9 @@ public WHERE is(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_in.asp */ - public WHERE is(Object... objects) { + public WHERE is(T... objects) { String s = ""; - for (Object obj : objects) { + for (T obj : objects) { s += "?,"; whereObjects.add(obj); } @@ -523,7 +525,7 @@ public WHERE is(Object... objects) { /** * columnName <> ?
*/ - public WHERE isNot(Object obj) { + public WHERE isNot(T obj) { sqlBuilder.append(columnName).append(" <> ? "); whereObjects.add(obj); return this; @@ -532,7 +534,7 @@ public WHERE isNot(Object obj) { /** * columnName IS NULL
*/ - public WHERE isNull() { + public WHERE isNull() { sqlBuilder.append(columnName).append(" IS NULL "); return this; } @@ -540,7 +542,7 @@ public WHERE isNull() { /** * columnName IS NOT NULL
*/ - public WHERE isNotNull() { + public WHERE isNotNull() { sqlBuilder.append(columnName).append(" IS NOT NULL "); return this; } @@ -550,7 +552,7 @@ public WHERE isNotNull() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE like(Object obj) { + public WHERE like(T obj) { sqlBuilder.append(columnName).append(" LIKE ? "); whereObjects.add(obj); return this; @@ -561,7 +563,7 @@ public WHERE like(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE notLike(Object obj) { + public WHERE notLike(T obj) { sqlBuilder.append(columnName).append(" NOT LIKE ? "); whereObjects.add(obj); return this; @@ -570,7 +572,7 @@ public WHERE notLike(Object obj) { /** * columnName > ?
*/ - public WHERE biggerThan(Object obj) { + public WHERE biggerThan(T obj) { sqlBuilder.append(columnName).append(" > ? "); whereObjects.add(obj); return this; @@ -579,7 +581,7 @@ public WHERE biggerThan(Object obj) { /** * columnName < ?
*/ - public WHERE smallerThan(Object obj) { + public WHERE smallerThan(T obj) { sqlBuilder.append(columnName).append(" < ? "); whereObjects.add(obj); return this; @@ -588,7 +590,7 @@ public WHERE smallerThan(Object obj) { /** * columnName >= ?
*/ - public WHERE biggerOrEqual(Object obj) { + public WHERE biggerOrEqual(T obj) { sqlBuilder.append(columnName).append(" >= ? "); whereObjects.add(obj); return this; @@ -597,7 +599,7 @@ public WHERE biggerOrEqual(Object obj) { /** * columnName <= ?
*/ - public WHERE smallerOrEqual(Object obj) { + public WHERE smallerOrEqual(T obj) { sqlBuilder.append(columnName).append(" <= ? "); whereObjects.add(obj); return this; @@ -606,7 +608,7 @@ public WHERE smallerOrEqual(Object obj) { /** * columnName BETWEEN ? AND ?
*/ - public WHERE between(Object obj1, Object obj2) { + public WHERE between(T obj1, T obj2) { sqlBuilder.append(columnName).append(" BETWEEN ? AND ? "); whereObjects.add(obj1); whereObjects.add(obj2); @@ -618,7 +620,7 @@ public WHERE between(Object obj1, Object obj2) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE smallestFirst() { + public WHERE smallestFirst() { orderByBuilder.append(columnName + " ASC, "); return this; } @@ -628,7 +630,7 @@ public WHERE smallestFirst() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE biggestFirst() { + public WHERE biggestFirst() { orderByBuilder.append(columnName + " DESC, "); return this; } @@ -638,7 +640,7 @@ public WHERE biggestFirst() { * * @see https://www.w3schools.com/mysql/mysql_limit.asp */ - public WHERE limit(int num) { + public WHERE limit(int num) { limitBuilder.append("LIMIT ").append(num + " "); return this; } diff --git a/src/main/java/com/osiris/jsqlgen/payhook/WebhookEndpoint.java b/src/main/java/com/osiris/jsqlgen/payhook/WebhookEndpoint.java index 176a69c..2b9d82d 100644 --- a/src/main/java/com/osiris/jsqlgen/payhook/WebhookEndpoint.java +++ b/src/main/java/com/osiris/jsqlgen/payhook/WebhookEndpoint.java @@ -18,7 +18,7 @@ NO EXCEPTIONS is enabled which makes it possible to use this methods outside of try/catch blocks because SQL errors will be caught and thrown as runtime exceptions instead.
*/ public class WebhookEndpoint{ -private static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); +public static java.util.concurrent.atomic.AtomicInteger idCounter = new java.util.concurrent.atomic.AtomicInteger(0); static { try{ Connection con = Database.getCon(); @@ -109,11 +109,11 @@ public static WebhookEndpoint get(int id) { if that statement is null, returns all the contents of this table. */ public static List get(String where, Object... whereValues) { -Connection con = Database.getCon(); String sql = "SELECT `id`,`url`,`stripeWebhookSecret`" + " FROM `webhookendpoint`" + (where != null ? where : ""); List list = new ArrayList<>(); +Connection con = Database.getCon(); try (PreparedStatement ps = con.prepareStatement(sql)) { if(where!=null && whereValues!=null) for (int i = 0; i < whereValues.length; i++) { @@ -184,6 +184,8 @@ public static void getLazy(Consumer> onResultReceived, Con }).start(); } +public static int count(){ return count(null, null); } + public static int count(String where, Object... whereValues) { String sql = "SELECT COUNT(`id`) AS recordCount FROM `webhookendpoint`" + (where != null ? where : ""); @@ -207,9 +209,9 @@ Searches the provided object in the database (by its id), @throws Exception when failed to find by id or other SQL issues. */ public static void update(WebhookEndpoint obj) { +String sql = "UPDATE `webhookendpoint` SET `id`=?,`url`=?,`stripeWebhookSecret`=? WHERE id="+obj.id; Connection con = Database.getCon(); -try (PreparedStatement ps = con.prepareStatement( - "UPDATE `webhookendpoint` SET `id`=?,`url`=?,`stripeWebhookSecret`=? WHERE id="+obj.id)) { +try (PreparedStatement ps = con.prepareStatement(sql)) { ps.setInt(1, obj.id); ps.setString(2, obj.url); ps.setString(3, obj.stripeWebhookSecret); @@ -222,9 +224,9 @@ public static void update(WebhookEndpoint obj) { Adds the provided object to the database (note that the id is not checked for duplicates). */ public static void add(WebhookEndpoint obj) { +String sql = "INSERT INTO `webhookendpoint` (`id`,`url`,`stripeWebhookSecret`) VALUES (?,?,?)"; Connection con = Database.getCon(); -try (PreparedStatement ps = con.prepareStatement( - "INSERT INTO `webhookendpoint` (`id`,`url`,`stripeWebhookSecret`) VALUES (?,?,?)")) { +try (PreparedStatement ps = con.prepareStatement(sql)) { ps.setInt(1, obj.id); ps.setString(2, obj.url); ps.setString(3, obj.stripeWebhookSecret); @@ -262,9 +264,9 @@ public static void remove(String where, Object... whereValues) { } public static void removeAll() { - Connection con = Database.getCon(); - try (PreparedStatement ps = con.prepareStatement( - "DELETE FROM `webhookendpoint`")) { +String sql = "DELETE FROM `webhookendpoint`"; +Connection con = Database.getCon(); + try (PreparedStatement ps = con.prepareStatement(sql)) { ps.executeUpdate(); }catch(Exception e){throw new RuntimeException(e);} finally{Database.freeCon(con);} @@ -276,16 +278,16 @@ public WebhookEndpoint clone(){ public String toPrintString(){ return ""+"id="+this.id+" "+"url="+this.url+" "+"stripeWebhookSecret="+this.stripeWebhookSecret+" "; } -public static WHERE whereId() { -return new WHERE("`id`"); +public static WHERE whereId() { +return new WHERE("`id`"); } -public static WHERE whereUrl() { -return new WHERE("`url`"); +public static WHERE whereUrl() { +return new WHERE("`url`"); } -public static WHERE whereStripeWebhookSecret() { -return new WHERE("`stripeWebhookSecret`"); +public static WHERE whereStripeWebhookSecret() { +return new WHERE("`stripeWebhookSecret`"); } -public static class WHERE { +public static class WHERE { /** * Remember to prepend WHERE on the final SQL statement. * This is not done by this class due to performance reasons.

@@ -318,7 +320,7 @@ public List get() { if(!whereObjects.isEmpty()) return WebhookEndpoint.get(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return WebhookEndpoint.get(where+orderBy+limitBuilder.toString(), (Object[]) null); + return WebhookEndpoint.get(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -333,7 +335,7 @@ public int count() { if(!whereObjects.isEmpty()) return WebhookEndpoint.count(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - return WebhookEndpoint.count(where+orderBy+limitBuilder.toString(), (Object[]) null); + return WebhookEndpoint.count(where+orderBy+limitBuilder.toString(), (T[]) null); } /** @@ -348,13 +350,13 @@ public void remove() { if(!whereObjects.isEmpty()) WebhookEndpoint.remove(where+orderBy+limitBuilder.toString(), whereObjects.toArray()); else - WebhookEndpoint.remove(where+orderBy+limitBuilder.toString(), (Object[]) null); + WebhookEndpoint.remove(where+orderBy+limitBuilder.toString(), (T[]) null); } /** * AND (...)
*/ - public WHERE and(WHERE where) { + public WHERE and(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("AND (").append(sql).append(") "); @@ -367,7 +369,7 @@ public WHERE and(WHERE where) { /** * OR (...)
*/ - public WHERE or(WHERE where) { + public WHERE or(WHERE where) { String sql = where.sqlBuilder.toString(); if(!sql.isEmpty()) { sqlBuilder.append("OR (").append(sql).append(") "); @@ -380,7 +382,7 @@ public WHERE or(WHERE where) { /** * columnName = ?
*/ - public WHERE is(Object obj) { + public WHERE is(T obj) { sqlBuilder.append(columnName).append(" = ? "); whereObjects.add(obj); return this; @@ -391,9 +393,9 @@ public WHERE is(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_in.asp */ - public WHERE is(Object... objects) { + public WHERE is(T... objects) { String s = ""; - for (Object obj : objects) { + for (T obj : objects) { s += "?,"; whereObjects.add(obj); } @@ -405,7 +407,7 @@ public WHERE is(Object... objects) { /** * columnName <> ?
*/ - public WHERE isNot(Object obj) { + public WHERE isNot(T obj) { sqlBuilder.append(columnName).append(" <> ? "); whereObjects.add(obj); return this; @@ -414,7 +416,7 @@ public WHERE isNot(Object obj) { /** * columnName IS NULL
*/ - public WHERE isNull() { + public WHERE isNull() { sqlBuilder.append(columnName).append(" IS NULL "); return this; } @@ -422,7 +424,7 @@ public WHERE isNull() { /** * columnName IS NOT NULL
*/ - public WHERE isNotNull() { + public WHERE isNotNull() { sqlBuilder.append(columnName).append(" IS NOT NULL "); return this; } @@ -432,7 +434,7 @@ public WHERE isNotNull() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE like(Object obj) { + public WHERE like(T obj) { sqlBuilder.append(columnName).append(" LIKE ? "); whereObjects.add(obj); return this; @@ -443,7 +445,7 @@ public WHERE like(Object obj) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE notLike(Object obj) { + public WHERE notLike(T obj) { sqlBuilder.append(columnName).append(" NOT LIKE ? "); whereObjects.add(obj); return this; @@ -452,7 +454,7 @@ public WHERE notLike(Object obj) { /** * columnName > ?
*/ - public WHERE biggerThan(Object obj) { + public WHERE biggerThan(T obj) { sqlBuilder.append(columnName).append(" > ? "); whereObjects.add(obj); return this; @@ -461,7 +463,7 @@ public WHERE biggerThan(Object obj) { /** * columnName < ?
*/ - public WHERE smallerThan(Object obj) { + public WHERE smallerThan(T obj) { sqlBuilder.append(columnName).append(" < ? "); whereObjects.add(obj); return this; @@ -470,7 +472,7 @@ public WHERE smallerThan(Object obj) { /** * columnName >= ?
*/ - public WHERE biggerOrEqual(Object obj) { + public WHERE biggerOrEqual(T obj) { sqlBuilder.append(columnName).append(" >= ? "); whereObjects.add(obj); return this; @@ -479,7 +481,7 @@ public WHERE biggerOrEqual(Object obj) { /** * columnName <= ?
*/ - public WHERE smallerOrEqual(Object obj) { + public WHERE smallerOrEqual(T obj) { sqlBuilder.append(columnName).append(" <= ? "); whereObjects.add(obj); return this; @@ -488,7 +490,7 @@ public WHERE smallerOrEqual(Object obj) { /** * columnName BETWEEN ? AND ?
*/ - public WHERE between(Object obj1, Object obj2) { + public WHERE between(T obj1, T obj2) { sqlBuilder.append(columnName).append(" BETWEEN ? AND ? "); whereObjects.add(obj1); whereObjects.add(obj2); @@ -500,7 +502,7 @@ public WHERE between(Object obj1, Object obj2) { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE smallestFirst() { + public WHERE smallestFirst() { orderByBuilder.append(columnName + " ASC, "); return this; } @@ -510,7 +512,7 @@ public WHERE smallestFirst() { * * @see https://www.w3schools.com/mysql/mysql_like.asp */ - public WHERE biggestFirst() { + public WHERE biggestFirst() { orderByBuilder.append(columnName + " DESC, "); return this; } @@ -520,7 +522,7 @@ public WHERE biggestFirst() { * * @see https://www.w3schools.com/mysql/mysql_limit.asp */ - public WHERE limit(int num) { + public WHERE limit(int num) { limitBuilder.append("LIMIT ").append(num + " "); return this; } diff --git a/src/main/java/com/osiris/payhook/PayHook.java b/src/main/java/com/osiris/payhook/PayHook.java index aa7d56e..6c01ea2 100644 --- a/src/main/java/com/osiris/payhook/PayHook.java +++ b/src/main/java/com/osiris/payhook/PayHook.java @@ -972,7 +972,7 @@ public static void receiveWebhookEvent(PaymentProcessor paymentProcessor, Map payments = Payment.whereId().is(paymentId).get(); + List payments = Payment.whereId().is(Integer.valueOf(paymentId)).get(); if (payments.isEmpty()) throw new WebHookValidationException( "Received invalid webhook event (" + PaymentProcessor.PAYPAL + ", failed to find payment with id '" + paymentId + "' in local database)."); Payment firstPayment = payments.get(0); @@ -1043,7 +1043,7 @@ public static void receiveWebhookEvent(PaymentProcessor paymentProcessor, Map payments = Payment.whereId().is(paymentId).get(); + List payments = Payment.whereId().is(Integer.valueOf(paymentId)).get(); if (payments.isEmpty()) throw new WebHookValidationException( "Received invalid webhook event (" + PaymentProcessor.PAYPAL + ", failed to find payment with id '" + paymentId + "' in local database)."); Payment firstPayment = payments.get(0);