embulk-input-jdbc 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 448f952857706e80263b5b4fb0fd0a0afb0bc932
4
- data.tar.gz: 394b0a3d874564fa7c10e8141f157bc2b71486e6
3
+ metadata.gz: debd726a2754ee5ffa81e8b0a19b6f0962edf7e0
4
+ data.tar.gz: 4fa93d96dc225cf41687ee60b29b4d9d17fc9622
5
5
  SHA512:
6
- metadata.gz: 1a0ba32aa3c9ac2169130102fe85eb841c1da236a062a2bff9dcdc4196282d5237a1705261250c52f3234dfb279017dbb47e972325396abfceb685b3bc0b56d4
7
- data.tar.gz: 174d493cad631c3bb15cf475ee7aa77aee4db10a4b40cc8350c4b31732517c54410110bafafe8454d3d52f4d364bd5df3571704ddbe3670db7a67be6c86cc880
6
+ metadata.gz: 068f25c21264c1d42cdc1634a3b3a61da127d8e0e859c8cdfeeebb20aa1d35eebd716495dd09ab2903e7d06722bf107a21b911a1c43337f35502f7c0768df928
7
+ data.tar.gz: d7c1829e071c1123b8877ff22679c4a51f3bf59eaca512620e685690012ce976b3e41ed6a958837f0cf09be8dcbfed2c408ccf0728354b4411febb0a701a784d
@@ -1,5 +1,10 @@
1
1
  package org.embulk.input.jdbc;
2
2
 
3
+ import java.io.File;
4
+ import java.io.FileFilter;
5
+ import java.net.MalformedURLException;
6
+ import java.net.URISyntaxException;
7
+ import java.net.URL;
3
8
  import java.nio.file.Path;
4
9
  import java.util.List;
5
10
  import java.util.Map;
@@ -14,7 +19,6 @@ import com.google.common.base.Optional;
14
19
  import com.google.common.base.Supplier;
15
20
  import com.google.common.base.Throwables;
16
21
  import com.google.common.collect.ImmutableList;
17
- import com.google.common.collect.ImmutableMap;
18
22
 
19
23
  import org.embulk.config.Config;
20
24
  import org.embulk.config.ConfigException;
@@ -583,6 +587,43 @@ public abstract class AbstractJdbcInputPlugin
583
587
  // }
584
588
  //}
585
589
 
590
+ protected void loadDriver(String className, Optional<String> driverPath)
591
+ {
592
+ if (driverPath.isPresent()) {
593
+ addDriverJarToClasspath(driverPath.get());
594
+ } else {
595
+ try {
596
+ // Gradle test task will add JDBC driver to classpath
597
+ Class.forName(className);
598
+
599
+ } catch (ClassNotFoundException ex) {
600
+ File root = findPluginRoot();
601
+ File driverLib = new File(root, "default_jdbc_driver");
602
+ File[] files = driverLib.listFiles(new FileFilter() {
603
+ @Override
604
+ public boolean accept(File file) {
605
+ return file.isFile() && file.getName().endsWith(".jar");
606
+ }
607
+ });
608
+ if (files == null || files.length == 0) {
609
+ throw new RuntimeException("Cannot find JDBC driver in '" + root.getAbsolutePath() + "'.");
610
+ } else {
611
+ for (File file : files) {
612
+ logger.info("JDBC Driver = " + file.getAbsolutePath());
613
+ addDriverJarToClasspath(file.getAbsolutePath());
614
+ }
615
+ }
616
+ }
617
+ }
618
+
619
+ // Load JDBC Driver
620
+ try {
621
+ Class.forName(className);
622
+ } catch (ClassNotFoundException ex) {
623
+ throw new RuntimeException(ex);
624
+ }
625
+ }
626
+
586
627
  protected void addDriverJarToClasspath(String glob)
587
628
  {
588
629
  // TODO match glob
@@ -593,4 +634,28 @@ public abstract class AbstractJdbcInputPlugin
593
634
  }
594
635
  loader.addPath(Paths.get(glob));
595
636
  }
637
+
638
+ protected File findPluginRoot()
639
+ {
640
+ try {
641
+ URL url = getClass().getResource("/" + getClass().getName().replace('.', '/') + ".class");
642
+ if (url.toString().startsWith("jar:")) {
643
+ url = new URL(url.toString().replaceAll("^jar:", "").replaceAll("![^!]*$", ""));
644
+ }
645
+
646
+ File folder = new File(url.toURI()).getParentFile();
647
+ for (;; folder = folder.getParentFile()) {
648
+ if (folder == null) {
649
+ throw new RuntimeException("Cannot find 'embulk-input-xxx' folder.");
650
+ }
651
+
652
+ if (folder.getName().startsWith("embulk-input-")) {
653
+ return folder;
654
+ }
655
+ }
656
+ } catch (MalformedURLException | URISyntaxException e) {
657
+ throw new RuntimeException(e);
658
+ }
659
+ }
660
+
596
661
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-23 00:00:00.000000000 Z
11
+ date: 2017-07-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Selects records from a table.
14
14
  email:
@@ -19,7 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - build.gradle
22
- - classpath/embulk-input-jdbc-0.8.4.jar
22
+ - classpath/embulk-input-jdbc-0.8.5.jar
23
23
  - lib/embulk/input/jdbc.rb
24
24
  - src/main/java/org/embulk/input/JdbcInputPlugin.java
25
25
  - src/main/java/org/embulk/input/jdbc/AbstractJdbcInputPlugin.java