Added connection test when creating any data source now.
This commit is contained in:
parent
54f6612048
commit
64c46e6be9
|
@ -59,7 +59,11 @@ public class JdbcDataSourceFactory implements DataSourceFactory {
|
||||||
throw new ProfileLoadException("Profile " + profileName + " has a database with an unsupported schema version.");
|
throw new ProfileLoadException("Profile " + profileName + " has a database with an unsupported schema version.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new JdbcDataSource(getJdbcUrl(profileName), Profile.getContentDir(profileName));
|
var dataSource = new JdbcDataSource(getJdbcUrl(profileName), Profile.getContentDir(profileName));
|
||||||
|
if (!testConnection(dataSource)) {
|
||||||
|
throw new ProfileLoadException("Unabled to connect to the profile's database.");
|
||||||
|
}
|
||||||
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SchemaStatus getSchemaStatus(String profileName) throws IOException {
|
public SchemaStatus getSchemaStatus(String profileName) throws IOException {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -50,6 +51,8 @@ public class ProfileLoader {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ProfileLoadException("Failed to load profile settings.", e);
|
throw new ProfileLoadException("Failed to load profile settings.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to check the profile's schema version and migrate if needed.
|
||||||
try {
|
try {
|
||||||
DataSourceFactory.SchemaStatus status = dataSourceFactory.getSchemaStatus(name);
|
DataSourceFactory.SchemaStatus status = dataSourceFactory.getSchemaStatus(name);
|
||||||
if (status == DataSourceFactory.SchemaStatus.NEEDS_MIGRATION) {
|
if (status == DataSourceFactory.SchemaStatus.NEEDS_MIGRATION) {
|
||||||
|
@ -72,11 +75,14 @@ public class ProfileLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a recent backup and make one if not present.
|
// Check for a recent backup and make one if not present.
|
||||||
try {
|
LocalDateTime lastBackup = ProfileBackups.getLastBackupTimestamp(name);
|
||||||
ProfileBackups.makeBackup(name);
|
if (lastBackup == null || lastBackup.isBefore(LocalDateTime.now().minusDays(1))) {
|
||||||
ProfileBackups.cleanOldBackups(name);
|
try {
|
||||||
} catch (IOException e) {
|
ProfileBackups.makeBackup(name);
|
||||||
log.error("Failed to create backup for profile " + name + ".", e);
|
ProfileBackups.cleanOldBackups(name);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Failed to create backup for profile " + name + ".", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSource dataSource = dataSourceFactory.getDataSource(name);
|
DataSource dataSource = dataSourceFactory.getDataSource(name);
|
||||||
|
|
Loading…
Reference in New Issue