Updated Branches:
  refs/heads/sqoop2 982c76e03 -> 13439909f

SQOOP-613 Add support for integer type to metadata model


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

Branch: refs/heads/sqoop2
Commit: 13439909f300b8e573ad31b0023095008d452244
Parents: 982c76e
Author: Bilung Lee <[email protected]>
Authored: Wed Oct 3 16:42:07 2012 -0700
Committer: Bilung Lee <[email protected]>
Committed: Wed Oct 3 16:42:07 2012 -0700

----------------------------------------------------------------------
 .../org/apache/sqoop/client/utils/FormFiller.java  |   67 +++++++++--
 .../apache/sqoop/json/util/FormSerialization.java  |    8 +-
 .../java/org/apache/sqoop/model/MInputType.java    |    7 +-
 .../java/org/apache/sqoop/model/MIntegerInput.java |   92 +++++++++++++++
 .../apache/sqoop/framework/FrameworkManager.java   |    5 +-
 .../repository/derby/DerbyRepositoryHandler.java   |    7 +
 6 files changed, 172 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/13439909/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java 
b/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
index af3ff8a..2404587 100644
--- a/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
+++ b/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
@@ -20,6 +20,7 @@ package org.apache.sqoop.client.utils;
 import jline.ConsoleReader;
 import org.apache.sqoop.model.MForm;
 import org.apache.sqoop.model.MInput;
+import org.apache.sqoop.model.MIntegerInput;
 import org.apache.sqoop.model.MStringInput;
 import org.codehaus.groovy.tools.shell.IO;
 
@@ -32,7 +33,6 @@ import java.util.ResourceBundle;
  */
 public class FormFiller {
 
-
   public static boolean fillForms(IO io,
                                   List<MForm> forms,
                                   ConsoleReader reader,
@@ -70,12 +70,10 @@ public class FormFiller {
     // performed.
     switch (input.getValidationSeverity()) {
       case ERROR:
-        io.out.println("Error message: @|red "
-          + input.getValidationMessage() + " |@");
+        errorMessage(io, input.getValidationMessage());
         break;
       case WARNING:
-        io.out.println("Warning message: @|yellow "
-          + input.getValidationMessage() + " |@");
+        warningMessage(io, input.getValidationMessage());
         break;
       default:
         // Simply ignore all other states for the moment
@@ -86,6 +84,8 @@ public class FormFiller {
     switch (input.getType()) {
       case STRING:
         return fillInputString(io, (MStringInput) input, reader, bundle);
+      case INTEGER:
+        return fillInputInteger(io, (MIntegerInput) input, reader, bundle);
       //TODO(jarcec): Support MAP
       default:
         io.out.println("Unsupported data type " + input.getType());
@@ -93,17 +93,50 @@ public class FormFiller {
     }
   }
 
+  private static boolean fillInputInteger(IO io,
+                                          MIntegerInput input,
+                                          ConsoleReader reader,
+                                          ResourceBundle bundle)
+                                          throws IOException {
+    generatePrompt(reader, bundle, input);
+
+    // Fill already filled data when available
+    if(!input.isEmpty()) {
+      reader.putString(input.getValue().toString());
+    }
+
+    String userTyped = reader.readLine();
+
+    if (userTyped == null) {
+      return false;
+    } else if (userTyped.isEmpty()) {
+      input.setEmpty();
+    } else {
+      Integer value;
+      try {
+        value = Integer.valueOf(userTyped);
+        input.setValue(value);
+      } catch (NumberFormatException ex) {
+        errorMessage(io, "Input is not valid integer number");
+        return fillInputInteger(io, input, reader, bundle);
+      }
+
+      input.setValue(Integer.valueOf(userTyped));
+    }
+
+    return true;
+  }
+
   public static boolean fillInputString(IO io,
                                         MStringInput input,
                                         ConsoleReader reader,
                                         ResourceBundle bundle)
                                         throws IOException {
-    // Print prompt
-    reader.printString(bundle.getString(input.getLabelKey()) + ": ");
-    reader.flushConsole();
+    generatePrompt(reader, bundle, input);
 
     // Fill already filled data when available
-    if(!input.isEmpty()) {
+    // However do not printout if this input contains sensitive information.
+    if(!input.isEmpty() && !input.isMasked()) {
       reader.putString(input.getValue());
     }
 
@@ -126,6 +159,22 @@ public class FormFiller {
     return true;
   }
 
+  public static void generatePrompt(ConsoleReader reader,
+                                    ResourceBundle bundle,
+                                    MInput input)
+                                    throws IOException {
+    reader.printString(bundle.getString(input.getLabelKey()) + ": ");
+    reader.flushConsole();
+  }
+
+  public static void errorMessage(IO io, String message) {
+    io.out.println("Error message: @|red " + message + " |@");
+  }
+
+  public static void warningMessage(IO io, String message) {
+    io.out.println("Warning message: @|yellow " + message + " |@");
+  }
+
   private FormFiller() {
     // Do not instantiate
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/13439909/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
----------------------------------------------------------------------
diff --git 
a/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java 
b/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
index 6b7332a..752acbe 100644
--- a/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
+++ b/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
@@ -21,6 +21,7 @@ import org.apache.sqoop.model.MForm;
 import org.apache.sqoop.model.MFormType;
 import org.apache.sqoop.model.MInput;
 import org.apache.sqoop.model.MInputType;
+import org.apache.sqoop.model.MIntegerInput;
 import org.apache.sqoop.model.MMapInput;
 import org.apache.sqoop.model.MStringInput;
 import org.json.simple.JSONArray;
@@ -135,20 +136,23 @@ public class FormSerialization {
       JSONObject input = (JSONObject) inputs.get(i);
       MInputType type =
           MInputType.valueOf((String) input.get(FORM_INPUT_TYPE));
+      String name = (String) input.get(FORM_INPUT_NAME);
       MInput mInput = null;
       switch (type) {
         case STRING: {
-          String name = (String) input.get(FORM_INPUT_NAME);
           boolean mask = (Boolean) input.get(FORM_INPUT_MASK);
           long size = (Long) input.get(FORM_INPUT_SIZE);
           mInput = new MStringInput(name, mask, (short) size);
           break;
         }
         case MAP: {
-          String name = (String) input.get(FORM_INPUT_NAME);
           mInput = new MMapInput(name);
           break;
         }
+        case INTEGER: {
+          mInput = new MIntegerInput(name);
+          break;
+        }
       }
 
       // Propagate form ID

http://git-wip-us.apache.org/repos/asf/sqoop/blob/13439909/common/src/main/java/org/apache/sqoop/model/MInputType.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MInputType.java 
b/common/src/main/java/org/apache/sqoop/model/MInputType.java
index 7acdbca..8016349 100644
--- a/common/src/main/java/org/apache/sqoop/model/MInputType.java
+++ b/common/src/main/java/org/apache/sqoop/model/MInputType.java
@@ -29,5 +29,10 @@ public enum MInputType {
   STRING,
 
   /** Map input type */
-  MAP;
+  MAP,
+
+  /** Integer input type */
+  INTEGER,
+
+  ;
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/13439909/common/src/main/java/org/apache/sqoop/model/MIntegerInput.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MIntegerInput.java 
b/common/src/main/java/org/apache/sqoop/model/MIntegerInput.java
new file mode 100644
index 0000000..26477cc
--- /dev/null
+++ b/common/src/main/java/org/apache/sqoop/model/MIntegerInput.java
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.model;
+
+/**
+ * Integer base user input.
+ *
+ * This input is able to process empty (NULL) value.
+ */
+public class MIntegerInput extends MInput<Integer> {
+
+  public MIntegerInput(String name) {
+    super(name);
+  }
+
+  @Override
+  public String getUrlSafeValueString() {
+    if(isEmpty()) {
+      return "";
+    }
+
+    return getValue().toString();
+  }
+
+  @Override
+  public void restoreFromUrlSafeValueString(String valueString) {
+    if(valueString.isEmpty()) {
+      setEmpty();
+    }
+
+    setValue(Integer.valueOf(valueString));
+  }
+
+  @Override
+  public MInputType getType() {
+    return MInputType.INTEGER;
+  }
+
+  @Override
+  protected boolean hasExtraInfo() {
+    return false;
+  }
+
+  @Override
+  protected String getExtraInfoToString() {
+    return "";
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (other == this) {
+      return true;
+    }
+
+    if (!(other instanceof MIntegerInput)) {
+      return false;
+    }
+
+    MIntegerInput i = (MIntegerInput) other;
+    return getName().equals(i.getName());
+  }
+
+  @Override
+  public int hashCode() {
+    return 23 + 31 * getName().hashCode();
+  }
+
+  @Override
+  public boolean isEmpty() {
+    return getValue() == null;
+  }
+
+  @Override
+  public void setEmpty() {
+    setValue(null);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/13439909/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java 
b/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
index 657eab2..4485fd6 100644
--- a/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
+++ b/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
@@ -20,6 +20,7 @@ package org.apache.sqoop.framework;
 import org.apache.log4j.Logger;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.model.MConnectionForms;
+import org.apache.sqoop.model.MIntegerInput;
 import org.apache.sqoop.model.MJob;
 import org.apache.sqoop.model.MForm;
 import org.apache.sqoop.model.MFramework;
@@ -62,8 +63,8 @@ public class FrameworkManager {
     // Build the CONNECTION_FORMS forms for import
     List<MInput<?>> connFormInputs = new ArrayList<MInput<?>>();
 
-    MStringInput maxConnections = new MStringInput(
-      INPUT_CONN_MAX_SIMULTANEOUS_CONNECTIONS, false, (short) 10);
+    MIntegerInput maxConnections = new MIntegerInput(
+      INPUT_CONN_MAX_SIMULTANEOUS_CONNECTIONS);
     connFormInputs.add(maxConnections);
 
     MForm connForm = new MForm(FORM_SECURITY, connFormInputs);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/13439909/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
----------------------------------------------------------------------
diff --git 
a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
 
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
index 17e43b8..ef3d804 100644
--- 
a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
+++ 
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
@@ -37,6 +37,7 @@ import org.apache.log4j.Logger;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.model.MConnection;
 import org.apache.sqoop.model.MConnectionForms;
+import org.apache.sqoop.model.MIntegerInput;
 import org.apache.sqoop.model.MJob;
 import org.apache.sqoop.model.MJobForms;
 import org.apache.sqoop.model.MConnector;
@@ -934,6 +935,9 @@ public class DerbyRepositoryHandler implements 
JdbcRepositoryHandler {
         MStringInput   strInput = (MStringInput) input;
         baseInputStmt.setBoolean(5, strInput.isMasked());
         baseInputStmt.setShort(6, strInput.getMaxLength());
+      } else {
+        baseInputStmt.setNull(5, Types.BOOLEAN);
+        baseInputStmt.setNull(6, Types.INTEGER);
       }
       int baseInputCount = baseInputStmt.executeUpdate();
       if (baseInputCount != 1) {
@@ -1058,6 +1062,9 @@ public class DerbyRepositoryHandler implements 
JdbcRepositoryHandler {
         case MAP:
           input = new MMapInput(inputName);
           break;
+        case INTEGER:
+          input = new MIntegerInput(inputName);
+          break;
         default:
           throw new SqoopException(DerbyRepoError.DERBYREPO_0006,
               "input-" + inputName + ":" + inputId + ":"

Reply via email to