From 8bae5fd4f98555699864ab9defb4c072846c42df Mon Sep 17 00:00:00 2001 From: Presti Date: Tue, 22 Oct 2024 13:52:23 +0200 Subject: [PATCH] Deprecated methods are now removed. --- .../java/de/presti/ree6/sql/SQLConnector.java | 112 ------------------ .../java/de/presti/ree6/sql/SQLWorker.java | 72 ----------- src/test/java/Main.java | 4 +- 3 files changed, 2 insertions(+), 186 deletions(-) diff --git a/src/main/java/de/presti/ree6/sql/SQLConnector.java b/src/main/java/de/presti/ree6/sql/SQLConnector.java index 432f72a..5566c5d 100644 --- a/src/main/java/de/presti/ree6/sql/SQLConnector.java +++ b/src/main/java/de/presti/ree6/sql/SQLConnector.java @@ -143,118 +143,6 @@ public void runMigrations() { //region Utility - /** - * Query basic SQL Statements, without using the ORM-System. - * - * @param sqlQuery The SQL Query. - * @param ignoreError If errors should not be printed into the console. - * @param parameters The Parameters for the Query. - * @return Either a {@link Integer} or the result object of the ResultSet. - * @deprecated Use {@link #query(String, Map)} instead. - */ - @Deprecated(forRemoval = true) - public Object querySQL(String sqlQuery, boolean ignoreError, Object... parameters) { - return querySQL(sqlQuery, !sqlQuery.startsWith("SELECT"), ignoreError, parameters); - } - - /** - * Query basic SQL Statements, without using the ORM-System. - * - * @param sqlQuery The SQL Query. - * @param update If a executeUpdate should be used. - * @param ignoreError If errors should not be printed into the console. - * @param parameters The Parameters for the Query. - * @return Either a {@link Integer} or the result object of the ResultSet. - * @deprecated Use {@link #query(String, Map)} instead. - */ - @Deprecated(forRemoval = true) - public Object querySQL(String sqlQuery, boolean update, boolean ignoreError, Object... parameters) { - if (!isConnected()) { - if (connectedOnce()) { - connectToSQLServer(); - return querySQL(sqlQuery, update, parameters); - } else { - return null; - } - } - - try (Connection connection = getDataSource().getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery, ResultSet.CONCUR_READ_ONLY)) { - - if (parameters != null) { - for (int i = 0; i < parameters.length; i++) { - Object parameter = parameters[i]; - if (parameter == null) continue; - - preparedStatement.setObject(i + 1, parameter); - } - } - - if (update) { - return preparedStatement.executeUpdate(); - } else { - try (ResultSet resultSet = preparedStatement.executeQuery()) { - if (resultSet.next()) { - return resultSet; - } - - return null; - } - } - } catch (Exception exception) { - if (!ignoreError) { - Sentry.captureException(exception); - log.error("Failed to send SQL-Query: {}", sqlQuery, exception); - } - } - - return null; - } - - /** - * Send an SQL-Query to SQL-Server and get the response. - * - * @param The Class entity. - * @param r The class entity. - * @param sqlQuery the SQL-Query. - * @param parameters a list with all parameters that should be considered. - * @return The Result from the SQL-Server. - * @deprecated Use {@link #query(String, Map)} instead. - */ - @Deprecated(forRemoval = true) - public Query querySQL(@NotNull R r, @NotNull String sqlQuery, @Nullable Map parameters) { - - if (!isConnected()) { - if (connectedOnce()) { - connectToSQLServer(); - return querySQL(r, sqlQuery, parameters); - } else { - return null; - } - } - - try (Session session = SQLSession.getSessionFactory().openSession()) { - - session.beginTransaction(); - - Query query = (Query) session.createNativeQuery(sqlQuery, r.getClass()); - - if (parameters != null) { - for (Map.Entry entry : parameters.entrySet()) { - query.setParameter(entry.getKey(), entry.getValue()); - } - } - - session.getTransaction().commit(); - - return query; - } catch (Exception exception) { - Sentry.captureException(exception); - log.error("Failed to send SQL-Query: {}", sqlQuery, exception); - throw exception; - } - } - /** * Query HQL-Statements without the need of a class Instance. * diff --git a/src/main/java/de/presti/ree6/sql/SQLWorker.java b/src/main/java/de/presti/ree6/sql/SQLWorker.java index 6d58524..961f8de 100644 --- a/src/main/java/de/presti/ree6/sql/SQLWorker.java +++ b/src/main/java/de/presti/ree6/sql/SQLWorker.java @@ -1816,52 +1816,6 @@ public Mono hasSetting(long guildId, String settingName) { return getEntity(new Setting(), "FROM Setting WHERE settingId.guildId =:gid AND settingId.name =:name", Map.of("gid", guildId, "name", settingName)).map(Optional::isPresent); } - /** - * Check if there is an entry for the Setting, if not, create one for every Setting that doesn't have an entry. - * - * @param guildId the ID of the Guild. - * @param setting the Setting itself. - * @deprecated This will loop through every setting and sets them every single time a config is being received. - */ - @Deprecated(forRemoval = true, since = "3.0.0") - public void checkSetting(long guildId, Setting setting) { - checkSetting(guildId, setting.getName()); - } - - /** - * Check if there is an entry for the Setting, if not, create one for every Setting that doesn't have an entry. - * - * @param guildId the ID of the Guild. - * @param settingName the Identifier of the Setting. - * @deprecated This will loop through every setting and sets them every single time a config is being received. - */ - @Deprecated(forRemoval = true, since = "3.0.0") - public void checkSetting(long guildId, String settingName) { - // Check if the Setting exists in our Database. - hasSetting(guildId, settingName).subscribe(hasSetting -> { - // If not then creat every Setting that doesn't exist for the Guild. - if (!hasSetting) { - createSettings(guildId); - } - }); - } - - /** - * Create Settings entries for the Guild - * - * @param guildId the ID of the Guild. - * @deprecated This will loop through every setting and sets them every single time a config is being received. - */ - @Deprecated(forRemoval = true, since = "3.0.0") - public void createSettings(long guildId) { - SettingsManager.getSettings().forEach(setting -> hasSetting(guildId, setting).subscribe(hasSetting -> { - // If not, then create every Setting that doesn't exist for the Guild. - if (!hasSetting) { - setSetting(guildId, setting.getName(), setting.getDisplayName(), setting.getValue()); - } - })); - } - /** * Create Settings entries for the commands on the Guild * @@ -2232,20 +2186,6 @@ private String getHibernateQueryForId(Field[] fields) { //region Entity-System - - /** - * Update an Entity in the Database. - * - * @param The Class-Entity. - * @param r The Class-Entity to update. - * @return the new update entity. - * @deprecated This method is only here to make it easier to find methods that need to be updated. - */ - @Deprecated(forRemoval = true, since = "3.0.0") - public Mono updateEntity(Optional r) { - return r.map(this::updateEntity).orElseGet(Mono::empty); - } - /** * Update an Entity in the Database. * @@ -2324,18 +2264,6 @@ private long getNextId(R r) { return maxId + 1; } - /** - * Delete an entity from the database - * - * @param The Class-Entity. - * @param r The Class-Entity to delete. - * @deprecated This method is only here to make it easier to find methods that need to be updated. - */ - @Deprecated(forRemoval = true, since = "3.0.0") - public Mono deleteEntity(Optional r) { - return r.map(this::deleteEntity).orElse(Mono.empty()); - } - /** * Delete an entity from the database * diff --git a/src/test/java/Main.java b/src/test/java/Main.java index 4745bca..866960f 100644 --- a/src/test/java/Main.java +++ b/src/test/java/Main.java @@ -25,13 +25,13 @@ public static void main(String[] args) throws SQLException { new SQLSession(sqlConfig); - if (sqlConfig.getTyp() == DatabaseTyp.SQLite) { + /*if (sqlConfig.getTyp() == DatabaseTyp.SQLite) { SQLSession.getSqlConnector().querySQL("PRAGMA foreign_keys = ON;", true, (Object[]) null); if (SQLSession.getSqlConnector().querySQL("PRAGMA foreign_keys;", false, (Object[]) null) instanceof ResultSet resultSet) { System.out.println(resultSet.getBoolean(1)); } - } + }*/ WebhookYouTube hook = new WebhookYouTube(-1, "test", "test", -1, -1, "test"); SQLSession.getSqlConnector().getSqlWorker().updateEntity(hook).block();