Skip to content

Commit

Permalink
Remove problematic Q2O calls :/
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed May 23, 2024
1 parent b091558 commit 9952645
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SqLiteDataHandler(@NotNull File claimChunkDb) {
public void init() {
joinedPlayers = new HashMap<>();
claimedChunks = new HashMap<>();
sqLiteWrapper = new SqLiteWrapper(claimChunkDb);
sqLiteWrapper = new SqLiteWrapper(claimChunkDb, false);

init = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.cjburkey.claimchunk.data.sqlite;

import com.zaxxer.q2o.Q2Sql;
import com.zaxxer.q2o.SqlClosure;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/** This class is responsible for creating, loading, and upgrading the database file. */
public class SqLiteTableMigrationManager {
Expand Down Expand Up @@ -63,18 +62,21 @@ FOREIGN KEY(other_player_uuid) REFERENCES player_data(player_uuid)
// Use this method to determine if a column exists in a table to perform migrations
// TODO: MAYBE CHECK IF THIS WORKS
@SuppressWarnings("unused")
private static boolean columnExists(Connection connection, String tableName, String columnName)
throws SQLException {
PreparedStatement statement =
connection.prepareCall(
"""
SELECT COUNT(*) FROM pragma_table_info(?) WHERE name=?
""");
statement.setString(1, tableName);
statement.setString(2, columnName);
ResultSet resultSet = statement.executeQuery();
int count = resultSet.next() ? resultSet.getInt(1) : 0;
return count > 0;
public static boolean columnExists(String tableName, String columnName) {
return SqlClosure.sqlExecute(
connection -> {
try (PreparedStatement statement =
connection.prepareStatement(
"""
SELECT COUNT(*) FROM pragma_table_info(?) WHERE name=?
""")) {
statement.setString(1, tableName);
statement.setString(2, columnName);
ResultSet resultSet = statement.executeQuery();
int count = resultSet.next() ? resultSet.getInt(1) : 0;
return count > 0;
}
});
}

// Whenever a column is added or moved or transformed or whatever, add a
Expand Down
Loading

0 comments on commit 9952645

Please sign in to comment.