mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Remove unnecessary mappers
This commit is contained in:
1 parent
b871adef8f
commit
3f644245a0
8 files changed
+34
-75
No files matched your search
@@ -29,7 +29,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public interface SaveOnChange {
|
||||
|
||||
int saveDisplayName(final UUID id, final @Nullable Component component);
|
||||
int saveDisplayName(final UUID id, final @Nullable Component displayName);
|
||||
|
||||
int saveMuted(final UUID id, final boolean muted);
|
||||
|
||||
|
||||
@@ -35,11 +35,10 @@ import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.config.DatabaseSettings;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.SaveOnChange;
|
||||
import net.draycia.carbon.common.users.db.jdbi.CarbonPlayerCommonRowMapper;
|
||||
import net.draycia.carbon.common.users.db.jdbi.ComponentMapper;
|
||||
import net.draycia.carbon.common.users.db.jdbi.KeyArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.jdbi.KeyMapper;
|
||||
import net.draycia.carbon.common.users.db.jdbi.UUIDArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.mysql.CarbonPlayerCommonRowMapper;
|
||||
import net.draycia.carbon.common.users.db.mysql.ComponentArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.mysql.KeyArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.mysql.UUIDArgumentFactory;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -90,10 +89,9 @@ public final class MariaDBUserManager implements UserManager<CarbonPlayerCommon>
|
||||
|
||||
final Jdbi jdbi = Jdbi.create(dataSource)
|
||||
.registerArrayType(UUID.class, "uuid")
|
||||
.registerArgument(new UUIDArgumentFactory())
|
||||
.registerArgument(new ComponentArgumentFactory())
|
||||
.registerArgument(new KeyArgumentFactory())
|
||||
.registerColumnMapper(Component.class, new ComponentMapper())
|
||||
.registerColumnMapper(Key.class, new KeyMapper())
|
||||
.registerArgument(new UUIDArgumentFactory())
|
||||
.registerRowMapper(new CarbonPlayerCommonRowMapper())
|
||||
.installPlugin(new SqlObjectPlugin());
|
||||
|
||||
|
||||
@@ -31,31 +31,31 @@ import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public interface SQLSaveOnChange extends SaveOnChange {
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (displayname = :displayname) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveDisplayName(final UUID id, final @Nullable Component component);
|
||||
@SqlUpdate("UPDATE carbon_users SET displayname = :displayName WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveDisplayName(final UUID id, final @Nullable Component displayName);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (muted = :muted) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
@SqlUpdate("UPDATE carbon_users SET muted = :muted WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveMuted(final UUID id, final boolean muted);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (deafened = :deafened) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
@SqlUpdate("UPDATE carbon_users SET deafened = :deafened WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveDeafened(final UUID id, final boolean deafened);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (spying = :spying) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
@SqlUpdate("UPDATE carbon_users SET spying = :spying WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveSpying(final UUID id, final boolean spying);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET selectedchannel = :selectedChannel WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (lastwhispertarget = :lastWhisperTarget) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
@SqlUpdate("UPDATE carbon_users SET lastwhispertarget = :lastWhisperTarget WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (whisperreplytarget = :whisperReplyTarget) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
@SqlUpdate("UPDATE carbon_users SET whisperreplytarget = :whisperReplyTarget WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget);
|
||||
|
||||
@SqlUpdate("INSERT INTO carbon_ignores VALUES (id = UNHEX(REPLACE(:id, '-', '')), ignoredplayer = :ignoredPlayer)")
|
||||
@SqlUpdate("INSERT INTO carbon_ignores VALUES id = UNHEX(REPLACE(:id, '-', ''), ignoredplayer = :ignoredPlayer)")
|
||||
int addIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
@SqlUpdate("DELETE FROM carbon_ignores WHERE (id = UNHEX(REPLACE(:id, '-', '')), ignoredplayer = UNHEX(REPLACE(:ignoredPlayer, '-', '')))")
|
||||
@SqlUpdate("DELETE FROM carbon_ignores WHERE id = UNHEX(REPLACE(:id, '-', ''), ignoredplayer = UNHEX(REPLACE(:ignoredPlayer, '-', '')))")
|
||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 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.jdbi;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import net.kyori.adventure.key.Key;
|
||||
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 class KeyMapper implements ColumnMapper<Key> {
|
||||
|
||||
@Override
|
||||
public Key map(final ResultSet r, final int columnNumber, final StatementContext ctx) throws SQLException {
|
||||
return Key.key(r.getString(columnNumber));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key map(final ResultSet r, final String columnLabel, final StatementContext ctx) throws SQLException {
|
||||
return Key.key(r.getString(columnLabel));
|
||||
}
|
||||
|
||||
}
|
||||
+4
-2
@@ -17,7 +17,7 @@
|
||||
* 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.jdbi;
|
||||
package net.draycia.carbon.common.users.db.mysql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -25,6 +25,7 @@ import java.util.UUID;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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;
|
||||
@@ -38,6 +39,7 @@ public class CarbonPlayerCommonRowMapper implements RowMapper<CarbonPlayerCommon
|
||||
final @Nullable String lastWhisperTarget = rs.getString("lastwhispertarget");
|
||||
final @Nullable String whisperReplyTarget = rs.getString("whisperreplytarget");
|
||||
final @Nullable @Subst("carbon:global") String selectedChannel = rs.getString("selectedchannel");
|
||||
final @Nullable String displayName = rs.getString("displayname");
|
||||
|
||||
return new CarbonPlayerCommon(
|
||||
rs.getBoolean("muted"),
|
||||
@@ -45,7 +47,7 @@ public class CarbonPlayerCommonRowMapper implements RowMapper<CarbonPlayerCommon
|
||||
selectedChannel == null ? null : Key.key(selectedChannel),
|
||||
rs.getString("username"),
|
||||
UUID.fromString(id),
|
||||
rs.getObject("displayname", Component.class),
|
||||
displayName == null ? null : GsonComponentSerializer.gson().deserialize(displayName),
|
||||
lastWhisperTarget == null ? null : UUID.fromString(lastWhisperTarget),
|
||||
whisperReplyTarget == null ? null : UUID.fromString(whisperReplyTarget),
|
||||
rs.getBoolean("spying")
|
||||
+12
-11
@@ -17,27 +17,28 @@
|
||||
* 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.jdbi;
|
||||
package net.draycia.carbon.common.users.db.mysql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.key.Key;
|
||||
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;
|
||||
import org.jdbi.v3.core.argument.AbstractArgumentFactory;
|
||||
import org.jdbi.v3.core.argument.Argument;
|
||||
import org.jdbi.v3.core.config.ConfigRegistry;
|
||||
|
||||
public class ComponentMapper implements ColumnMapper<Component> {
|
||||
public final class ComponentArgumentFactory extends AbstractArgumentFactory<Component> {
|
||||
|
||||
final GsonComponentSerializer serializer = GsonComponentSerializer.gson();
|
||||
|
||||
@Override
|
||||
public Component map(final ResultSet r, final int columnNumber, final StatementContext ctx) throws SQLException {
|
||||
return this.serializer.deserialize(r.getString(columnNumber));
|
||||
public ComponentArgumentFactory() {
|
||||
super(Types.VARCHAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component map(final ResultSet r, final String columnLabel, final StatementContext ctx) throws SQLException {
|
||||
return this.serializer.deserialize(r.getString(columnLabel));
|
||||
public Argument build(final Component value, final ConfigRegistry config) {
|
||||
return (position, statement, ctx) -> statement.setString(position, this.serializer.serialize(value));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* 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.jdbi;
|
||||
package net.draycia.carbon.common.users.db.mysql;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.UUID;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* 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.jdbi;
|
||||
package net.draycia.carbon.common.users.db.mysql;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.UUID;
|
||||
Reference in new issue
Block a user