From 62d320e13d8ba46b4e1a89971174e4bbd899df34 Mon Sep 17 00:00:00 2001 From: ghost2173 <69243988+ghost2173@users.noreply.github.com> Date: Mon, 1 Aug 2022 20:53:02 +0300 Subject: [PATCH 1/2] i hate @slowcheet4h have this shitty formating i hate that you ignore important exceptions fuck you --- .../yystal/sql/YDatabaseClient.java | 83 +++++++++---------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/pisi/unitedmeows/yystal/sql/YDatabaseClient.java b/pisi/unitedmeows/yystal/sql/YDatabaseClient.java index 43144dc..9d32f1c 100644 --- a/pisi/unitedmeows/yystal/sql/YDatabaseClient.java +++ b/pisi/unitedmeows/yystal/sql/YDatabaseClient.java @@ -1,19 +1,22 @@ package pisi.unitedmeows.yystal.sql; -import pisi.unitedmeows.yystal.utils.IDisposable; - -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -public class YDatabaseClient implements IDisposable { +import pisi.unitedmeows.yystal.utils.IDisposable; +public class YDatabaseClient implements IDisposable { private boolean connected; private Connection connection; private final java.lang.Object actionLock = new java.lang.Object(); - private HashMap> tableColumnsCache; + private HashMap> tableColumnsCache; public YDatabaseClient(String username, String password, String database, String host, int port) { try { @@ -22,10 +25,11 @@ public YDatabaseClient(String username, String password, String database, String connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?characterEncoding=latin1&useConfigs=maxPerformance", username, password); connected = true; } - tableColumnsCache = new HashMap<>(); + tableColumnsCache = new HashMap<>(); } catch (Exception ex) { connected = false; + ex.printStackTrace(); } } @@ -57,37 +61,26 @@ public List> select(YSQLCommand sql, String... columnNames) return select(sql.getHooked(), columnNames); } - public List dbColumnsNoCache(String table) { - synchronized (actionLock) { - List> select = select( - new YSQLCommand( - "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=^").putString(table), - "TABLE_CATALOG", - "TABLE_SCHEMA", - "TABLE_NAME", - "COLUMN_NAME" - ); - - List columns = new ArrayList<>(); - - for (int i = 0; i < select.size(); i++) { - columns.add((String) select.get(i).get("COLUMN_NAME")); - } - - return columns; - } - } - - public List dbColumns(String table) { - List columns = tableColumnsCache.getOrDefault(table, null); - - if (columns == null) { - tableColumnsCache.put(table, dbColumnsNoCache(table)); - return columns; - } + public List dbColumnsNoCache(String table) { + synchronized (actionLock) { + List> select = select(new YSQLCommand("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=^").putString(table), "TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME", + "COLUMN_NAME"); + List columns = new ArrayList<>(); + for (int i = 0; i < select.size(); i++) { + columns.add((String) select.get(i).get("COLUMN_NAME")); + } + return columns; + } + } - return tableColumnsCache.get(table); - } + public List dbColumns(String table) { + List columns = tableColumnsCache.getOrDefault(table, null); + if (columns == null) { + tableColumnsCache.put(table, dbColumnsNoCache(table)); + return columns; + } + return tableColumnsCache.get(table); + } public List> select(String sql) { synchronized (actionLock) { @@ -142,15 +135,15 @@ public Connection connection() { return connection; } - @Override - public void close() { - try { - connection.close(); - } catch (Exception ex) {} - connected = false; - tableColumnsCache.clear(); - } - + @Override + public void close() { + try { + connection.close(); + } + catch (Exception ex) {} + connected = false; + tableColumnsCache.clear(); + } /* public boolean insertMulti(String tableName, List> dataList, String... columns) { String sql = "INSERT INTO " + tableName + "(" + String.join(",", columns) + " VALUES "; From 02c911956743573c9abdf2f17576e5f23a548284 Mon Sep 17 00:00:00 2001 From: ghost2173 <69243988+ghost2173@users.noreply.github.com> Date: Mon, 1 Aug 2022 20:53:33 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index abbd58d..cdb8068 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ After that you can add: com.github.unitedmeows yystal - 1.1.5 + 1.1.6 ``` to your pom.xml.