Skip to content

Commit

Permalink
Merge pull request #14 from twosigma/jarek/10_bx_driver_manager
Browse files Browse the repository at this point in the history
jarek/kernel_base_10: add BxDriverManager
  • Loading branch information
ildipo authored Jul 17, 2020
2 parents c31960a + 4a3a890 commit dab2cee
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Optional;

import static java.util.Arrays.asList;

public class RuntimetoolsImpl implements Runtimetools {

public void configRuntimeJars(KernelFunctionality kernel) {
// kernel.addJarsToClasspath(Arrays.asList(new PathToJar(getJar("runtimetools"))));
// kernel.addImport(new ImportPath("com.twosigma.beakerx.BxDriverManager"));
public void configRuntimeJars(KernelFunctionality kernel) {
Optional<String> runtimetools = getJar("runtimetools");
if (runtimetools.isPresent()) {
kernel.addJarsToClasspath(asList(new PathToJar(runtimetools.get())));
kernel.addImport(new ImportPath("com.twosigma.beakerx.BxDriverManager"));
}
}

private String getJar(String name) {
private Optional<String> getJar(String name) {
try {
Path path = Paths.get(KernelFunctionality.class.getProtectionDomain().getCodeSource().getLocation().toURI());
return path.getParent().getParent().getParent().resolve(name).resolve("lib").resolve(name + ".jar").toString();
Path location = path.getParent().getParent().getParent().resolve("kernel").resolve("ext");
if (location.toFile().exists()) {
Optional<String> jarFile = Arrays.stream(location.toFile().list()).filter(jar -> jar.contains(name)).findFirst();
return jarFile.map(s -> location.resolve(s).toString());
} else {
return Optional.empty();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
32 changes: 32 additions & 0 deletions runtimetools/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2020 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}


publishing {
publications {
maven(MavenPublication) {
groupId 'com.twosigma'
artifactId 'beakerx-runtimetools'
version "$beakerxVersion"
from components.java
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.twosigma.beakerx;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;

public class BxDriverManager {

public static Connection getConnection(String url) throws SQLException {
return DriverManager.getConnection(url);
}

public static Connection getConnection(String url, String user, String password) throws SQLException {
return DriverManager.getConnection(url, user, password);
}

public static Connection getConnection(String url, java.util.Properties info) throws SQLException {
return DriverManager.getConnection(url, info);
}

public static Driver getDriver(String url) throws SQLException {
return DriverManager.getDriver(url);
}

public static java.util.Enumeration<Driver> getDrivers() {
return DriverManager.getDrivers();
}

public static synchronized void registerDriver(Driver driver) throws SQLException {
DriverManager.registerDriver(driver);
}

public static synchronized void deregisterDriver(Driver driver) throws SQLException {
DriverManager.deregisterDriver(driver);
}

}
5 changes: 4 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ include 'doclet'
include 'base-api'
include 'base-test'
include 'base'
include 'runtimetools'

// uncomment when demo projects have to be rebuild
//include 'demoProjects'
//include 'demoProjects:loadMagicJarDemo'
//include 'demoProjects:demo'
//include 'demoProjects:BeakerXClasspathTest'
//include 'demoProjects:BeakerXClasspathTest'


0 comments on commit dab2cee

Please sign in to comment.