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

migratedb.v1.commandline.driversupport.PostgreSQLDriverSupport Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package migratedb.v1.commandline.driversupport;

import com.google.auto.service.AutoService;
import migratedb.v1.commandline.DriverSupport;
import migratedb.v1.core.internal.util.Development;

import java.util.Map;
import java.util.Properties;

@AutoService(DriverSupport.class)
public class PostgreSQLDriverSupport  implements DriverSupport {
    @Override
    public String getName() {
        return "PostgreSQL";
    }

    @Override
    public boolean handlesJdbcUrl(String url) {
        return url.startsWith("jdbc:postgresql:") || url.startsWith("jdbc:p6spy:postgresql:");
    }

    @Override
    public String getDriverClass(String url, ClassLoader classLoader) {

        if (url.startsWith("jdbc:p6spy:postgresql:")) {
            return "com.p6spy.engine.spy.P6SpyDriver";
        }
        return "org.postgresql.Driver";
    }


    @Override
    public void modifyDefaultConnectionProps(String url, Properties props, ClassLoader classLoader) {
        props.put("applicationName", APPLICATION_NAME);
    }

    @Override
    public boolean detectUserRequiredByUrl(String url) {
        return !url.contains("user=");
    }

    @Override
    public boolean detectPasswordRequiredByUrl(String url) {
        // Postgres supports password in URL
        return !url.contains("password=");
    }

    @Override
    public boolean externalAuthPropertiesRequired(String url, String username, String password) {
        return DriverSupport.super.externalAuthPropertiesRequired(url, username, password);
    }

    @Override
    public Map getExternalAuthProperties(String url, String username) {
        PgpassFileReader pgpassFileReader = new PgpassFileReader();
        if (pgpassFileReader.getPgpassFilePath() != null) {
            Development.TODO("Support PGPASSFILE password file");
        }
        return DriverSupport.super.getExternalAuthProperties(url, username);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy