simplify database handling across sql flavors (#279)

This commit is contained in:
Jason authored and GitHub committed 2023-08-22 19:44:09 -07:00
1 parent dbd01c52da
commit 7ed005afeb
33 files changed
+188 -210

No files matched your search

@@ -36,6 +36,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.statement.PreparedBatch; import org.jdbi.v3.core.statement.PreparedBatch;
import org.jdbi.v3.core.statement.Update;
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
public abstract class DatabaseUserManager extends CachingUserManager { public abstract class DatabaseUserManager extends CachingUserManager {
@@ -69,16 +70,10 @@ public abstract class DatabaseUserManager extends CachingUserManager {
@Override @Override
public final void saveSync(final CarbonPlayerCommon player) { public final void saveSync(final CarbonPlayerCommon player) {
this.jdbi.useTransaction(handle -> { this.jdbi.useTransaction(handle -> {
handle.createUpdate(this.locator.query("insert-player")) final int inserted = bindPlayerArguments(handle.createUpdate(this.locator.query("insert-player")), player).execute();
.bind("id", player.uuid()) if (inserted != 1) {
.bind("muted", player.muted()) bindPlayerArguments(handle.createUpdate(this.locator.query("update-player")), player).execute();
.bind("deafened", player.deafened()) }
.bind("selectedchannel", player.selectedChannelKey())
.bind("displayname", player.displayNameRaw())
.bind("lastwhispertarget", player.lastWhisperTarget())
.bind("whisperreplytarget", player.whisperReplyTarget())
.bind("spying", player.spying())
.execute();
handle.createUpdate(this.locator.query("clear-ignores")) handle.createUpdate(this.locator.query("clear-ignores"))
.bind("id", player.uuid()) .bind("id", player.uuid())
@@ -104,9 +99,18 @@ public abstract class DatabaseUserManager extends CachingUserManager {
} }
batch.execute(); batch.execute();
} }
handle.commit();
}); });
} }
private static Update bindPlayerArguments(final Update update, final CarbonPlayerCommon player) {
return update.bind("id", player.uuid())
.bind("muted", player.muted())
.bind("deafened", player.deafened())
.bind("selectedchannel", player.selectedChannelKey())
.bind("displayname", player.displayNameRaw())
.bind("lastwhispertarget", player.lastWhisperTarget())
.bind("whisperreplytarget", player.whisperReplyTarget())
.bind("spying", player.spying());
}
} }
@@ -28,20 +28,19 @@ import org.jdbi.v3.core.locator.internal.ClasspathBuilder;
public final class QueriesLocator { public final class QueriesLocator {
private static final String PREFIX = "queries/";
private static final Splitter SPLITTER = Splitter.on(';'); private static final Splitter SPLITTER = Splitter.on(';');
private final ClasspathSqlLocator locator = ClasspathSqlLocator.create(); private final ClasspathSqlLocator locator = ClasspathSqlLocator.create();
private final DBType dbType;
public QueriesLocator(final DBType dbType) { public QueriesLocator() {
this.dbType = dbType;
} }
public @NonNull String query(final @NonNull String name) { public @NonNull String query(final @NonNull String name) {
return this.locate(this.dbType.basePath() + name); return this.locate(PREFIX + name);
} }
public @NonNull List<@NonNull String> queries(final @NonNull String name) { public @NonNull List<@NonNull String> queries(final @NonNull String name) {
return SPLITTER.splitToList(this.locator.locate(this.dbType.basePath() + name)); return SPLITTER.splitToList(this.locator.locate(PREFIX + name));
} }
private String locate(final String name) { private String locate(final String name) {
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.draycia.carbon.common.users.db.mysql; package net.draycia.carbon.common.users.db.argument;
import java.sql.Types; import java.sql.Types;
import java.util.UUID; import java.util.UUID;
@@ -25,16 +25,25 @@ import org.jdbi.v3.core.argument.AbstractArgumentFactory;
import org.jdbi.v3.core.argument.Argument; import org.jdbi.v3.core.argument.Argument;
import org.jdbi.v3.core.config.ConfigRegistry; import org.jdbi.v3.core.config.ConfigRegistry;
// https://github.com/broccolai/tickets/blob/55a23b5fcfdc8e4b4bfa861ea7ec620506bd0dfa/core/src/main/java/broccolai/tickets/core/storage/factory/UUIDArgumentFactory.java public final class BinaryUUIDArgumentFactory extends AbstractArgumentFactory<UUID> {
public final class MySQLUUIDArgumentFactory extends AbstractArgumentFactory<UUID> {
public MySQLUUIDArgumentFactory() { public BinaryUUIDArgumentFactory() {
super(Types.VARCHAR); super(Types.BINARY); // BINARY(16)
} }
@Override @Override
public Argument build(final UUID value, final ConfigRegistry config) { public Argument build(final UUID value, final ConfigRegistry config) {
return (position, statement, ctx) -> statement.setString(position, value.toString()); return (position, statement, ctx) -> statement.setBytes(position, unhex(value.toString().replace("-", "")));
}
private static byte[] unhex(final String s) {
final int len = s.length();
final byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i + 1), 16));
}
return data;
} }
} }
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.draycia.carbon.common.users.db; package net.draycia.carbon.common.users.db.argument;
import java.sql.Types; import java.sql.Types;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@@ -28,15 +28,13 @@ import org.jdbi.v3.core.config.ConfigRegistry;
public final class ComponentArgumentFactory extends AbstractArgumentFactory<Component> { public final class ComponentArgumentFactory extends AbstractArgumentFactory<Component> {
final GsonComponentSerializer serializer = GsonComponentSerializer.gson();
public ComponentArgumentFactory() { public ComponentArgumentFactory() {
super(Types.VARCHAR); super(Types.VARCHAR);
} }
@Override @Override
public Argument build(final Component value, final ConfigRegistry config) { public Argument build(final Component value, final ConfigRegistry config) {
return (position, statement, ctx) -> statement.setString(position, this.serializer.serialize(value)); return (position, statement, ctx) -> statement.setString(position, GsonComponentSerializer.gson().serialize(value));
} }
} }
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.draycia.carbon.common.users.db; package net.draycia.carbon.common.users.db.argument;
import java.sql.Types; import java.sql.Types;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
@@ -0,0 +1,44 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.common.users.db.mapper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import net.draycia.carbon.common.util.FastUuidSansHyphens;
import net.draycia.carbon.common.util.Strings;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext;
public final class BinaryUUIDColumnMapper implements ColumnMapper<UUID> {
@Override
public UUID map(final ResultSet rs, final int columnNumber, final StatementContext ctx) throws SQLException {
final byte @Nullable [] bytes = rs.getBytes(columnNumber);
if (bytes != null) {
return FastUuidSansHyphens.parseUuid(Strings.asHexString(bytes));
}
return null;
}
}
@@ -0,0 +1,37 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.common.users.db.mapper;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.draycia.carbon.common.util.Strings;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext;
public final class ComponentColumnMapper implements ColumnMapper<Component> {
@Override
public Component map(final ResultSet rs, final int columnNumber, final StatementContext ctx) throws SQLException {
return GsonComponentSerializer.gson().deserializeOrNull(Strings.trim(rs.getString(columnNumber)));
}
}
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.draycia.carbon.common.users.db; package net.draycia.carbon.common.users.db.mapper;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@@ -28,7 +28,7 @@ import org.intellij.lang.annotations.Subst;
import org.jdbi.v3.core.mapper.ColumnMapper; import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext; import org.jdbi.v3.core.statement.StatementContext;
public class KeyColumnMapper implements ColumnMapper<Key> { public final class KeyColumnMapper implements ColumnMapper<Key> {
@Override @Override
public Key map(final ResultSet rs, final int columnNumber, final StatementContext ctx) throws SQLException { public Key map(final ResultSet rs, final int columnNumber, final StatementContext ctx) throws SQLException {
@@ -17,21 +17,20 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.draycia.carbon.common.users.db; package net.draycia.carbon.common.users.db.mapper;
public final class DBType { import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext;
private final String basePath; // todo: I'm not entirely sure that this is necessary, but I don't feel like testing PSQL
public final class NativeUUIDColumnMapper implements ColumnMapper<UUID> {
private DBType(final String basePath) { @Override
this.basePath = basePath; public UUID map(final ResultSet rs, final int columnNumber, final StatementContext ctx) throws SQLException {
return rs.getObject(columnNumber, UUID.class);
} }
public String basePath() {
return this.basePath;
}
public static final DBType MYSQL = new DBType("queries/mysql/");
public static final DBType POSTGRESQL = new DBType("queries/postgresql/");
} }
@@ -17,36 +17,32 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package net.draycia.carbon.common.users.db.postgresql; package net.draycia.carbon.common.users.db.mapper;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
import net.draycia.carbon.common.users.CarbonPlayerCommon; import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.util.Strings;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.jdbi.v3.core.mapper.ColumnMapper;
import org.intellij.lang.annotations.Subst;
import org.jdbi.v3.core.mapper.RowMapper; import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.statement.StatementContext; import org.jdbi.v3.core.statement.StatementContext;
public class PostgreSQLPlayerRowMapper implements RowMapper<CarbonPlayerCommon> { public final class PlayerRowMapper implements RowMapper<CarbonPlayerCommon> {
@Override @Override
public CarbonPlayerCommon map(final ResultSet rs, final StatementContext ctx) throws SQLException { public CarbonPlayerCommon map(final ResultSet rs, final StatementContext ctx) throws SQLException {
final @Nullable @Subst("carbon:global") String selectedChannel = Strings.trim(rs.getString("selectedchannel")); final ColumnMapper<UUID> uuid = ctx.findColumnMapperFor(UUID.class).orElseThrow();
final @Nullable String displayName = Strings.trim(rs.getString("displayname"));
return new CarbonPlayerCommon( return new CarbonPlayerCommon(
rs.getBoolean("muted"), rs.getBoolean("muted"),
rs.getBoolean("deafened"), rs.getBoolean("deafened"),
selectedChannel == null ? null : Key.key(selectedChannel), ctx.findColumnMapperFor(Key.class).orElseThrow().map(rs, "selectedchannel", ctx),
null, null,
rs.getObject("id", UUID.class), uuid.map(rs, "id", ctx),
displayName == null ? null : GsonComponentSerializer.gson().deserialize(displayName), ctx.findColumnMapperFor(Component.class).orElseThrow().map(rs, "displayname", ctx),
rs.getObject("lastwhispertarget", UUID.class), uuid.map(rs, "lastwhispertarget", ctx),
rs.getObject("whisperreplytarget", UUID.class), uuid.map(rs, "whisperreplytarget", ctx),
rs.getBoolean("spying") rs.getBoolean("spying")
); );
} }
@@ -1,57 +0,0 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.common.users.db.mysql;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.util.Strings;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.intellij.lang.annotations.Subst;
import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.statement.StatementContext;
public class MySQLPlayerRowMapper implements RowMapper<CarbonPlayerCommon> {
@Override
public CarbonPlayerCommon map(final ResultSet rs, final StatementContext ctx) throws SQLException {
final String id = Strings.trim(rs.getString("id"));
final @Nullable String lastWhisperTarget = Strings.trim(rs.getString("lastwhispertarget"));
final @Nullable String whisperReplyTarget = Strings.trim(rs.getString("whisperreplytarget"));
final @Nullable @Subst("carbon:global") String selectedChannel = Strings.trim(rs.getString("selectedchannel"));
final @Nullable String displayName = Strings.trim(rs.getString("displayname"));
return new CarbonPlayerCommon(
rs.getBoolean("muted"),
rs.getBoolean("deafened"),
selectedChannel == null ? null : Key.key(selectedChannel),
null,
UUID.fromString(id),
displayName == null ? null : GsonComponentSerializer.gson().deserialize(displayName),
lastWhisperTarget == null ? null : UUID.fromString(lastWhisperTarget),
whisperReplyTarget == null ? null : UUID.fromString(whisperReplyTarget),
rs.getBoolean("spying")
);
}
}
@@ -36,15 +36,19 @@ import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.messaging.packets.PacketFactory; import net.draycia.carbon.common.messaging.packets.PacketFactory;
import net.draycia.carbon.common.users.CarbonPlayerCommon; import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
import net.draycia.carbon.common.users.db.DBType;
import net.draycia.carbon.common.users.db.DatabaseUserManager; import net.draycia.carbon.common.users.db.DatabaseUserManager;
import net.draycia.carbon.common.users.db.KeyArgumentFactory;
import net.draycia.carbon.common.users.db.KeyColumnMapper;
import net.draycia.carbon.common.users.db.QueriesLocator; import net.draycia.carbon.common.users.db.QueriesLocator;
import net.draycia.carbon.common.users.db.argument.BinaryUUIDArgumentFactory;
import net.draycia.carbon.common.users.db.argument.ComponentArgumentFactory;
import net.draycia.carbon.common.users.db.argument.KeyArgumentFactory;
import net.draycia.carbon.common.users.db.mapper.BinaryUUIDColumnMapper;
import net.draycia.carbon.common.users.db.mapper.ComponentColumnMapper;
import net.draycia.carbon.common.users.db.mapper.KeyColumnMapper;
import net.draycia.carbon.common.users.db.mapper.PlayerRowMapper;
import net.draycia.carbon.common.util.ConcurrentUtil; import net.draycia.carbon.common.util.ConcurrentUtil;
import net.draycia.carbon.common.util.SQLDrivers; import net.draycia.carbon.common.util.SQLDrivers;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@@ -67,7 +71,7 @@ public final class MySQLUserManager extends DatabaseUserManager {
) { ) {
super( super(
jdbi, jdbi,
new QueriesLocator(DBType.MYSQL), new QueriesLocator(),
logger, logger,
profileResolver, profileResolver,
playerInjector, playerInjector,
@@ -165,10 +169,12 @@ public final class MySQLUserManager extends DatabaseUserManager {
final Jdbi jdbi = Jdbi.create(dataSource) final Jdbi jdbi = Jdbi.create(dataSource)
.registerArgument(new ComponentArgumentFactory()) .registerArgument(new ComponentArgumentFactory())
.registerArgument(new KeyArgumentFactory()) .registerArgument(new KeyArgumentFactory())
.registerArgument(new MySQLUUIDArgumentFactory()) .registerArgument(new BinaryUUIDArgumentFactory())
.registerColumnMapper(Key.class, new KeyColumnMapper())
.registerColumnMapper(Component.class, new ComponentColumnMapper())
.registerColumnMapper(UUID.class, new BinaryUUIDColumnMapper())
.registerRowMapper(new PlayerRowMapper())
.registerArrayType(UUID.class, "uuid") .registerArrayType(UUID.class, "uuid")
.registerColumnMapper(new KeyColumnMapper())
.registerRowMapper(new MySQLPlayerRowMapper())
.installPlugin(new SqlObjectPlugin()); .installPlugin(new SqlObjectPlugin());
return new MySQLUserManager(jdbi, this.logger, this.profileResolver, this.playerInjector, this.messagingManager, this.packetFactory, this.channelRegistry); return new MySQLUserManager(jdbi, this.logger, this.profileResolver, this.playerInjector, this.messagingManager, this.packetFactory, this.channelRegistry);
@@ -35,15 +35,18 @@ import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.messaging.packets.PacketFactory; import net.draycia.carbon.common.messaging.packets.PacketFactory;
import net.draycia.carbon.common.users.CarbonPlayerCommon; import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
import net.draycia.carbon.common.users.db.DBType;
import net.draycia.carbon.common.users.db.DatabaseUserManager; import net.draycia.carbon.common.users.db.DatabaseUserManager;
import net.draycia.carbon.common.users.db.KeyArgumentFactory;
import net.draycia.carbon.common.users.db.KeyColumnMapper;
import net.draycia.carbon.common.users.db.QueriesLocator; import net.draycia.carbon.common.users.db.QueriesLocator;
import net.draycia.carbon.common.users.db.argument.ComponentArgumentFactory;
import net.draycia.carbon.common.users.db.argument.KeyArgumentFactory;
import net.draycia.carbon.common.users.db.mapper.ComponentColumnMapper;
import net.draycia.carbon.common.users.db.mapper.KeyColumnMapper;
import net.draycia.carbon.common.users.db.mapper.NativeUUIDColumnMapper;
import net.draycia.carbon.common.users.db.mapper.PlayerRowMapper;
import net.draycia.carbon.common.util.ConcurrentUtil; import net.draycia.carbon.common.util.ConcurrentUtil;
import net.draycia.carbon.common.util.SQLDrivers; import net.draycia.carbon.common.util.SQLDrivers;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@@ -67,7 +70,7 @@ public final class PostgreSQLUserManager extends DatabaseUserManager {
) { ) {
super( super(
jdbi, jdbi,
new QueriesLocator(DBType.POSTGRESQL), new QueriesLocator(),
logger, logger,
profileResolver, profileResolver,
playerInjector, playerInjector,
@@ -166,8 +169,10 @@ public final class PostgreSQLUserManager extends DatabaseUserManager {
final Jdbi jdbi = Jdbi.create(dataSource) final Jdbi jdbi = Jdbi.create(dataSource)
.registerArgument(new ComponentArgumentFactory()) .registerArgument(new ComponentArgumentFactory())
.registerArgument(new KeyArgumentFactory()) .registerArgument(new KeyArgumentFactory())
.registerColumnMapper(new KeyColumnMapper()) .registerColumnMapper(Key.class, new KeyColumnMapper())
.registerRowMapper(new PostgreSQLPlayerRowMapper()) .registerColumnMapper(Component.class, new ComponentColumnMapper())
.registerColumnMapper(UUID.class, new NativeUUIDColumnMapper())
.registerRowMapper(new PlayerRowMapper())
.installPlugin(new SqlObjectPlugin()) .installPlugin(new SqlObjectPlugin())
.installPlugin(new PostgresPlugin()); .installPlugin(new PostgresPlugin());
@@ -0,0 +1,9 @@
INSERT IGNORE INTO carbon_users SET
id = :id,
muted = :muted,
deafened = :deafened,
selectedchannel = :selectedchannel,
displayname = :displayname,
lastwhispertarget = :lastwhispertarget,
whisperreplytarget = :whisperreplytarget,
spying = :spying;
@@ -1 +0,0 @@
DELETE FROM carbon_ignores WHERE (id = UNHEX(REPLACE(:id, '-', '')));
@@ -1 +0,0 @@
DELETE FROM carbon_leftchannels WHERE (id = UNHEX(REPLACE(:id, '-', '')));
@@ -1,19 +0,0 @@
INSERT INTO carbon_users SET
id = UNHEX(REPLACE(:id, '-', '')),
muted = :muted,
deafened = :deafened,
selectedchannel = :selectedchannel,
displayname = :displayname,
lastwhispertarget = UNHEX(REPLACE(:lastwhispertarget, '-', '')),
whisperreplytarget = UNHEX(REPLACE(:whisperreplytarget, '-', '')),
spying = :spying
ON DUPLICATE KEY UPDATE
id = UNHEX(REPLACE(:id, '-', '')),
muted = :muted,
deafened = :deafened,
selectedchannel = :selectedchannel,
displayname = :displayname,
lastwhispertarget = UNHEX(REPLACE(:lastwhispertarget, '-', '')),
whisperreplytarget = UNHEX(REPLACE(:whisperreplytarget, '-', '')),
spying = :spying
;
@@ -1 +0,0 @@
INSERT IGNORE INTO carbon_ignores (id, ignoredplayer) VALUES(UNHEX(REPLACE(:id, '-', '')), UNHEX(REPLACE(:ignoredplayer, '-', '')))
@@ -1 +0,0 @@
INSERT IGNORE INTO carbon_leftchannels (id, channel) VALUES(UNHEX(REPLACE(:id, '-', '')), :channel)
@@ -1,9 +0,0 @@
SELECT
LOWER(CONCAT(
LEFT(HEX(ignoredplayer), 8), '-',
MID(HEX(ignoredplayer), 9, 4), '-',
MID(HEX(ignoredplayer), 13, 4), '-',
MID(HEX(ignoredplayer), 17, 4), '-',
RIGHT(HEX(ignoredplayer), 12)
)) AS ignoredplayer
FROM carbon_ignores WHERE (id = UNHEX(REPLACE(:id, '-', '')));
@@ -1 +0,0 @@
SELECT channel FROM carbon_leftchannels WHERE (id = UNHEX(REPLACE(:id, '-', '')));
@@ -1,28 +0,0 @@
SELECT
LOWER(CONCAT(
LEFT(HEX(id), 8), '-',
MID(HEX(id), 9, 4), '-',
MID(HEX(id), 13, 4), '-',
MID(HEX(id), 17, 4), '-',
RIGHT(HEX(id), 12)
)) AS id,
muted,
deafened,
selectedchannel,
displayname,
LOWER(CONCAT(
LEFT(HEX(lastwhispertarget), 8), '-',
MID(HEX(lastwhispertarget), 9, 4), '-',
MID(HEX(lastwhispertarget), 13, 4), '-',
MID(HEX(lastwhispertarget), 17, 4), '-',
RIGHT(HEX(lastwhispertarget), 12)
)) AS lastwhispertarget,
LOWER(CONCAT(
LEFT(HEX(whisperreplytarget), 8), '-',
MID(HEX(whisperreplytarget), 9, 4), '-',
MID(HEX(whisperreplytarget), 13, 4), '-',
MID(HEX(whisperreplytarget), 17, 4), '-',
RIGHT(HEX(whisperreplytarget), 12)
)) AS whisperreplytarget,
spying
FROM carbon_users WHERE (id = UNHEX(REPLACE(:id, '-', '')));
@@ -1,19 +0,0 @@
INSERT INTO carbon_users SET
id = :id,
muted = :muted,
deafened = :deafened,
selectedchannel = :selectedchannel,
displayname = :displayname,
lastwhispertarget = :lastwhispertarget,
whisperreplytarget = :whisperreplytarget,
spying = :spying
ON CONFLICT (id) DO UPDATE SET
id = :id,
muted = :muted,
deafened = :deafened,
selectedchannel = :selectedchannel,
displayname = :displayname,
lastwhispertarget = :lastwhispertarget,
whisperreplytarget = :whisperreplytarget,
spying = :spying
;
@@ -1 +0,0 @@
INSERT INTO carbon_ignores (id, ignoredplayer) VALUES(:id, :ignoredplayer)
@@ -1 +0,0 @@
INSERT INTO carbon_leftchannels (id, channel) VALUES(:id, :channel)
@@ -0,0 +1 @@
INSERT IGNORE INTO carbon_ignores (id, ignoredplayer) VALUES(:id, :ignoredplayer)
@@ -0,0 +1 @@
INSERT IGNORE INTO carbon_leftchannels (id, channel) VALUES(:id, :channel)
@@ -0,0 +1,9 @@
UPDATE carbon_users SET
id = :id,
muted = :muted,
deafened = :deafened,
selectedchannel = :selectedchannel,
displayname = :displayname,
lastwhispertarget = :lastwhispertarget,
whisperreplytarget = :whisperreplytarget,
spying = :spying;