All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.enioka.jqm.model.updater.cli.DbUpdateVerb Maven / Gradle / Ivy

The newest version!
package com.enioka.jqm.model.updater.cli;

import java.sql.SQLException;
import java.util.Properties;
import java.util.ServiceLoader;

import org.kohsuke.MetaInfServices;

import com.beust.jcommander.Parameters;
import com.enioka.jqm.cli.api.CommandBase;
import com.enioka.jqm.jdbc.Db;
import com.enioka.jqm.jdbc.DbManager;
import com.enioka.jqm.model.updater.DbSchemaManager;
import com.enioka.jqm.shared.services.ServiceLoaderHelper;

@MetaInfServices(CommandBase.class)
@Parameters(commandNames = "Update-Schema", commandDescription = "Updates the database schema.")
public class DbUpdateVerb extends CommandBase
{
    @Override
    public int doWork()
    {
        var dbSchemaManager = ServiceLoaderHelper.getService(ServiceLoader.load(DbSchemaManager.class));
        Properties properties = new Properties();
        properties.put("com.enioka.jqm.jdbc.waitForConnectionValid", "true");
        properties.put("com.enioka.jqm.jdbc.waitForSchemaValid", "false");

        Db db = DbManager.getDb(properties);
        try (var cnx = db.getDataSource().getConnection())
        {
            dbSchemaManager.updateSchema(cnx);
            return 0;
        }
        catch (SQLException e)
        {
            jqmlogger.error("Could not upgrade database schema", e);
            return 1;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy