You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ab...@apache.org on 2014/10/10 05:06:57 UTC
[05/50] [abbrv] git commit: SQOOP-1542: Sqoop2: From/To: MConnector
should handle null forms
SQOOP-1542: Sqoop2: From/To: MConnector should handle null forms
(Abraham Elmahrek via Jarek Jarcec Cecho)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/d0153621
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/d0153621
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/d0153621
Branch: refs/heads/sqoop2
Commit: d0153621d38c4c8478276417b12e36bd67ed6121
Parents: 049994a
Author: Jarek Jarcec Cecho <ja...@apache.org>
Authored: Wed Sep 24 16:16:54 2014 -0700
Committer: Abraham Elmahrek <ab...@elmahrek.com>
Committed: Thu Oct 9 17:58:18 2014 -0700
----------------------------------------------------------------------
.../java/org/apache/sqoop/model/MConnector.java | 64 +++++++++++++++++---
.../org/apache/sqoop/model/TestMConnector.java | 52 ++++++++++++++++
2 files changed, 107 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/d0153621/common/src/main/java/org/apache/sqoop/model/MConnector.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MConnector.java b/common/src/main/java/org/apache/sqoop/model/MConnector.java
index 3dc1014..7999b08 100644
--- a/common/src/main/java/org/apache/sqoop/model/MConnector.java
+++ b/common/src/main/java/org/apache/sqoop/model/MConnector.java
@@ -63,12 +63,18 @@ public final class MConnector extends MPersistableEntity implements MClonable {
@Override
public String toString() {
+ MJobForms fromJobForms = this.getJobForms(Direction.FROM);
+ MJobForms toJobForms = this.getJobForms(Direction.TO);
StringBuilder sb = new StringBuilder("connector-");
sb.append(uniqueName).append(":").append(getPersistenceId()).append(":");
sb.append(className);
sb.append(", ").append(getConnectionForms().toString());
- sb.append(", ").append(getJobForms(Direction.FROM).toString());
- sb.append(", ").append(getJobForms(Direction.TO).toString());
+ if (fromJobForms != null) {
+ sb.append(", ").append(fromJobForms.toString());
+ }
+ if (toJobForms != null) {
+ sb.append(", ").append(toJobForms.toString());
+ }
return sb.toString();
}
@@ -83,19 +89,47 @@ public final class MConnector extends MPersistableEntity implements MClonable {
}
MConnector mc = (MConnector) other;
+ SupportedDirections supportedDirections = this.getSupportedDirections();
+ SupportedDirections mcSupportedDirections = mc.getSupportedDirections();
+
+ if (supportedDirections.isDirectionSupported(Direction.FROM)
+ && mcSupportedDirections.isDirectionSupported(Direction.FROM)
+ && !getJobForms(Direction.FROM).equals(mc.getJobForms(Direction.FROM))) {
+ return false;
+ }
+
+ if (supportedDirections.isDirectionSupported(Direction.FROM)
+ != mcSupportedDirections.isDirectionSupported(Direction.FROM)) {
+ return false;
+ }
+
+ if (supportedDirections.isDirectionSupported(Direction.TO)
+ && mcSupportedDirections.isDirectionSupported(Direction.TO)
+ && !getJobForms(Direction.TO).equals(mc.getJobForms(Direction.TO))) {
+ return false;
+ }
+
+ if (supportedDirections.isDirectionSupported(Direction.TO)
+ != mcSupportedDirections.isDirectionSupported(Direction.TO)) {
+ return false;
+ }
+
return uniqueName.equals(mc.uniqueName)
&& className.equals(mc.className)
&& version.equals(mc.version)
- && connectionForms.equals(mc.getConnectionForms())
- && fromJobForms.equals(mc.getJobForms(Direction.FROM))
- && toJobForms.equals(mc.getJobForms(Direction.TO));
+ && connectionForms.equals(mc.getConnectionForms());
}
@Override
public int hashCode() {
+ SupportedDirections supportedDirections = getSupportedDirections();
int result = getConnectionForms().hashCode();
- result = 31 * result + getJobForms(Direction.FROM).hashCode();
- result = 31 * result + getJobForms(Direction.TO).hashCode();
+ if (supportedDirections.isDirectionSupported(Direction.FROM)) {
+ result = 31 * result + getJobForms(Direction.FROM).hashCode();
+ }
+ if (supportedDirections.isDirectionSupported(Direction.TO)) {
+ result = 31 * result + getJobForms(Direction.TO).hashCode();
+ }
result = 31 * result + version.hashCode();
result = 31 * result + uniqueName.hashCode();
result = 31 * result + className.hashCode();
@@ -105,13 +139,25 @@ public final class MConnector extends MPersistableEntity implements MClonable {
public MConnector clone(boolean cloneWithValue) {
//Connector never have any values filled
cloneWithValue = false;
+
+ MJobForms fromJobForms = this.getJobForms(Direction.FROM);
+ MJobForms toJobForms = this.getJobForms(Direction.TO);
+
+ if (fromJobForms != null) {
+ fromJobForms = fromJobForms.clone(cloneWithValue);
+ }
+
+ if (toJobForms != null) {
+ toJobForms = toJobForms.clone(cloneWithValue);
+ }
+
MConnector copy = new MConnector(
this.getUniqueName(),
this.getClassName(),
this.getVersion(),
this.getConnectionForms().clone(cloneWithValue),
- this.getJobForms(Direction.FROM).clone(cloneWithValue),
- this.getJobForms(Direction.TO).clone(cloneWithValue));
+ fromJobForms,
+ toJobForms);
copy.setPersistenceId(this.getPersistenceId());
return copy;
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/d0153621/common/src/test/java/org/apache/sqoop/model/TestMConnector.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMConnector.java b/common/src/test/java/org/apache/sqoop/model/TestMConnector.java
index 3fde47b..0a5fd90 100644
--- a/common/src/test/java/org/apache/sqoop/model/TestMConnector.java
+++ b/common/src/test/java/org/apache/sqoop/model/TestMConnector.java
@@ -132,6 +132,58 @@ public class TestMConnector {
}
@Test
+ public void testFromDirection() {
+ MConnector connector = createConnector(Arrays.asList(Direction.FROM));
+
+ // Clone should clone only one job form.
+ MConnector clone = connector.clone(true);
+ assertNotNull(clone.getJobForms(Direction.FROM));
+ assertNull(clone.getJobForms(Direction.TO));
+ assertEquals(connector, clone);
+ assertEquals(connector.toString(), clone.toString());
+ assertNotEquals(connector.hashCode(), clone.hashCode());
+ }
+
+ @Test
+ public void testToDirection() {
+ MConnector connector = createConnector(Arrays.asList(Direction.TO));
+
+ // Clone should clone only one job form.
+ MConnector clone = connector.clone(true);
+ assertNull(clone.getJobForms(Direction.FROM));
+ assertNotNull(clone.getJobForms(Direction.TO));
+ assertEquals(connector, clone);
+ assertEquals(connector.toString(), clone.toString());
+ assertNotEquals(connector.hashCode(), clone.hashCode());
+ }
+
+ @Test
+ public void testNoDirection() {
+ MConnector connector = createConnector(Arrays.asList(new Direction[0]));
+
+ // Clone should clone only one job form.
+ MConnector clone = connector.clone(true);
+ assertNull(clone.getJobForms(Direction.FROM));
+ assertNull(clone.getJobForms(Direction.TO));
+ assertEquals(connector, clone);
+ assertEquals(connector.toString(), clone.toString());
+ assertNotEquals(connector.hashCode(), clone.hashCode());
+ }
+
+ @Test
+ public void testBothDirections() {
+ MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO));
+
+ // Clone should clone only one job form.
+ MConnector clone = connector.clone(true);
+ assertNotNull(clone.getJobForms(Direction.FROM));
+ assertNotNull(clone.getJobForms(Direction.TO));
+ assertEquals(connector, clone);
+ assertEquals(connector.toString(), clone.toString());
+ assertNotEquals(connector.hashCode(), clone.hashCode());
+ }
+
+ @Test
public void testGetSupportedDirections() {
MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO));
assertTrue(connector.getSupportedDirections().isDirectionSupported(Direction.FROM));