This commit is contained in:
Draycia committed 2022-06-08 15:16:19 -07:00
1 parent 6cbabd692e
commit 9903e0da2c
15 files changed
+165 -21

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ dependencies {
api(libs.jdbiObject)
api(libs.hikariCP)
api(libs.flyway)
api(libs.flywayMysql)
//api(libs.flywayMysql)
api(libs.mysql)
api(libs.caffeine)
api(libs.mariadb)
@@ -26,7 +26,6 @@ import com.google.inject.Singleton;
import io.leangen.geantyref.TypeToken;
import java.util.Objects;
import java.util.UUID;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.users.UserManager;
@@ -1,3 +1,22 @@
/*
* 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.config;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -1,3 +1,22 @@
/*
* 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;
import java.sql.ResultSet;
@@ -12,7 +31,7 @@ import org.jdbi.v3.core.statement.StatementContext;
public class CarbonPlayerCommonRowMapper implements RowMapper<CarbonPlayerCommon> {
@Override
public CarbonPlayerCommon map(ResultSet rs, StatementContext ctx) throws SQLException {
public CarbonPlayerCommon map(final ResultSet rs, final StatementContext ctx) throws SQLException {
return new CarbonPlayerCommon(
rs.getBoolean("muted"),
rs.getBoolean("deafened"),
@@ -1,3 +1,22 @@
/*
* 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;
import java.sql.ResultSet;
@@ -1,3 +1,22 @@
/*
* 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;
public final class DBType {
@@ -1,3 +1,22 @@
/*
* 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;
import com.zaxxer.hikari.HikariConfig;
@@ -23,12 +42,13 @@ import org.flywaydb.core.Flyway;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.statement.PreparedBatch;
import org.jdbi.v3.core.statement.Update;
import static net.kyori.adventure.text.Component.empty;
import static net.kyori.adventure.text.Component.text;
// TODO: Dispatch updates using messaging system when users are modified
@DefaultQualifier(NonNull.class)
public class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
public final class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
private final Jdbi jdbi;
@@ -54,7 +74,7 @@ public class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
Flyway.configure(CarbonChatProvider.carbonChat().getClass().getClassLoader())
.baselineVersion("0")
.baselineOnMigrate(true)
.locations("queries/migrations")
.locations("queries/migrations/sql")
.dataSource(dataSource)
.validateOnMigrate(true)
.load()
@@ -1,9 +1,31 @@
/*
* 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;
import com.google.common.base.Splitter;
import java.util.List;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jdbi.v3.core.locator.ClasspathSqlLocator;
import org.jdbi.v3.core.locator.internal.ClasspathBuilder;
public final class QueriesLocator {
@@ -16,11 +38,20 @@ public final class QueriesLocator {
}
public @NonNull String query(final @NonNull String name) {
return this.locator.locate(this.dbType.basePath() + name);
return this.locate(this.dbType.basePath() + name);
}
public @NonNull List<@NonNull String> queries(final @NonNull String name) {
return SPLITTER.splitToList(this.locator.locate(this.dbType.basePath() + name));
}
private String locate(final String name) {
return locator.getResource(
CarbonChat.class.getClassLoader(),
new ClasspathBuilder()
.appendDotPath(name)
.setExtension("sql")
.build());
}
}
@@ -1,7 +1,7 @@
/*
* CarbonChat
*
* Copyright (c) 2021 Josh Taylor (broccolai)
* Copyright (c) 2021 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
@@ -1,11 +1,11 @@
INSERT INTO carbon_users VALUES (
UUID_TO_BIN(:id),
UNHEX(REPLACE(:id, '-', '')),
:muted,
:deafened,
:selectedchannel,
:username,
:displayname,
UUID_TO_BIN(:lastwhispertarget),
UUID_TO_BIN(:whisperreplytarget),
UNHEX(REPLACE(:lastwhispertarget, '-', '')),
UNHEX(REPLACE(:whisperreplytarget, '-', '')),
:spying
);
@@ -1 +1 @@
INSERT INTO carbon_ignores (id, ignoredplayer) VALUES(UUID_TO_BIN(:id), :name)
INSERT INTO carbon_ignores (id, ignoredplayer) VALUES(UNHEX(REPLACE(:id, '-', '')), UNHEX(REPLACE(:ignoredplayer, '-', '')))
@@ -1,12 +1,12 @@
UPDATE carbon_users
SET
id = UUID_TO_BIN(:id),
id = UNHEX(REPLACE(:id, '-', '')),
muted = :muted,
deafened = :deafened,
selectedchannel = :selectedchannel,
username= :username,
displayname = :displayname,
lastwhispertarget = UUID_TO_BIN(:lastwhispertarget),
whisperreplytarget = UUID_TO_BIN(:whisperreplytarget),
lastwhispertarget = UNHEX(REPLACE(:lastwhispertarget, '-', '')),
whisperreplytarget = UNHEX(REPLACE(:whisperreplytarget, '-', '')),
spying = :spying
WHERE id = UUID_TO_BIN(:id);
WHERE id = UNHEX(REPLACE(:id, '-', ''));
@@ -1 +1 @@
SELECT ignoredplayer FROM carbon_ignores WHERE (id = :id);
SELECT ignoredplayer FROM carbon_ignores WHERE (id = UNHEX(REPLACE(:id, '-', '')));
@@ -1,11 +1,29 @@
SELECT
BIN_TO_UUID(id) id,
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,
username,
displayname,
UUID_TO_BIN(lastwhispertarget) lastwhispertarget,
UUID_TO_BIN(whisperreplytarget) whisperreplytarget,
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 = UUID_TO_BIN(:id));
FROM carbon_users WHERE (id = UNHEX(REPLACE(:id, '-', '')));
+1 -1
View File
@@ -40,7 +40,7 @@ versions:
jdbi: 3.25.0
hikari: 5.0.0
mysql: 8.0.12
flyway: 8.3.0
flyway: 7.7.1
caffeine: 3.0.5
mariadb: 3.0.2-rc