embulk-output-jdbc 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/classpath/embulk-output-jdbc-0.2.0.jar +0 -0
- data/src/main/java/org/embulk/output/JdbcOutputPlugin.java +28 -21
- data/src/main/java/org/embulk/output/jdbc/AbstractJdbcOutputPlugin.java +0 -21
- data/src/main/java/org/embulk/output/jdbc/JdbcOutputConnection.java +33 -13
- metadata +3 -3
- data/classpath/embulk-output-jdbc-0.1.3.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01a92a4a868446c83653516d3028fb5b423f2fdb
|
4
|
+
data.tar.gz: 1894bda08176a5ec0e9be2008d516689d3066871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bc0733eec6851d2f953fe32c703177643b21bf09e34d463af4bf876ef7525b8eeaca4070627c41e0cb595b0f875bfac60ffcc6bea18cfa8c4e4779b2f9c1302
|
7
|
+
data.tar.gz: 76ba0c713a4dcd324aae9c9d8502556a082df91b36a9708277e69a8b81a91753bd91b7d8143299bd98fb9878f8f6ad09e77634456ad6fcfff0c0066f103be049
|
Binary file
|
@@ -27,15 +27,27 @@ public class JdbcOutputPlugin
|
|
27
27
|
|
28
28
|
public interface GenericPluginTask extends PluginTask
|
29
29
|
{
|
30
|
-
@Config("
|
31
|
-
|
30
|
+
@Config("driver_path")
|
31
|
+
@ConfigDefault("null")
|
32
|
+
public Optional<String> getDriverPath();
|
32
33
|
|
33
34
|
@Config("driver_class")
|
34
35
|
public String getDriverClass();
|
35
36
|
|
36
|
-
@Config("
|
37
|
+
@Config("url")
|
38
|
+
public String getUrl();
|
39
|
+
|
40
|
+
@Config("user")
|
37
41
|
@ConfigDefault("null")
|
38
|
-
public Optional<String>
|
42
|
+
public Optional<String> getUser();
|
43
|
+
|
44
|
+
@Config("password")
|
45
|
+
@ConfigDefault("null")
|
46
|
+
public Optional<String> getPassword();
|
47
|
+
|
48
|
+
@Config("schema")
|
49
|
+
@ConfigDefault("null")
|
50
|
+
public Optional<String> getSchema();
|
39
51
|
}
|
40
52
|
|
41
53
|
@Override
|
@@ -47,11 +59,11 @@ public class JdbcOutputPlugin
|
|
47
59
|
@Override
|
48
60
|
protected GenericOutputConnector getConnector(PluginTask task, boolean retryableMetadataOperation)
|
49
61
|
{
|
50
|
-
GenericPluginTask
|
62
|
+
GenericPluginTask t = (GenericPluginTask) task;
|
51
63
|
|
52
|
-
if (
|
64
|
+
if (t.getDriverPath().isPresent()) {
|
53
65
|
synchronized (loadedJarGlobs) {
|
54
|
-
String glob =
|
66
|
+
String glob = t.getDriverPath().get();
|
55
67
|
if (!loadedJarGlobs.contains(glob)) {
|
56
68
|
loadDriverJar(glob);
|
57
69
|
loadedJarGlobs.add(glob);
|
@@ -59,23 +71,18 @@ public class JdbcOutputPlugin
|
|
59
71
|
}
|
60
72
|
}
|
61
73
|
|
62
|
-
String url;
|
63
|
-
if (g.getPort().isPresent()) {
|
64
|
-
url = String.format("jdbc:%s://%s:%d/%s",
|
65
|
-
g.getDriverName(), g.getHost(), g.getPort().get(), g.getDatabase());
|
66
|
-
} else {
|
67
|
-
url = String.format("jdbc:%s://%s/%s",
|
68
|
-
g.getDriverName(), g.getHost(), g.getDatabase());
|
69
|
-
}
|
70
|
-
|
71
74
|
Properties props = new Properties();
|
72
|
-
|
73
|
-
|
75
|
+
if (t.getUser().isPresent()) {
|
76
|
+
props.setProperty("user", t.getUser().get());
|
77
|
+
}
|
78
|
+
if (t.getPassword().isPresent()) {
|
79
|
+
props.setProperty("password", t.getPassword().get());
|
80
|
+
}
|
74
81
|
|
75
|
-
props.putAll(
|
82
|
+
props.putAll(t.getOptions());
|
76
83
|
|
77
|
-
return new GenericOutputConnector(
|
78
|
-
|
84
|
+
return new GenericOutputConnector(t.getUrl(), props, t.getDriverClass(),
|
85
|
+
t.getSchema().orNull());
|
79
86
|
}
|
80
87
|
|
81
88
|
private void loadDriverJar(String glob)
|
@@ -45,31 +45,10 @@ public abstract class AbstractJdbcOutputPlugin
|
|
45
45
|
public interface PluginTask
|
46
46
|
extends Task
|
47
47
|
{
|
48
|
-
@Config("host")
|
49
|
-
public String getHost();
|
50
|
-
|
51
|
-
@Config("port")
|
52
|
-
@ConfigDefault("null")
|
53
|
-
public Optional<Integer> getPort();
|
54
|
-
|
55
|
-
@Config("user")
|
56
|
-
public String getUser();
|
57
|
-
|
58
|
-
@Config("password")
|
59
|
-
@ConfigDefault("\"\"")
|
60
|
-
public String getPassword();
|
61
|
-
|
62
48
|
@Config("options")
|
63
49
|
@ConfigDefault("{}")
|
64
50
|
public Properties getOptions();
|
65
51
|
|
66
|
-
@Config("database")
|
67
|
-
public String getDatabase();
|
68
|
-
|
69
|
-
@Config("schema")
|
70
|
-
@ConfigDefault("null")
|
71
|
-
public Optional<String> getSchema();
|
72
|
-
|
73
52
|
@Config("table")
|
74
53
|
public String getTable();
|
75
54
|
|
@@ -52,6 +52,7 @@ public class JdbcOutputConnection
|
|
52
52
|
try {
|
53
53
|
String sql = "SET search_path TO " + quoteIdentifierString(schema);
|
54
54
|
executeUpdate(stmt, sql);
|
55
|
+
commitIfNecessary(connection);
|
55
56
|
} finally {
|
56
57
|
stmt.close();
|
57
58
|
}
|
@@ -63,10 +64,9 @@ public class JdbcOutputConnection
|
|
63
64
|
try {
|
64
65
|
String sql = String.format("DROP TABLE IF EXISTS %s", quoteIdentifierString(tableName));
|
65
66
|
executeUpdate(stmt, sql);
|
66
|
-
connection
|
67
|
+
commitIfNecessary(connection);
|
67
68
|
} catch (SQLException ex) {
|
68
|
-
connection
|
69
|
-
throw ex;
|
69
|
+
throw safeRollback(connection, ex);
|
70
70
|
} finally {
|
71
71
|
stmt.close();
|
72
72
|
}
|
@@ -78,10 +78,9 @@ public class JdbcOutputConnection
|
|
78
78
|
try {
|
79
79
|
String sql = buildCreateTableIfNotExistsSql(tableName, schema);
|
80
80
|
executeUpdate(stmt, sql);
|
81
|
-
connection
|
81
|
+
commitIfNecessary(connection);
|
82
82
|
} catch (SQLException ex) {
|
83
|
-
connection
|
84
|
-
throw ex;
|
83
|
+
throw safeRollback(connection, ex);
|
85
84
|
} finally {
|
86
85
|
stmt.close();
|
87
86
|
}
|
@@ -226,7 +225,7 @@ public class JdbcOutputConnection
|
|
226
225
|
}
|
227
226
|
String sql = buildInsertTableSql(fromTable, fromTableSchema, toTable);
|
228
227
|
executeUpdate(stmt, sql);
|
229
|
-
connection
|
228
|
+
commitIfNecessary(connection);
|
230
229
|
} catch (SQLException ex) {
|
231
230
|
connection.rollback();
|
232
231
|
throw ex;
|
@@ -276,10 +275,9 @@ public class JdbcOutputConnection
|
|
276
275
|
// }
|
277
276
|
// String sql = buildGatherInsertTables(fromTable, fromTableSchema, toTable);
|
278
277
|
// executeUpdate(stmt, sql);
|
279
|
-
// connection
|
278
|
+
// commitIfNecessary(connection);
|
280
279
|
// } catch (SQLException ex) {
|
281
|
-
// connection
|
282
|
-
// throw ex;
|
280
|
+
// throw safeRollback(connection, ex);
|
283
281
|
// } finally {
|
284
282
|
// stmt.close();
|
285
283
|
// }
|
@@ -307,10 +305,9 @@ public class JdbcOutputConnection
|
|
307
305
|
executeUpdate(stmt, sql);
|
308
306
|
}
|
309
307
|
|
310
|
-
connection
|
308
|
+
commitIfNecessary(connection);
|
311
309
|
} catch (SQLException ex) {
|
312
|
-
connection
|
313
|
-
throw ex;
|
310
|
+
throw safeRollback(connection, ex);
|
314
311
|
} finally {
|
315
312
|
stmt.close();
|
316
313
|
}
|
@@ -420,4 +417,27 @@ public class JdbcOutputConnection
|
|
420
417
|
}
|
421
418
|
return count;
|
422
419
|
}
|
420
|
+
|
421
|
+
protected void commitIfNecessary(Connection con) throws SQLException
|
422
|
+
{
|
423
|
+
if (!con.getAutoCommit()) {
|
424
|
+
con.commit();
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
protected SQLException safeRollback(Connection con, SQLException cause)
|
429
|
+
{
|
430
|
+
try {
|
431
|
+
if (!con.getAutoCommit()) {
|
432
|
+
con.rollback();
|
433
|
+
}
|
434
|
+
return cause;
|
435
|
+
} catch (SQLException ex) {
|
436
|
+
if (cause != null) {
|
437
|
+
cause.addSuppressed(ex);
|
438
|
+
return cause;
|
439
|
+
}
|
440
|
+
return ex;
|
441
|
+
}
|
442
|
+
}
|
423
443
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-jdbc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Inserts or updates records to a table.
|
14
14
|
email:
|
@@ -39,7 +39,7 @@ files:
|
|
39
39
|
- src/main/java/org/embulk/output/jdbc/setter/SqlTimestampColumnSetter.java
|
40
40
|
- src/main/java/org/embulk/output/jdbc/setter/StringColumnSetter.java
|
41
41
|
- src/test/java/org/embulk/output/TestJdbcOutputPlugin.java
|
42
|
-
- classpath/embulk-output-jdbc-0.
|
42
|
+
- classpath/embulk-output-jdbc-0.2.0.jar
|
43
43
|
homepage: https://github.com/embulk/embulk-output-jdbc
|
44
44
|
licenses:
|
45
45
|
- Apache 2.0
|
Binary file
|