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

liquibase.sdk.supplier.database.DatabaseSupplier Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package liquibase.sdk.supplier.database;

import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.OfflineConnection;
import liquibase.database.jvm.JdbcConnection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;

public class DatabaseSupplier {

    private HashSet allDatabases;

    public Set getAllDatabases() {
        if (allDatabases == null) {
            allDatabases = new HashSet(DatabaseFactory.getInstance().getImplementedDatabases());

            for (Database database : allDatabases) {
                ConnectionConfigurationFactory configurationFactory = ConnectionConfigurationFactory.getInstance();
                for (ConnectionSupplier connectionSupplier : configurationFactory.getConfigurations(database)) {
                    try {
                        Connection connection = connectionSupplier.openConnection();
                        database.setConnection(new JdbcConnection(connection));
                        break;
                    } catch (SQLException e) {
                        System.out.println("Cannot connect to "+connectionSupplier.getJdbcUrl());
                        database.setConnection(new OfflineConnection("offline:"+database.getShortName()));
                    }
                }
            }
        }
        return allDatabases;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy