Search in sources :

Example 1 with SQLKernelParameters

use of com.twosigma.beakerx.sql.kernel.SQLKernelParameters in project beakerx by twosigma.

the class SQLEvaluator method configureSqlEvaluator.

protected void configureSqlEvaluator(EvaluatorParameters kernelParameters) {
    SQLKernelParameters params = new SQLKernelParameters(kernelParameters);
    Optional<Collection<String>> cp = params.getClassPath();
    if (cp.isPresent()) {
        if (cp.get() == null || cp.get().isEmpty()) {
            classPath = new Classpath();
        } else {
            for (String line : cp.get()) {
                if (!line.trim().isEmpty()) {
                    classPath.add(new PathToJar(line));
                }
            }
        }
        jdbcClient.loadDrivers(classPath.getPathsAsStrings());
    }
    if (params.defaultDatasource().isPresent()) {
        this.defaultConnectionString = new ConnectionStringHolder(params.defaultDatasource().orElse(""), jdbcClient);
    }
    if (params.datasources().isPresent()) {
        this.namedConnectionString = new HashMap<>();
        Scanner sc = new Scanner(params.datasources().orElse(""));
        while (sc.hasNext()) {
            String line = sc.nextLine();
            int i = line.indexOf('=');
            if (i < 1 || i == line.length() - 1) {
                logger.warn("Error in datasource line, this line will be ignored: {}.", line);
                continue;
            }
            String name = line.substring(0, i).trim();
            String value = line.substring(i + 1).trim();
            if (value.startsWith("\"") && value.endsWith("\"")) {
                value = value.substring(1, value.length() - 1);
            }
            namedConnectionString.put(name, new ConnectionStringHolder(value, jdbcClient));
        }
    }
}
Also used : Scanner(java.util.Scanner) ClasspathScanner(com.twosigma.beakerx.autocomplete.ClasspathScanner) ConnectionStringHolder(com.twosigma.beakerx.sql.ConnectionStringHolder) Classpath(com.twosigma.beakerx.kernel.Classpath) SQLKernelParameters(com.twosigma.beakerx.sql.kernel.SQLKernelParameters) Collection(java.util.Collection) PathToJar(com.twosigma.beakerx.kernel.PathToJar)

Aggregations

ClasspathScanner (com.twosigma.beakerx.autocomplete.ClasspathScanner)1 Classpath (com.twosigma.beakerx.kernel.Classpath)1 PathToJar (com.twosigma.beakerx.kernel.PathToJar)1 ConnectionStringHolder (com.twosigma.beakerx.sql.ConnectionStringHolder)1 SQLKernelParameters (com.twosigma.beakerx.sql.kernel.SQLKernelParameters)1 Collection (java.util.Collection)1 Scanner (java.util.Scanner)1