Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdraves committed Jun 18, 2018
2 parents ecef5f7 + ad62b91 commit 27ba9fa
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Logger;


public class SQL extends Kernel {
private final static Logger logger = Logger.getLogger(SQL.class.getName());

private SQL(String sessionId, Evaluator evaluator, KernelSocketsFactory kernelSocketsFactory) {
super(sessionId, evaluator, kernelSocketsFactory, new SQLCustomMagicCommandsImpl());
Expand All @@ -67,22 +70,52 @@ public KernelHandler<Message> getKernelInfoHandler(Kernel kernel) {
return new SQLKernelInfoHandler(kernel);
}




public static void main(final String[] args) throws InterruptedException, IOException {
KernelRunner.run(() -> {
String id = uuid();
KernelSocketsFactoryImpl kernelSocketsFactory = new KernelSocketsFactoryImpl(
new KernelConfigurationFile(args));
SQLEvaluator evaluator = new SQLEvaluator(id, id, getKernelParameters());
EvaluatorParameters params = getKernelParameters();
SQLEvaluator evaluator = new SQLEvaluator(id, id, params);
evaluator.setShellOptions(params);
return new SQL(id, evaluator, kernelSocketsFactory);
});
}

private static EvaluatorParameters getKernelParameters() {
HashMap<String, Object> kernelParameters = new HashMap<>();
kernelParameters.put(IMPORTS, new DefaultJVMVariables().getImports());
String uri = getDefaultConnectionString();
if (uri != null) {
logger.info("Setting default connection string to " + uri);
kernelParameters.put("%defaultDatasource", uri);
}
// "{%defaultDatasource=jdbc:trysettingitbydefault}"
return new EvaluatorParameters(kernelParameters);
}

private static String getDefaultConnectionString() {
String uri = System.getenv("BEAKER_JDBC_DEFAULT_CONNECTION");

if (uri != null && uri.contains("jdbc:")) {
return uri;
}
else if (uri != null)
{
logger.warning("Ignoring incorrectly formatted BEAKER_JDBC_DEFAULT_CONNECTION: " + uri);
return null;
}
else
{
return null;
}

}


static class SQLCustomMagicCommandsImpl implements CustomMagicCommandsFactory {
@Override
public List<MagicCommandType> customMagicCommands(KernelFunctionality kernel) {
Expand Down

0 comments on commit 27ba9fa

Please sign in to comment.