Repository: incubator-beam
Updated Branches:
  refs/heads/master 6d0c205a3 -> 3e4b2fd0d


[BEAM-959] Improve validation messages in JdbcIO


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/7b314aad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/7b314aad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/7b314aad

Branch: refs/heads/master
Commit: 7b314aad1c7c62ad61e09e610c60f53ac056d75d
Parents: 6d0c205
Author: Jean-Baptiste Onofré <jbono...@apache.org>
Authored: Thu Nov 17 17:07:21 2016 +0100
Committer: Jean-Baptiste Onofré <jbono...@apache.org>
Committed: Thu Nov 24 08:50:01 2016 +0100

----------------------------------------------------------------------
 .../org/apache/beam/sdk/io/jdbc/JdbcIO.java     | 52 +++++++++++++-------
 1 file changed, 35 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/7b314aad/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
----------------------------------------------------------------------
diff --git 
a/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java 
b/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
index 0e0703f..9644a65 100644
--- a/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
+++ b/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java
@@ -18,7 +18,7 @@
 package org.apache.beam.sdk.io.jdbc;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
 
 import com.google.auto.value.AutoValue;
 
@@ -183,16 +183,20 @@ public class JdbcIO {
     }
 
     public static DataSourceConfiguration create(DataSource dataSource) {
-      checkNotNull(dataSource, "dataSource");
-      checkArgument(dataSource instanceof Serializable, "dataSource must be 
Serializable");
+      checkArgument(dataSource != null, 
"DataSourceConfiguration.create(dataSource) called with "
+          + "null data source");
+      checkArgument(dataSource instanceof Serializable,
+          "DataSourceConfiguration.create(dataSource) called with a dataSource 
not Serializable");
       return new AutoValue_JdbcIO_DataSourceConfiguration.Builder()
           .setDataSource(dataSource)
           .build();
     }
 
     public static DataSourceConfiguration create(String driverClassName, 
String url) {
-      checkNotNull(driverClassName, "driverClassName");
-      checkNotNull(url, "url");
+      checkArgument(driverClassName != null,
+          "DataSourceConfiguration.create(driverClassName, url) called with 
null driverClassName");
+      checkArgument(url != null,
+          "DataSourceConfiguration.create(driverClassName, url) called with 
null url");
       return new AutoValue_JdbcIO_DataSourceConfiguration.Builder()
           .setDriverClassName(driverClassName)
           .setUrl(url)
@@ -263,27 +267,31 @@ public class JdbcIO {
     }
 
     public Read<T> withDataSourceConfiguration(DataSourceConfiguration 
configuration) {
-      checkNotNull(configuration, "configuration");
+      checkArgument(configuration != null, 
"JdbcIO.read().withDataSourceConfiguration"
+          + "(configuration) called with null configuration");
       return toBuilder().setDataSourceConfiguration(configuration).build();
     }
 
     public Read<T> withQuery(String query) {
-      checkNotNull(query, "query");
+      checkArgument(query != null, "JdbcIO.read().withQuery(query) called with 
null query");
       return toBuilder().setQuery(query).build();
     }
 
     public Read<T> withStatementPrepator(StatementPreparator 
statementPreparator) {
-      checkNotNull(statementPreparator, "statementPreparator");
+      checkArgument(statementPreparator != null,
+          "JdbcIO.read().withStatementPreparator(statementPreparator) called "
+              + "with null statementPreparator");
       return toBuilder().setStatementPreparator(statementPreparator).build();
     }
 
     public Read<T> withRowMapper(RowMapper<T> rowMapper) {
-      checkNotNull(rowMapper, "rowMapper");
+      checkArgument(rowMapper != null,
+          "JdbcIO.read().withRowMapper(rowMapper) called with null rowMapper");
       return toBuilder().setRowMapper(rowMapper).build();
     }
 
     public Read<T> withCoder(Coder<T> coder) {
-      checkNotNull(coder, "coder");
+      checkArgument(coder != null, "JdbcIO.read().withCoder(coder) called with 
null coder");
       return toBuilder().setCoder(coder).build();
     }
 
@@ -314,10 +322,15 @@ public class JdbcIO {
 
     @Override
     public void validate(PBegin input) {
-      checkNotNull(getQuery(), "query");
-      checkNotNull(getRowMapper(), "rowMapper");
-      checkNotNull(getCoder(), "coder");
-      checkNotNull(getDataSourceConfiguration());
+      checkState(getQuery() != null,
+          "JdbcIO.read() requires a query to be set via withQuery(query)");
+      checkState(getRowMapper() != null,
+          "JdbcIO.read() requires a rowMapper to be set via 
withRowMapper(rowMapper)");
+      checkState(getCoder() != null,
+          "JdbcIO.read() requires a coder to be set via withCoder(coder)");
+      checkState(getDataSourceConfiguration() != null,
+          "JdbcIO.read() requires a DataSource configuration to be set via "
+              + "withDataSourceConfiguration(dataSourceConfiguration)");
     }
 
     @Override
@@ -411,9 +424,14 @@ public class JdbcIO {
 
     @Override
     public void validate(PCollection<T> input) {
-      checkNotNull(getDataSourceConfiguration(), "dataSourceConfiguration");
-      checkNotNull(getStatement(), "statement");
-      checkNotNull(getPreparedStatementSetter(), "preparedStatementSetter");
+      checkArgument(getDataSourceConfiguration() != null,
+          "JdbcIO.write() requires a configuration to be set via "
+              + ".withDataSourceConfiguration(configuration)");
+      checkArgument(getStatement() != null,
+          "JdbcIO.write() requires a statement to be set via 
.withStatement(statement)");
+      checkArgument(getPreparedStatementSetter() != null,
+          "JdbcIO.write() requires a preparedStatementSetter to be set via "
+              + ".withPreparedStatementSetter(preparedStatementSetter)");
     }
 
     private static class WriteFn<T> extends DoFn<T, Void> {

Reply via email to