sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cheol...@apache.org
Subject git commit: SQOOP-774: exception is thrown when creating a connection object if connectionString starts with an empty space
Date Mon, 17 Dec 2012 19:53:46 GMT
Updated Branches:
  refs/heads/sqoop2 4c10a3173 -> 649178222


SQOOP-774: exception is thrown when creating a connection object if
connectionString starts with an empty space

(Jarek Jarcec Cecho via Cheolsoo Park)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/64917822
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/64917822
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/64917822

Branch: refs/heads/sqoop2
Commit: 649178222589b3abe38d96224edc3c5855d4d8e3
Parents: 4c10a31
Author: Cheolsoo Park <cheolsoo@apache.org>
Authored: Mon Dec 17 11:53:10 2012 -0800
Committer: Cheolsoo Park <cheolsoo@apache.org>
Committed: Mon Dec 17 11:53:10 2012 -0800

----------------------------------------------------------------------
 .../java/org/apache/sqoop/json/ValidationBean.java |   12 +-
 .../java/org/apache/sqoop/model/FormUtils.java     |    8 +-
 .../org/apache/sqoop/validation/Validation.java    |   85 +++++++++++++--
 .../apache/sqoop/validation/ValidationError.java   |    1 +
 .../org/apache/sqoop/json/TestValidationBean.java  |   25 +++--
 .../java/org/apache/sqoop/model/TestFormUtils.java |   14 ++-
 .../sqoop/connector/jdbc/GenericJdbcValidator.java |    3 +-
 7 files changed, 114 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/64917822/common/src/main/java/org/apache/sqoop/json/ValidationBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/ValidationBean.java b/common/src/main/java/org/apache/sqoop/json/ValidationBean.java
index 1ad8186..747a228 100644
--- a/common/src/main/java/org/apache/sqoop/json/ValidationBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/ValidationBean.java
@@ -94,9 +94,9 @@ public class ValidationBean implements JsonBean {
     object.put(STATUS, validation.getStatus().name());
 
     JSONObject jsonMessages = new JSONObject();
-    Map<String, Validation.Message> messages = validation.getMessages();
+    Map<Validation.FormInput, Validation.Message> messages = validation.getMessages();
 
-    for(Map.Entry<String, Validation.Message> entry : messages.entrySet()) {
+    for(Map.Entry<Validation.FormInput, Validation.Message> entry : messages.entrySet())
{
       JSONObject jsonEntry = new JSONObject();
       jsonEntry.put(STATUS, entry.getValue().getStatus().name());
       jsonEntry.put(MESSAGE, entry.getValue().getMessage());
@@ -121,8 +121,8 @@ public class ValidationBean implements JsonBean {
 
   public Validation restoreValidation(JSONObject jsonObject) {
     JSONObject jsonMessages = (JSONObject) jsonObject.get(MESSAGES);
-    Map<String, Validation.Message> messages
-      = new HashMap<String, Validation.Message>();
+    Map<Validation.FormInput, Validation.Message> messages
+      = new HashMap<Validation.FormInput, Validation.Message>();
 
     for(Object key : jsonMessages.keySet()) {
       JSONObject jsonMessage = (JSONObject) jsonMessages.get(key);
@@ -133,11 +133,11 @@ public class ValidationBean implements JsonBean {
       Validation.Message message
         = new Validation.Message(status, stringMessage);
 
-      messages.put((String)key, message);
+      messages.put(new Validation.FormInput((String)key), message);
     }
 
     Status status = Status.valueOf((String) jsonObject.get(STATUS));
 
-    return new Validation(status,messages);
+    return new Validation(status, messages);
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/64917822/common/src/main/java/org/apache/sqoop/model/FormUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/FormUtils.java b/common/src/main/java/org/apache/sqoop/model/FormUtils.java
index 05941f6..585d02e 100644
--- a/common/src/main/java/org/apache/sqoop/model/FormUtils.java
+++ b/common/src/main/java/org/apache/sqoop/model/FormUtils.java
@@ -255,13 +255,13 @@ public class FormUtils {
    * @param validation Validation that we should apply
    */
   public static void applyValidation(List<MForm> forms, Validation validation) {
-    Map<String, Validation.Message> messages = validation.getMessages();
+    Map<Validation.FormInput, Validation.Message> messages = validation.getMessages();
 
     for(MForm form : forms) {
       for(MInput input : form.getInputs()) {
-        String inputName = input.getName();
-        if(messages.containsKey(inputName)){
-          Validation.Message message = messages.get(inputName);
+        Validation.FormInput fi = new Validation.FormInput(input.getName());
+        if(messages.containsKey(fi)) {
+          Validation.Message message = messages.get(fi);
 
           input.setValidationMessage(message.getStatus(), message.getMessage());
         } else {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/64917822/common/src/main/java/org/apache/sqoop/validation/Validation.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/validation/Validation.java b/common/src/main/java/org/apache/sqoop/validation/Validation.java
index e4398b6..ddc1d9e 100644
--- a/common/src/main/java/org/apache/sqoop/validation/Validation.java
+++ b/common/src/main/java/org/apache/sqoop/validation/Validation.java
@@ -19,6 +19,7 @@ package org.apache.sqoop.validation;
 
 import org.apache.sqoop.common.SqoopException;
 
+import java.lang.reflect.Field;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -34,7 +35,7 @@ public class Validation {
   Status status;
 
   // Status messages for various fields
-  Map<String, Message> messages;
+  Map<FormInput, Message> messages;
 
   private Validation() {
     klass = null;
@@ -44,9 +45,9 @@ public class Validation {
 
     this.klass = klass;
     status = Status.getDefault();
-    messages = new HashMap<String, Message>();
+    messages = new HashMap<FormInput, Message>();
   }
-  public Validation(Status status, Map<String, Message> messages) {
+  public Validation(Status status, Map<FormInput, Message> messages) {
     this();
 
     this.status = status;
@@ -57,25 +58,35 @@ public class Validation {
     return status;
   }
 
-  public Map<String, Message> getMessages() {
+  public Map<FormInput, Message> getMessages() {
     return messages;
   }
 
-  public void addMessage(Status status, String field, String message ) {
+  public void addMessage(Status status, String form, String field, String message ) {
     if( klass == null) {
       throw new SqoopException(ValidationError.VALIDATION_0001);
     }
 
-    // Verify that this is valid field in configuration object
+    Field formField;
+
+    // Verify that such form exists
+    try {
+      formField = klass.getDeclaredField(form);
+    } catch (NoSuchFieldException e) {
+      throw new SqoopException(ValidationError.VALIDATION_0002,
+        "Can't get form " + form + " from " + klass.getName(), e);
+    }
+
+    // Verify that such input exists on given form
     try {
-      klass.getDeclaredField(field);
+      formField.getType().getDeclaredField(field);
     } catch (NoSuchFieldException e) {
       throw new SqoopException(ValidationError.VALIDATION_0002,
-        "Field " + field + " is not present in " + klass.getName());
+        "Can't get input " + field + " from form" + formField.getType().getName(), e);
     }
 
     this.status = Status.getWorstStatus(this.status, status);
-    messages.put(field, new Message(status, message));
+    messages.put(new FormInput(form, field), new Message(status, message));
   }
 
   public static class Message {
@@ -121,4 +132,60 @@ public class Validation {
       return "{" + status.name() + ": " + message + "}";
     }
   }
+
+  public static class FormInput {
+    private String form;
+    private String input;
+
+    public FormInput(String form, String input) {
+      this.form = form;
+      this.input = input;
+    }
+
+    public FormInput(String formInput) {
+      String []parts = formInput.split("\\.");
+      if(parts.length != 2) {
+        throw new SqoopException(ValidationError.VALIDATION_0003,
+          "Specification " + formInput + " is not in valid format form.input");
+      }
+
+      this.form = parts[0];
+      this.input = parts[1];
+    }
+
+    public String getForm() {
+      return form;
+    }
+
+    public String getInput() {
+      return input;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      FormInput formInput = (FormInput) o;
+
+      if (form != null ? !form.equals(formInput.form) : formInput.form != null)
+        return false;
+      if (input != null ? !input.equals(formInput.input) : formInput.input != null)
+        return false;
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      int result = form != null ? form.hashCode() : 0;
+      result = 31 * result + (input != null ? input.hashCode() : 0);
+      return result;
+    }
+
+    @Override
+    public String toString() {
+      return form + "." + input;
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/64917822/common/src/main/java/org/apache/sqoop/validation/ValidationError.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/validation/ValidationError.java b/common/src/main/java/org/apache/sqoop/validation/ValidationError.java
index 0c7e0ed..264d6e3 100644
--- a/common/src/main/java/org/apache/sqoop/validation/ValidationError.java
+++ b/common/src/main/java/org/apache/sqoop/validation/ValidationError.java
@@ -30,6 +30,7 @@ public enum ValidationError implements ErrorCode {
 
   VALIDATION_0002("Usage of missing field"),
 
+  VALIDATION_0003("Invalid representation of form and input field"),
   ;
 
   private final String message;

http://git-wip-us.apache.org/repos/asf/sqoop/blob/64917822/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java b/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java
index bdef7e8..ebcb749 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java
@@ -52,19 +52,22 @@ public class TestValidationBean {
 
     assertNull(retrievedBean.getId());
 
+    Validation.FormInput fa = new Validation.FormInput("f", "i");
+    Validation.FormInput fb = new Validation.FormInput("f2", "i2");
+
     Validation connector = retrievedBean.getConnectorValidation();
     assertEquals(Status.FINE, connector.getStatus());
     assertEquals(2, connector.getMessages().size());
-    assertTrue(connector.getMessages().containsKey("a"));
+    assertTrue(connector.getMessages().containsKey(fa));
     assertEquals(new Validation.Message(Status.FINE, "d"),
-      connector.getMessages().get("a"));
+      connector.getMessages().get(fa));
 
     Validation framework = retrievedBean.getFrameworkValidation();
     assertEquals(Status.UNACCEPTABLE, framework.getStatus());
     assertEquals(2, framework.getMessages().size());
-    assertTrue(framework.getMessages().containsKey("b"));
+    assertTrue(framework.getMessages().containsKey(fb));
     assertEquals(new Validation.Message(Status.UNACCEPTABLE, "c"),
-      framework.getMessages().get("b"));
+      framework.getMessages().get(fb));
   }
 
   @Test
@@ -89,11 +92,15 @@ public class TestValidationBean {
   }
 
   public Validation getValidation(Status status) {
-    Map<String, Validation.Message> messages =
-      new HashMap<String, Validation.Message>();
-
-    messages.put("a", new Validation.Message(status, "d"));
-    messages.put("b", new Validation.Message(status, "c"));
+    Map<Validation.FormInput, Validation.Message> messages =
+      new HashMap<Validation.FormInput, Validation.Message>();
+
+    messages.put(
+      new Validation.FormInput("f", "i"),
+      new Validation.Message(status, "d"));
+    messages.put(
+      new Validation.FormInput("f2", "i2"),
+      new Validation.Message(status, "c"));
 
     return new Validation(status, messages);
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/64917822/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java b/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java
index f17155f..c80bd45 100644
--- a/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java
+++ b/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java
@@ -115,11 +115,15 @@ public class TestFormUtils extends TestCase {
   }
 
   protected Validation getValidation() {
-    Map<String, Validation.Message> messages
-      = new HashMap<String, Validation.Message>();
-
-    messages.put("aForm.a1", new Validation.Message(Status.ACCEPTABLE, "e1"));
-    messages.put("aForm.a2", new Validation.Message(Status.UNACCEPTABLE, "e2"));
+    Map<Validation.FormInput, Validation.Message> messages
+      = new HashMap<Validation.FormInput, Validation.Message>();
+
+    messages.put(
+      new Validation.FormInput("aForm", "a1"),
+      new Validation.Message(Status.ACCEPTABLE, "e1"));
+    messages.put(
+      new Validation.FormInput("aForm", "a2"),
+      new Validation.Message(Status.UNACCEPTABLE, "e2"));
 
     return new Validation(Status.UNACCEPTABLE, messages);
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/64917822/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java
----------------------------------------------------------------------
diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java
b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java
index 52ad2dc..5ba1aae 100644
--- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java
+++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java
@@ -34,7 +34,8 @@ public class GenericJdbcValidator extends Validator {
 
     if(config.connection.connectionString == null
       || !config.connection.connectionString.startsWith("jdbc:")) {
-      validation.addMessage(Status.UNACCEPTABLE, "connectionString",
+      validation.addMessage(Status.UNACCEPTABLE,
+        "connection", "connectionString",
         "This do not seem as a valid JDBC URL");
     }
 


Mime
View raw message