Use the mariadb driver by default

This commit is contained in:
Luck 2017-04-05 21:23:18 +01:00
parent ea00ec64af
commit 5567b1dad8
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
7 changed files with 55 additions and 29 deletions

View File

@ -30,6 +30,7 @@ import lombok.Getter;
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"),
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"),
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"),

View File

@ -60,7 +60,8 @@ public class DependencyManager {
.put(StorageType.JSON, ImmutableList.of())
.put(StorageType.YAML, ImmutableList.of())
.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.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER))
.put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER))

View File

@ -107,6 +107,7 @@ public class StorageFactory {
type = defaultMethod;
}
plugin.getLog().info("Using " + type.getName() + " storage.");
storage = makeInstance(type, plugin);
}
@ -122,7 +123,9 @@ public class StorageFactory {
private static AbstractBacking makeBacking(StorageType method, LuckPermsPlugin plugin) {
switch (method) {
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:
return new SQLBacking(plugin, new SQLiteProvider(new File(plugin.getDataDirectory(), "luckperms-sqlite.db")), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
case H2:

View File

@ -30,18 +30,23 @@ import java.util.List;
public enum StorageType {
JSON("json", "flatfile"),
YAML("yaml", "yml"),
MONGODB("mongodb"),
MYSQL("mysql"),
POSTGRESQL("postgresql"),
SQLITE("sqlite"),
H2("h2");
JSON("JSON", "json", "flatfile"),
YAML("YAML", "yaml", "yml"),
MONGODB("MongoDB", "mongodb"),
MYSQL("MySQL", "mysql"),
MYSQL_LEGACY("MySQL-Legacy", "mysql-legacy"),
POSTGRESQL("PostgreSQL", "postgresql"),
SQLITE("SQLite", "sqlite"),
H2("H2", "h2");
@Getter
private final String name;
@Getter
private final List<String> identifiers;
StorageType(String... identifiers) {
StorageType(String name, String... identifiers) {
this.name = name;
this.identifiers = ImmutableList.copyOf(identifiers);
}

View File

@ -28,6 +28,7 @@ import com.google.common.collect.Iterables;
import me.lucko.luckperms.api.HeldPermission;
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.UserIdentifier;
import me.lucko.luckperms.common.core.model.Group;
@ -498,7 +499,7 @@ public class YAMLBacking extends FlatfileBacking {
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()) {
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()) {
List<String> vals = new ArrayList<>(e.getValue());

View File

@ -34,11 +34,13 @@ import java.util.concurrent.TimeUnit;
public class MySQLProvider extends SQLProvider {
private final DatastoreConfiguration configuration;
private final String driverClass;
private HikariDataSource hikari;
public MySQLProvider(DatastoreConfiguration configuration) {
super("MySQL");
public MySQLProvider(String name, String driverClass, DatastoreConfiguration configuration) {
super(name);
this.configuration = configuration;
this.driverClass = driverClass;
}
@Override
@ -57,23 +59,36 @@ public class MySQLProvider extends SQLProvider {
config.setMaximumPoolSize(configuration.getPoolSize());
config.setPoolName("luckperms");
config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
config.setDataSourceClassName(driverClass);
config.addDataSourceProperty("serverName", address);
config.addDataSourceProperty("port", port);
config.addDataSourceProperty("databaseName", database);
config.addDataSourceProperty("user", username);
config.addDataSourceProperty("password", password);
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("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("useLocalSessionState", "true");
config.addDataSourceProperty("characterEncoding", "utf8");
config.addDataSourceProperty("useUnicode", "true");
config.setUsername(username);
config.setPassword(password);
if (getName().toLowerCase().endsWith("legacy")) {
// doesn't exist on the MariaDB driver
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("alwaysSendSetIsolation", "false");
config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "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("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.
// Default is 30, but it shouldn't be taking that long.

View File

@ -43,7 +43,7 @@ public class HikariSupplier implements AutoCloseable {
hikari = new HikariDataSource();
hikari.setPoolName(poolName);
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("port", address.split(":")[1]);
hikari.addDataSourceProperty("databaseName", database);