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

io.edurt.datacap.plugin.jdbc.cratedb.CrateDBConnection Maven / Gradle / Ivy

There is a newer version: 2024.03.9
Show newest version
package io.edurt.datacap.plugin.jdbc.cratedb;

import io.edurt.datacap.spi.connection.JdbcConfigure;
import io.edurt.datacap.spi.connection.JdbcConnection;
import io.edurt.datacap.spi.model.Response;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class CrateDBConnection
        extends JdbcConnection
{
    public CrateDBConnection(JdbcConfigure jdbcConfigure, Response response)
    {
        super(jdbcConfigure, response);
    }

    @Override
    protected String formatJdbcUrl()
    {
        JdbcConfigure jdbcConfigure = (JdbcConfigure) this.getConfigure();
        StringBuffer buffer = new StringBuffer();
        buffer.append(jdbcConfigure.getJdbcType());
        buffer.append("://");
        buffer.append(jdbcConfigure.getHost());
        buffer.append(":");
        buffer.append(jdbcConfigure.getPort());
        if (jdbcConfigure.getDatabase().isPresent()) {
            buffer.append("/");
            buffer.append(jdbcConfigure.getDatabase().get());
        }
        else {
            buffer.append("/");
        }
        if (jdbcConfigure.getEnv().isPresent()) {
            Map env = jdbcConfigure.getEnv().get();
            List flatEnv = env.entrySet()
                    .stream()
                    .map(value -> String.format("%s=%s", value.getKey(), value.getValue()))
                    .collect(Collectors.toList());
            if (env.size() > 1) {
                buffer.append("?");
            }
            buffer.append(String.join("&", flatEnv));
        }
        return buffer.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy