Skip to content

Cleanup dataSource configuring, fix hikari default values, type not case-sensitive anymore #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jetbrains.annotations.Nullable;

import java.sql.Connection;
import java.util.Locale;

public class PrismDatabaseFactory {

Expand Down Expand Up @@ -40,21 +41,21 @@ public static void createDefaultConfig(final ConfigurationSection configuration)
dataSourceProperties = dataSourceSection.createSection("properties");
}
String dataType = dataSourceSection.getString("type","mysql");
updateDataSourceProperties(dataType,dataSourceProperties);
updateDataSourceProperties(dataType, dataSourceProperties);
addDatabaseDefaults(configuration);
}

private static void updateDataSourceProperties(@Nullable final String type,
final ConfigurationSection configuration) {
String test = type;
if (test == null) {
if (test == null) {
test = "mysql";
}
switch (test) {
case "mysql":
switch (test.toUpperCase(Locale.ROOT)) {
case "MYSQL":
MySqlPrismDataSource.updateDefaultConfig(configuration);
break;
case "hikari":
case "HIKARI":
default:
SqlPrismDataSource.updateDefaultConfig(configuration);
}
Expand Down Expand Up @@ -82,44 +83,26 @@ public static PrismDataSource createDataSource(ConfigurationSection configuratio
if (configuration == null) {
return null;
}
String dataSource;
ConfigurationSection dataSourceProperties;

if (configuration.isConfigurationSection("datasource")) {
ConfigurationSection dataSourceSection = configuration.getConfigurationSection("datasource");
if (dataSourceSection != null) { //in case they didnt update the config.
dataSource = dataSourceSection.getString("type");
dataSourceProperties = dataSourceSection.getConfigurationSection("properties");
} else {
//old config style
dataSource = configuration.getString("datasource");
dataSourceProperties = configuration.getConfigurationSection("prism." + dataSource);
}
} else {
//old config style
dataSource = configuration.getString("datasource");
dataSourceProperties = configuration.getConfigurationSection("prism." + dataSource);
}
if (dataSource == null) {
return null;
}
switch (dataSource) {
case "mysql":
String dataSource = configuration.getString("datasource.type");
ConfigurationSection dataSourceProperties = configuration.getConfigurationSection("datasource.properties");
switch (dataSource.toUpperCase(Locale.ROOT)) {
case "MYSQL":
Prism.log("Attempting to configure datasource as MySQL.");
database = new MySqlPrismDataSource(dataSourceProperties);
break;
case "sqlite":
case "HIKARI":
Prism.log("Attempting to configure datasource using the Hikari parameters.");
database = new PrismHikariDataSource(dataSourceProperties);
break;
case "SQLITE":
Prism.warn("ERROR: This version of Prism no longer supports SQLite.");
break;
case "derby":
case "DERBY":
Prism.warn("ERROR: This version of Prism no longer supports Derby. Please use Hikari.");
break;
case "hikari":
Prism.log("Attempting to configure datasource using the Hikari parameters.");
database = new PrismHikariDataSource(dataSourceProperties);
break;
default:
Prism.warn("ERROR: This version of Prism does not support " + dataSource);
Prism.warn("ERROR: Prism doesn't have a rule for " + dataSource + " datasource type. Please use MySQL or Hikari.");
break;
}
return database;
Expand All @@ -134,14 +117,9 @@ public static PrismDataSourceUpdater createUpdater(ConfigurationSection configur
if (configuration == null) {
return null;
}
String dataSource = configuration.getString("type", "mysql");
if (dataSource == null) {
return null;
}
switch (dataSource) {
case "mysql":
case "derby":
case "sqlite":
switch (configuration.getString("datasource.type").toUpperCase(Locale.ROOT)) {
case "MYSQL":
case "HIKARI":
return new SqlPrismDataSourceUpdater(database);
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ public class PrismHikariDataSource extends SqlPrismDataSource {
dbConfig = new HikariConfig(propFile.getPath());
} else {
Prism.log("You may need to adjust these settings for your setup.");
Prism.log("To set a table prefix you will need to create a config entry under");
Prism.log("prism:");
Prism.log(" datasource:");
Prism.log(" prefix: your-prefix");
Prism.log("To change the table prefix you will need to edit datasource.properties.prefix entry in config.yml");
String jdbcUrl = "jdbc:mysql://localhost:3306/prism?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
Prism.log("Default jdbcUrl: " + jdbcUrl);
Prism.log("Default Username: username");
Prism.log("Default Password: password");
Prism.log("You will need to provide the required jar libraries that support your database.");
Prism.log("You may need to provide the required jar libraries(driver) that support your database.");
dbConfig = new HikariConfig();
dbConfig.setJdbcUrl(jdbcUrl);
dbConfig.setUsername("username");
dbConfig.setPassword("password");
dbConfig.setMinimumIdle(2);
dbConfig.setMaximumPoolSize(10);
HikariHelper.createPropertiesFile(propFile, dbConfig, false);
}
}
Expand All @@ -58,6 +57,9 @@ public PrismDataSource createDataSource() {
} catch (HikariPool.PoolInitializationException e) {
Prism.warn("Hikari Pool did not Initialize: " + e.getMessage());
database = null;
} catch (IllegalArgumentException e) {
Prism.warn("Hikari Pool did not Initialize: " + e);
database = null;
}
return this;

Expand Down