Skip to content

Commit

Permalink
fix: temp. commented DB code to allow plugin to build
Browse files Browse the repository at this point in the history
uncomment if DB is required later
  • Loading branch information
rooooose-b committed Jan 21, 2024
1 parent 39f11ac commit 531a2b7
Showing 3 changed files with 64 additions and 96 deletions.
128 changes: 64 additions & 64 deletions src/main/java/io/github/Alathra/AlathraSkills/db/DatabaseQueries.java
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
import java.sql.SQLException;
import java.util.UUID;

import static io.github.ExampleUser.ExamplePlugin.db.schema.Tables.SOME_LIST;
//import static io.github.Alathra.AlathraSkills.db.schema.Tables.SOME_LIST;

/**
* A holder class for all SQL queries
@@ -24,80 +24,80 @@ public abstract class DatabaseQueries {
* <p>
* This method actually is an upsert and inserts or updates entries dependent on whether a duplicate row exists.
*/
public static void addEntry() {
try (
Connection con = DB.getConnection()
) {
DSLContext context = DB.getContext(con);

context
.insertInto(SOME_LIST)
.set(SOME_LIST.UUID, DatabaseQueries.convertUUIDToBytes(UUID.randomUUID()))
.set(SOME_LIST.NAME, "testname")
.onDuplicateKeyUpdate()
.set(SOME_LIST.NAME, "testname")
.execute();
} catch (SQLException e) {
Logger.get().error("SQL Query threw an error!", e);
}
}
// public static void addEntry() {
// try (
// Connection con = DB.getConnection()
// ) {
// DSLContext context = DB.getContext(con);
//
// context
// .insertInto(SOME_LIST)
// .set(SOME_LIST.UUID, DatabaseQueries.convertUUIDToBytes(UUID.randomUUID()))
// .set(SOME_LIST.NAME, "testname")
// .onDuplicateKeyUpdate()
// .set(SOME_LIST.NAME, "testname")
// .execute();
// } catch (SQLException e) {
// Logger.get().error("SQL Query threw an error!", e);
// }
// }

/**
* Example save all data to database.
* <p>
* This method actually is an upsert and inserts or updates entries dependent on whether a duplicate row exists.
*/
public static void saveAll() {
try (
@NotNull Connection con = DB.getConnection();
) {
DSLContext context = DB.getContext(con);

context
.insertInto(SOME_LIST)
.set(SOME_LIST.UUID, DatabaseQueries.convertUUIDToBytes(UUID.randomUUID()))
.set(SOME_LIST.NAME, "testname")
.onDuplicateKeyUpdate()
.set(SOME_LIST.NAME, "testname")
.execute();
} catch (SQLException e) {
Logger.get().error("SQL Query threw an error!", e);
}
}
// public static void saveAll() {
// try (
// @NotNull Connection con = DB.getConnection();
// ) {
// DSLContext context = DB.getContext(con);
//
// context
// .insertInto(SOME_LIST)
// .set(SOME_LIST.UUID, DatabaseQueries.convertUUIDToBytes(UUID.randomUUID()))
// .set(SOME_LIST.NAME, "testname")
// .onDuplicateKeyUpdate()
// .set(SOME_LIST.NAME, "testname")
// .execute();
// } catch (SQLException e) {
// Logger.get().error("SQL Query threw an error!", e);
// }
// }

/**
* Example load all data from database.
* <p>
* You should make this method return whatever it is you're grabbing from db.
*
*/
public static @Nullable Result<Record2<String, byte[]>> loadAll() {
try (
Connection con = DB.getConnection();
) {
DSLContext context = DB.getContext(con);

return context
.select(SOME_LIST.NAME, SOME_LIST.UUID)
.from(SOME_LIST)
.fetch();
} catch (SQLException e) {
Logger.get().error("SQL Query threw an error!", e);
}
return null;
}

public static byte[] convertUUIDToBytes(UUID uuid) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}

public static UUID convertBytesToUUID(byte[] bytes) {
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
long high = byteBuffer.getLong();
long low = byteBuffer.getLong();
return new UUID(high, low);
}
// public static @Nullable Result<Record2<String, byte[]>> loadAll() {
// try (
// Connection con = DB.getConnection();
// ) {
// DSLContext context = DB.getContext(con);
//
// return context
// .select(SOME_LIST.NAME, SOME_LIST.UUID)
// .from(SOME_LIST)
// .fetch();
// } catch (SQLException e) {
// Logger.get().error("SQL Query threw an error!", e);
// }
// return null;
// }
//
// public static byte[] convertUUIDToBytes(UUID uuid) {
// ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
// bb.putLong(uuid.getMostSignificantBits());
// bb.putLong(uuid.getLeastSignificantBits());
// return bb.array();
// }
//
// public static UUID convertBytesToUUID(byte[] bytes) {
// ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
// long high = byteBuffer.getLong();
// long low = byteBuffer.getLong();
// return new UUID(high, low);
// }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.Alathra.AlathraSkills.db.flyway;

import io.github.Alathra.AlathraSkills.db.DatabaseType;
import io.github.Alathra.AlathraSkills.db.flyway.migration.V3__Example;
import com.github.milkdrinkers.Crate.Config;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.ClassProvider;
@@ -18,7 +17,6 @@
public class DatabaseMigrationHandler {
// List of Java migrations
private final List<Class<? extends JavaMigration>> migrations = List.of(
V3__Example.class
);

private final Config config;

This file was deleted.

0 comments on commit 531a2b7

Please sign in to comment.