Patch for H2
This commit is contained in:
parent
5f89964f49
commit
910ebdd5bf
@ -9,7 +9,7 @@ the generated config.yml file.
|
|||||||
```yml
|
```yml
|
||||||
DataSource:
|
DataSource:
|
||||||
# What type of database do you want to use?
|
# What type of database do you want to use?
|
||||||
# Valid values: SQLITE, MARIADB, MYSQL, POSTGRESQL
|
# Valid values: H2, SQLITE, MARIADB, MYSQL, POSTGRESQL
|
||||||
backend: SQLITE
|
backend: SQLITE
|
||||||
# Enable the database caching system, should be disabled on bungeecord environments
|
# Enable the database caching system, should be disabled on bungeecord environments
|
||||||
# or when a website integration is being used.
|
# or when a website integration is being used.
|
||||||
|
|||||||
@ -200,7 +200,7 @@ public class H2 extends AbstractSqlDataSource {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException {
|
private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException {
|
||||||
try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) {
|
try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName.toUpperCase())) {
|
||||||
return !rs.next();
|
return !rs.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -384,20 +384,22 @@ public class H2 extends AbstractSqlDataSource {
|
|||||||
* @param st Statement object to the database
|
* @param st Statement object to the database
|
||||||
*/
|
*/
|
||||||
private void addRegistrationDateColumn(Statement st) throws SQLException {
|
private void addRegistrationDateColumn(Statement st) throws SQLException {
|
||||||
st.executeUpdate("ALTER TABLE " + tableName
|
int affectedRows = st.executeUpdate("ALTER TABLE " + tableName
|
||||||
+ " ADD COLUMN IF NOT EXISTS " + col.REGISTRATION_DATE + " BIGINT NOT NULL DEFAULT '0';");
|
+ " ADD COLUMN IF NOT EXISTS " + col.REGISTRATION_DATE + " BIGINT NOT NULL DEFAULT '0';");
|
||||||
|
|
||||||
// Use the timestamp from Java to avoid timezone issues in case JVM and database are out of sync
|
// Use the timestamp from Java to avoid timezone issues in case JVM and database are out of sync
|
||||||
|
if (affectedRows != 0) {
|
||||||
long currentTimestamp = System.currentTimeMillis();
|
long currentTimestamp = System.currentTimeMillis();
|
||||||
int updatedRows = st.executeUpdate(String.format("UPDATE %s SET %s = %d;",
|
int updatedRows = st.executeUpdate(String.format("UPDATE %s SET %s = %d;",
|
||||||
tableName, col.REGISTRATION_DATE, currentTimestamp));
|
tableName, col.REGISTRATION_DATE, currentTimestamp));
|
||||||
logger.info("Created column '" + col.REGISTRATION_DATE + "' and set the current timestamp, "
|
logger.info("Created column '" + col.REGISTRATION_DATE + "' and set the current timestamp, "
|
||||||
+ currentTimestamp + ", to all " + updatedRows + " rows");
|
+ currentTimestamp + ", to all " + updatedRows + " rows");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String getJdbcUrl(String dataPath, String ignored, String database) {
|
String getJdbcUrl(String dataPath, String ignored, String database) {
|
||||||
return "jdbc:h2:" + dataPath + File.separator + database + ".db";
|
return "jdbc:h2:" + dataPath + File.separator + database;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void close(Connection con) {
|
private static void close(Connection con) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user