Search in sources :

Example 11 with DataStoreType

use of jgnash.engine.DataStoreType in project jgnash by ccavanaugh.

the class BootEngineTask method checkAndBackupOldVersion.

/**
     * Check and determine if the file is an old format and backup in necessary.
     *
     * @param fileName fileName to verify
     * @param password assumed password
     * @return true if no errors are encountered
     */
private static boolean checkAndBackupOldVersion(final String fileName, final char[] password) {
    boolean result = false;
    if (Files.exists(Paths.get(fileName))) {
        final float version = EngineFactory.getFileVersion(Paths.get(fileName), password);
        final DataStoreType type = EngineFactory.getDataStoreByType(fileName);
        boolean oldSchema = false;
        if (type == DataStoreType.H2_DATABASE || type == DataStoreType.HSQL_DATABASE) {
            oldSchema = SqlUtils.useOldPersistenceUnit(fileName, password);
        }
        if (type == DataStoreType.H2_DATABASE && oldSchema) {
            Platform.runLater(() -> StaticUIMethods.displayMessage(ResourceUtils.getString("Message.Info.LongUpgrade")));
            final PackDatabaseTask packDatabaseTask = new PackDatabaseTask(fileName, password);
            new Thread(packDatabaseTask).start();
            Platform.runLater(() -> StaticUIMethods.displayTaskProgress(packDatabaseTask));
            try {
                // block until complete
                packDatabaseTask.get();
            } catch (final InterruptedException | ExecutionException e) {
                Logger.getLogger(BootEngineTask.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        }
        if (type == DataStoreType.HSQL_DATABASE && oldSchema) {
            final String errorMessage = ResourceUtils.getString("Message.Error.OldHsqlFile");
            Platform.runLater(() -> StaticUIMethods.displayError(errorMessage));
        } else if (version <= 0) {
            final String errorMessage = ResourceUtils.getString("Message.Error.InvalidUserPass");
            Platform.runLater(() -> StaticUIMethods.displayError(errorMessage));
        } else {
            result = true;
            // make a versioned backup first
            if (version < Engine.CURRENT_VERSION) {
                FileUtils.copyFile(Paths.get(fileName), Paths.get(fileName + "." + version));
                Platform.runLater(() -> StaticUIMethods.displayMessage(ResourceUtils.getString("Message.Info.Upgrade", fileName + "." + version)));
            }
        }
    }
    return result;
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) DataStoreType(jgnash.engine.DataStoreType)

Example 12 with DataStoreType

use of jgnash.engine.DataStoreType in project jgnash by ccavanaugh.

the class NewFileOne method getSettings.

@Override
public void getSettings(Map<Enum<?>, Object> map) {
    DataStoreType type = (DataStoreType) map.get(NewFileDialog.Settings.TYPE);
    if (type != null) {
        typeCombo.setSelectedItem(type);
    }
    String fileName = (String) map.get(NewFileDialog.Settings.DATABASE_NAME);
    if (FileUtils.fileHasExtension(fileName)) {
        dbNameField.setText(fileName);
    } else {
        dbNameField.setText(fileName + typeCombo.getSelectedDataStoreType().getDataStore().getFileExt());
    }
    checkForOverwrite();
}
Also used : DataStoreType(jgnash.engine.DataStoreType)

Aggregations

DataStoreType (jgnash.engine.DataStoreType)12 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)5 Properties (java.util.Properties)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)3 ResourceBundle (java.util.ResourceBundle)3 DatabaseMetaData (java.sql.DatabaseMetaData)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 Preferences (java.util.prefs.Preferences)2 SwingWorker (javax.swing.SwingWorker)2 File (java.io.File)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Statement (java.sql.Statement)1 Set (java.util.Set)1