Skip to content

Commit

Permalink
Deprecated methods are now removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Oct 22, 2024
1 parent e16ea00 commit 8bae5fd
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 186 deletions.
112 changes: 0 additions & 112 deletions src/main/java/de/presti/ree6/sql/SQLConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <R> 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 <R> Query<R> querySQL(@NotNull R r, @NotNull String sqlQuery, @Nullable Map<String, Object> parameters) {

if (!isConnected()) {
if (connectedOnce()) {
connectToSQLServer();
return querySQL(r, sqlQuery, parameters);
} else {
return null;
}
}

try (Session session = SQLSession.getSessionFactory().openSession()) {

session.beginTransaction();

Query<R> query = (Query<R>) session.createNativeQuery(sqlQuery, r.getClass());

if (parameters != null) {
for (Map.Entry<String, Object> 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.
*
Expand Down
72 changes: 0 additions & 72 deletions src/main/java/de/presti/ree6/sql/SQLWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1816,52 +1816,6 @@ public Mono<Boolean> 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
*
Expand Down Expand Up @@ -2232,20 +2186,6 @@ private String getHibernateQueryForId(Field[] fields) {

//region Entity-System


/**
* Update an Entity in the Database.
*
* @param <R> 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 <R> Mono<R> updateEntity(Optional<R> r) {
return r.map(this::updateEntity).orElseGet(Mono::empty);
}

/**
* Update an Entity in the Database.
*
Expand Down Expand Up @@ -2324,18 +2264,6 @@ private <R> long getNextId(R r) {
return maxId + 1;
}

/**
* Delete an entity from the database
*
* @param <R> 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 <R> Mono<Void> deleteEntity(Optional<R> r) {
return r.map(this::deleteEntity).orElse(Mono.empty());
}

/**
* Delete an entity from the database
*
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8bae5fd

Please sign in to comment.