mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Use the mariadb driver by default
This commit is contained in:
parent
ea00ec64af
commit
5567b1dad8
@ -30,6 +30,7 @@ import lombok.Getter;
|
|||||||
public enum Dependency {
|
public enum Dependency {
|
||||||
|
|
||||||
CAFFEINE("https://repo1.maven.org/maven2/com/github/ben-manes/caffeine/caffeine/2.4.0/caffeine-2.4.0.jar", "2.4.0"),
|
CAFFEINE("https://repo1.maven.org/maven2/com/github/ben-manes/caffeine/caffeine/2.4.0/caffeine-2.4.0.jar", "2.4.0"),
|
||||||
|
MARIADB_DRIVER("https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/1.5.9/mariadb-java-client-1.5.9.jar", "1.5.9"),
|
||||||
MYSQL_DRIVER("https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar", "5.1.6"),
|
MYSQL_DRIVER("https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar", "5.1.6"),
|
||||||
POSTGRESQL_DRIVER("https://repo1.maven.org/maven2/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar", "9.4.1212"),
|
POSTGRESQL_DRIVER("https://repo1.maven.org/maven2/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar", "9.4.1212"),
|
||||||
H2_DRIVER("https://repo1.maven.org/maven2/com/h2database/h2/1.4.193/h2-1.4.193.jar", "1.4.193"),
|
H2_DRIVER("https://repo1.maven.org/maven2/com/h2database/h2/1.4.193/h2-1.4.193.jar", "1.4.193"),
|
||||||
|
@ -60,7 +60,8 @@ public class DependencyManager {
|
|||||||
.put(StorageType.JSON, ImmutableList.of())
|
.put(StorageType.JSON, ImmutableList.of())
|
||||||
.put(StorageType.YAML, ImmutableList.of())
|
.put(StorageType.YAML, ImmutableList.of())
|
||||||
.put(StorageType.MONGODB, ImmutableList.of(Dependency.MONGODB_DRIVER))
|
.put(StorageType.MONGODB, ImmutableList.of(Dependency.MONGODB_DRIVER))
|
||||||
.put(StorageType.MYSQL, ImmutableList.of(Dependency.MYSQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
.put(StorageType.MYSQL, ImmutableList.of(Dependency.MARIADB_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
||||||
|
.put(StorageType.MYSQL_LEGACY, ImmutableList.of(Dependency.MYSQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
||||||
.put(StorageType.POSTGRESQL, ImmutableList.of(Dependency.POSTGRESQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
.put(StorageType.POSTGRESQL, ImmutableList.of(Dependency.POSTGRESQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
||||||
.put(StorageType.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER))
|
.put(StorageType.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER))
|
||||||
.put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER))
|
.put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER))
|
||||||
|
@ -107,6 +107,7 @@ public class StorageFactory {
|
|||||||
type = defaultMethod;
|
type = defaultMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.getLog().info("Using " + type.getName() + " storage.");
|
||||||
storage = makeInstance(type, plugin);
|
storage = makeInstance(type, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +123,9 @@ public class StorageFactory {
|
|||||||
private static AbstractBacking makeBacking(StorageType method, LuckPermsPlugin plugin) {
|
private static AbstractBacking makeBacking(StorageType method, LuckPermsPlugin plugin) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case MYSQL:
|
case MYSQL:
|
||||||
return new SQLBacking(plugin, new MySQLProvider(plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES)), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
|
return new SQLBacking(plugin, new MySQLProvider("MySQL", "org.mariadb.jdbc.MySQLDataSource", plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES)), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
|
||||||
|
case MYSQL_LEGACY:
|
||||||
|
return new SQLBacking(plugin, new MySQLProvider("MySQL-Legacy", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource", plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES)), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
|
||||||
case SQLITE:
|
case SQLITE:
|
||||||
return new SQLBacking(plugin, new SQLiteProvider(new File(plugin.getDataDirectory(), "luckperms-sqlite.db")), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
|
return new SQLBacking(plugin, new SQLiteProvider(new File(plugin.getDataDirectory(), "luckperms-sqlite.db")), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
|
||||||
case H2:
|
case H2:
|
||||||
|
@ -30,18 +30,23 @@ import java.util.List;
|
|||||||
|
|
||||||
public enum StorageType {
|
public enum StorageType {
|
||||||
|
|
||||||
JSON("json", "flatfile"),
|
JSON("JSON", "json", "flatfile"),
|
||||||
YAML("yaml", "yml"),
|
YAML("YAML", "yaml", "yml"),
|
||||||
MONGODB("mongodb"),
|
MONGODB("MongoDB", "mongodb"),
|
||||||
MYSQL("mysql"),
|
MYSQL("MySQL", "mysql"),
|
||||||
POSTGRESQL("postgresql"),
|
MYSQL_LEGACY("MySQL-Legacy", "mysql-legacy"),
|
||||||
SQLITE("sqlite"),
|
POSTGRESQL("PostgreSQL", "postgresql"),
|
||||||
H2("h2");
|
SQLITE("SQLite", "sqlite"),
|
||||||
|
H2("H2", "h2");
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final String name;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final List<String> identifiers;
|
private final List<String> identifiers;
|
||||||
|
|
||||||
StorageType(String... identifiers) {
|
StorageType(String name, String... identifiers) {
|
||||||
|
this.name = name;
|
||||||
this.identifiers = ImmutableList.copyOf(identifiers);
|
this.identifiers = ImmutableList.copyOf(identifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import com.google.common.collect.Iterables;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.HeldPermission;
|
import me.lucko.luckperms.api.HeldPermission;
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.core.NodeModel;
|
import me.lucko.luckperms.common.core.NodeModel;
|
||||||
import me.lucko.luckperms.common.core.UserIdentifier;
|
import me.lucko.luckperms.common.core.UserIdentifier;
|
||||||
import me.lucko.luckperms.common.core.model.Group;
|
import me.lucko.luckperms.common.core.model.Group;
|
||||||
@ -498,7 +499,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
context = map.build();
|
context = map.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.add(NodeModel.of(permission, value, server, world, expiry, context));
|
nodes.add(NodeModel.of(permission, value, server, world, expiry, ImmutableContextSet.fromMultimap(context)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -526,7 +527,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
|
|
||||||
if (!node.getContexts().isEmpty()) {
|
if (!node.getContexts().isEmpty()) {
|
||||||
Map<String, Object> context = new HashMap<>();
|
Map<String, Object> context = new HashMap<>();
|
||||||
Map<String, Collection<String>> map = node.getContexts().asMap();
|
Map<String, Collection<String>> map = node.getContexts().toMultimap().asMap();
|
||||||
|
|
||||||
for (Map.Entry<String, Collection<String>> e : map.entrySet()) {
|
for (Map.Entry<String, Collection<String>> e : map.entrySet()) {
|
||||||
List<String> vals = new ArrayList<>(e.getValue());
|
List<String> vals = new ArrayList<>(e.getValue());
|
||||||
|
@ -34,11 +34,13 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class MySQLProvider extends SQLProvider {
|
public class MySQLProvider extends SQLProvider {
|
||||||
|
|
||||||
private final DatastoreConfiguration configuration;
|
private final DatastoreConfiguration configuration;
|
||||||
|
private final String driverClass;
|
||||||
private HikariDataSource hikari;
|
private HikariDataSource hikari;
|
||||||
|
|
||||||
public MySQLProvider(DatastoreConfiguration configuration) {
|
public MySQLProvider(String name, String driverClass, DatastoreConfiguration configuration) {
|
||||||
super("MySQL");
|
super(name);
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
this.driverClass = driverClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,23 +59,36 @@ public class MySQLProvider extends SQLProvider {
|
|||||||
config.setMaximumPoolSize(configuration.getPoolSize());
|
config.setMaximumPoolSize(configuration.getPoolSize());
|
||||||
|
|
||||||
config.setPoolName("luckperms");
|
config.setPoolName("luckperms");
|
||||||
config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
config.setDataSourceClassName(driverClass);
|
||||||
config.addDataSourceProperty("serverName", address);
|
config.addDataSourceProperty("serverName", address);
|
||||||
config.addDataSourceProperty("port", port);
|
config.addDataSourceProperty("port", port);
|
||||||
config.addDataSourceProperty("databaseName", database);
|
config.addDataSourceProperty("databaseName", database);
|
||||||
config.addDataSourceProperty("user", username);
|
config.setUsername(username);
|
||||||
config.addDataSourceProperty("password", password);
|
config.setPassword(password);
|
||||||
|
|
||||||
|
if (getName().toLowerCase().endsWith("legacy")) {
|
||||||
|
|
||||||
|
// doesn't exist on the MariaDB driver
|
||||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
config.addDataSourceProperty("cachePrepStmts", "true");
|
||||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
|
||||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
|
||||||
config.addDataSourceProperty("useServerPrepStmts", "true");
|
|
||||||
config.addDataSourceProperty("cacheCallableStmts", "true");
|
|
||||||
config.addDataSourceProperty("alwaysSendSetIsolation", "false");
|
config.addDataSourceProperty("alwaysSendSetIsolation", "false");
|
||||||
config.addDataSourceProperty("cacheServerConfiguration", "true");
|
config.addDataSourceProperty("cacheServerConfiguration", "true");
|
||||||
config.addDataSourceProperty("elideSetAutoCommits", "true");
|
config.addDataSourceProperty("elideSetAutoCommits", "true");
|
||||||
config.addDataSourceProperty("useLocalSessionState", "true");
|
config.addDataSourceProperty("useLocalSessionState", "true");
|
||||||
|
|
||||||
|
// already set as default on mariadb
|
||||||
|
config.addDataSourceProperty("useServerPrepStmts", "true");
|
||||||
|
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||||
|
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||||
|
config.addDataSourceProperty("cacheCallableStmts", "true");
|
||||||
|
|
||||||
|
// make sure unicode characters can be used.
|
||||||
config.addDataSourceProperty("characterEncoding", "utf8");
|
config.addDataSourceProperty("characterEncoding", "utf8");
|
||||||
config.addDataSourceProperty("useUnicode", "true");
|
config.addDataSourceProperty("useUnicode", "true");
|
||||||
|
} else {
|
||||||
|
// hack for mariadb. this will call #setProperties on the datasource, which will append these options
|
||||||
|
// onto the connections.
|
||||||
|
config.addDataSourceProperty("properties", "useUnicode=true;characterEncoding=utf8");
|
||||||
|
}
|
||||||
|
|
||||||
// We will wait for 15 seconds to get a connection from the pool.
|
// We will wait for 15 seconds to get a connection from the pool.
|
||||||
// Default is 30, but it shouldn't be taking that long.
|
// Default is 30, but it shouldn't be taking that long.
|
||||||
|
@ -43,7 +43,7 @@ public class HikariSupplier implements AutoCloseable {
|
|||||||
hikari = new HikariDataSource();
|
hikari = new HikariDataSource();
|
||||||
hikari.setPoolName(poolName);
|
hikari.setPoolName(poolName);
|
||||||
hikari.setMaximumPoolSize(2);
|
hikari.setMaximumPoolSize(2);
|
||||||
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
hikari.setDataSourceClassName("org.mariadb.jdbc.Driver");
|
||||||
hikari.addDataSourceProperty("serverName", address.split(":")[0]);
|
hikari.addDataSourceProperty("serverName", address.split(":")[0]);
|
||||||
hikari.addDataSourceProperty("port", address.split(":")[1]);
|
hikari.addDataSourceProperty("port", address.split(":")[1]);
|
||||||
hikari.addDataSourceProperty("databaseName", database);
|
hikari.addDataSourceProperty("databaseName", database);
|
||||||
|
Loading…
Reference in New Issue
Block a user