Search in sources :

Example 1 with ConverterType

use of dev.rosewood.rosestacker.conversion.ConverterType in project RoseStacker by Rosewood-Development.

the class DataManager method setConversionHandlers.

public void setConversionHandlers(Set<ConverterType> converterTypes) {
    this.databaseConnector.connect(connection -> {
        String insertIgnore;
        if (this.databaseConnector instanceof SQLiteConnector) {
            insertIgnore = "INSERT OR IGNORE INTO ";
        } else {
            insertIgnore = "INSERT IGNORE ";
        }
        String query = insertIgnore + this.getTablePrefix() + "convert_handler (name) VALUES (?)";
        try (PreparedStatement statement = connection.prepareStatement(query)) {
            for (ConverterType converterType : converterTypes) {
                statement.setString(1, converterType.name());
                statement.addBatch();
            }
            statement.executeBatch();
        }
    });
}
Also used : SQLiteConnector(dev.rosewood.rosegarden.database.SQLiteConnector) PreparedStatement(java.sql.PreparedStatement) ConverterType(dev.rosewood.rosestacker.conversion.ConverterType)

Example 2 with ConverterType

use of dev.rosewood.rosestacker.conversion.ConverterType in project RoseStacker by Rosewood-Development.

the class DataManager method getConversionHandlers.

public Set<ConverterType> getConversionHandlers() {
    Set<ConverterType> conversionHandlers = EnumSet.noneOf(ConverterType.class);
    this.databaseConnector.connect(connection -> {
        String query = "SELECT name FROM " + this.getTablePrefix() + "convert_handler";
        try (Statement statement = connection.createStatement()) {
            ResultSet result = statement.executeQuery(query);
            while (result.next()) {
                ConverterType converterType = ConverterType.get(result.getString(1));
                if (converterType != null)
                    conversionHandlers.add(converterType);
            }
        }
    });
    return conversionHandlers;
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ConverterType(dev.rosewood.rosestacker.conversion.ConverterType)

Aggregations

ConverterType (dev.rosewood.rosestacker.conversion.ConverterType)2 PreparedStatement (java.sql.PreparedStatement)2 SQLiteConnector (dev.rosewood.rosegarden.database.SQLiteConnector)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1