mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
postgresql loads!
This commit is contained in:
1 parent
26e9eaa212
commit
f67bab76d9
7 files changed
+36
-40
No files matched your search
@@ -31,6 +31,7 @@ dependencies {
|
|||||||
api(libs.flyway)
|
api(libs.flyway)
|
||||||
api(libs.flywayMysql)
|
api(libs.flywayMysql)
|
||||||
api(libs.mysql)
|
api(libs.mysql)
|
||||||
|
api(libs.postgresql)
|
||||||
api(libs.caffeine)
|
api(libs.caffeine)
|
||||||
api(libs.mariadb)
|
api(libs.mariadb)
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ import net.draycia.carbon.common.messages.placeholders.KeyPlaceholderResolver;
|
|||||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||||
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
||||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||||
import net.draycia.carbon.common.users.JSONUserManager;
|
import net.draycia.carbon.common.users.db.postgresql.PostgreSQLUserManager;
|
||||||
|
import net.draycia.carbon.common.users.json.JSONUserManager;
|
||||||
import net.draycia.carbon.common.users.db.mysql.MySQLUserManager;
|
import net.draycia.carbon.common.users.db.mysql.MySQLUserManager;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
@@ -50,6 +51,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.moonshine.Moonshine;
|
import net.kyori.moonshine.Moonshine;
|
||||||
import net.kyori.moonshine.exception.scan.UnscannableMethodException;
|
import net.kyori.moonshine.exception.scan.UnscannableMethodException;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
@@ -61,22 +63,11 @@ public final class CarbonCommonModule extends AbstractModule {
|
|||||||
final ConfigFactory configFactory,
|
final ConfigFactory configFactory,
|
||||||
final Injector injector
|
final Injector injector
|
||||||
) {
|
) {
|
||||||
switch (Objects.requireNonNull(configFactory.primaryConfig()).storageType()) {
|
return switch (Objects.requireNonNull(configFactory.primaryConfig()).storageType()) {
|
||||||
case MYSQL -> {
|
case MYSQL -> MySQLUserManager.manager(configFactory.primaryConfig().databaseSettings());
|
||||||
final UserManager<CarbonPlayerCommon> userManager = MySQLUserManager.manager(
|
case PSQL -> PostgreSQLUserManager.manager(configFactory.primaryConfig().databaseSettings());
|
||||||
configFactory.primaryConfig().databaseSettings());
|
default -> injector.getInstance(JSONUserManager.class);
|
||||||
|
};
|
||||||
if (userManager == null) {
|
|
||||||
throw new IllegalStateException("Failure connecting to database.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return userManager;
|
|
||||||
}
|
|
||||||
case PSQL -> throw new UnsupportedOperationException("PostgreSQL is not supported yet.");
|
|
||||||
default -> {
|
|
||||||
return injector.getInstance(JSONUserManager.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
+2
-2
@@ -52,10 +52,10 @@ public interface MySQLSaveOnChange extends SaveOnChange {
|
|||||||
@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);
|
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 = UNHEX(REPLACE(:ignoredPlayer, '-', ''))")
|
||||||
int addIgnore(final UUID id, final UUID 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);
|
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
||||||
|
|
||||||
}
|
}
|
||||||
+9
-9
@@ -12,31 +12,31 @@ import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface PostgreSQLSaveOnChange extends SaveOnChange {
|
public interface PostgreSQLSaveOnChange extends SaveOnChange {
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("UPDATE carbon_users SET displayname = :displayName WHERE id = :id")
|
||||||
int saveDisplayName(final UUID id, final @Nullable Component displayName);
|
int saveDisplayName(final UUID id, final @Nullable Component displayName);
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("UPDATE carbon_users SET muted = :muted WHERE id = :id")
|
||||||
int saveMuted(final UUID id, final boolean muted);
|
int saveMuted(final UUID id, final boolean muted);
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("UPDATE carbon_users SET deafened = :deafened WHERE id = :id")
|
||||||
int saveDeafened(final UUID id, final boolean deafened);
|
int saveDeafened(final UUID id, final boolean deafened);
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("UPDATE carbon_users SET spying = :spying WHERE id = :id")
|
||||||
int saveSpying(final UUID id, final boolean spying);
|
int saveSpying(final UUID id, final boolean spying);
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("UPDATE carbon_users SET selectedchannel = :selectedChannel WHERE id = :id")
|
||||||
int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel);
|
int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel);
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("UPDATE carbon_users SET lastwhispertarget = :lastWhisperTarget WHERE id = :id")
|
||||||
int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget);
|
int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget);
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("UPDATE carbon_users SET whisperreplytarget = :whisperReplyTarget WHERE id = :id")
|
||||||
int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget);
|
int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget);
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("INSERT INTO carbon_ignores VALUES id = :id, ignoredplayer = :ignoredPlayer")
|
||||||
int addIgnore(final UUID id, final UUID ignoredPlayer);
|
int addIgnore(final UUID id, final UUID ignoredPlayer);
|
||||||
|
|
||||||
@SqlUpdate("")
|
@SqlUpdate("DELETE FROM carbon_ignores WHERE id = :id, ignoredplayer = :ignoredPlayer")
|
||||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
||||||
|
|
||||||
}
|
}
|
||||||
+9
-11
@@ -46,6 +46,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
import org.flywaydb.core.Flyway;
|
import org.flywaydb.core.Flyway;
|
||||||
|
import org.flywaydb.core.internal.database.postgresql.PostgreSQLDatabaseType;
|
||||||
|
import org.flywaydb.core.internal.plugin.PluginRegister;
|
||||||
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;
|
import org.jdbi.v3.core.statement.Update;
|
||||||
@@ -62,17 +64,16 @@ public final class PostgreSQLUserManager implements UserManager<CarbonPlayerComm
|
|||||||
private final Jdbi jdbi;
|
private final Jdbi jdbi;
|
||||||
|
|
||||||
private final Map<UUID, CarbonPlayerCommon> userCache = Collections.synchronizedMap(new HashMap<>());
|
private final Map<UUID, CarbonPlayerCommon> userCache = Collections.synchronizedMap(new HashMap<>());
|
||||||
private final QueriesLocator locator = new QueriesLocator(DBType.MYSQL);
|
private final QueriesLocator locator = new QueriesLocator(DBType.POSTGRESQL);
|
||||||
|
|
||||||
private PostgreSQLUserManager(final Jdbi jdbi) {
|
private PostgreSQLUserManager(final Jdbi jdbi) {
|
||||||
this.jdbi = jdbi;
|
this.jdbi = jdbi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PostgreSQLUserManager manager(
|
public static PostgreSQLUserManager manager(final DatabaseSettings databaseSettings) {
|
||||||
final DatabaseSettings databaseSettings
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
Class.forName("org.postgresql.Driver");
|
Class.forName("org.postgresql.Driver");
|
||||||
|
PluginRegister.REGISTERED_PLUGINS.add(new PostgreSQLDatabaseType());
|
||||||
} catch (final Exception exception) {
|
} catch (final Exception exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -95,7 +96,6 @@ public final class PostgreSQLUserManager implements UserManager<CarbonPlayerComm
|
|||||||
.migrate();
|
.migrate();
|
||||||
|
|
||||||
final Jdbi jdbi = Jdbi.create(dataSource)
|
final Jdbi jdbi = Jdbi.create(dataSource)
|
||||||
.registerArrayType(UUID.class, "uuid")
|
|
||||||
.registerArgument(new ComponentArgumentFactory())
|
.registerArgument(new ComponentArgumentFactory())
|
||||||
.registerArgument(new KeyArgumentFactory())
|
.registerArgument(new KeyArgumentFactory())
|
||||||
.registerRowMapper(new PostgreSQLPlayerRowMapper())
|
.registerRowMapper(new PostgreSQLPlayerRowMapper())
|
||||||
@@ -121,12 +121,10 @@ public final class PostgreSQLUserManager implements UserManager<CarbonPlayerComm
|
|||||||
.mapTo(CarbonPlayerCommon.class)
|
.mapTo(CarbonPlayerCommon.class)
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
if (carbonPlayerCommon != null) {
|
handle.createQuery(this.locator.query("select-ignores"))
|
||||||
handle.createQuery(this.locator.query("select-ignores"))
|
.bind("id", uuid)
|
||||||
.bind("id", uuid)
|
.mapTo(UUID.class)
|
||||||
.mapTo(UUID.class)
|
.forEach(ignoredPlayer -> carbonPlayerCommon.ignoring(ignoredPlayer, true));
|
||||||
.forEach(ignoredPlayer -> carbonPlayerCommon.ignoring(ignoredPlayer, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ComponentPlayerResult<>(carbonPlayerCommon, empty());
|
return new ComponentPlayerResult<>(carbonPlayerCommon, empty());
|
||||||
} catch (final IllegalStateException exception) {
|
} catch (final IllegalStateException exception) {
|
||||||
|
|||||||
+2
-1
@@ -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;
|
package net.draycia.carbon.common.users.json;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
@@ -41,6 +41,7 @@ import net.draycia.carbon.api.users.UserManager;
|
|||||||
import net.draycia.carbon.common.ForCarbon;
|
import net.draycia.carbon.common.ForCarbon;
|
||||||
import net.draycia.carbon.common.serialisation.gson.ChatChannelSerializerGson;
|
import net.draycia.carbon.common.serialisation.gson.ChatChannelSerializerGson;
|
||||||
import net.draycia.carbon.common.serialisation.gson.UUIDSerializerGson;
|
import net.draycia.carbon.common.serialisation.gson.UUIDSerializerGson;
|
||||||
|
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
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;
|
||||||
@@ -47,6 +47,7 @@ versions:
|
|||||||
netty: 4.1.68.Final
|
netty: 4.1.68.Final
|
||||||
zstdjni: 1.5.1-1
|
zstdjni: 1.5.1-1
|
||||||
jedis: 3.7.0
|
jedis: 3.7.0
|
||||||
|
postgresql: 42.3.1
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
adventureBom:
|
adventureBom:
|
||||||
@@ -209,6 +210,10 @@ dependencies:
|
|||||||
group: mysql
|
group: mysql
|
||||||
name: mysql-connector-java
|
name: mysql-connector-java
|
||||||
version: { ref: mysql }
|
version: { ref: mysql }
|
||||||
|
postgresql:
|
||||||
|
group: org.postgresql
|
||||||
|
name: postgresql
|
||||||
|
version: { ref: postgresql }
|
||||||
caffeine:
|
caffeine:
|
||||||
group: com.github.ben-manes.caffeine
|
group: com.github.ben-manes.caffeine
|
||||||
name: caffeine
|
name: caffeine
|
||||||
|
|||||||
Reference in new issue
Block a user