You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ja...@apache.org on 2015/09/08 12:48:46 UTC

sqoop git commit: SQOOP-2539: Sqoop2: Enforce resource name not null when creating table

Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 a13343b34 -> 933839f0f


SQOOP-2539: Sqoop2: Enforce resource name not null when creating table

(Dian Fu 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/933839f0
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/933839f0
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/933839f0

Branch: refs/heads/sqoop2
Commit: 933839f0f74ca75272cf9367fab9efcf00bcbc73
Parents: a13343b
Author: Jarek Jarcec Cecho <ja...@apache.org>
Authored: Tue Sep 8 12:48:01 2015 +0200
Committer: Jarek Jarcec Cecho <ja...@apache.org>
Committed: Tue Sep 8 12:48:01 2015 +0200

----------------------------------------------------------------------
 .../repository/common/CommonRepoUtils.java      |   6 +
 .../derby/DerbyRepositoryHandler.java           |   6 +
 .../derby/DerbySchemaUpgradeQuery.java          |  29 +++++
 .../mysql/MySqlSchemaCreateQuery.java           |   6 +-
 .../postgresql/PostgresqlRepositoryHandler.java |   6 +
 .../PostgresqlSchemaUpgradeQuery.java           |  61 +++++++++
 .../apache/sqoop/shell/utils/ConfigFiller.java  |   8 +-
 .../test/infrastructure/SqoopTestCase.java      |   3 +
 .../sqoop/test/testcases/ConnectorTestCase.java |   5 +-
 .../org/apache/sqoop/test/utils/SqoopUtils.java |  43 +++++++
 .../derby/upgrade/Derby1_99_5UpgradeTest.java   | 125 ++++++++++++++++++
 .../derby/upgrade/Derby1_99_6UpgradeTest.java   | 126 +++++++++++++++++++
 .../derby/derby-repository-1.99.5.tar.gz        | Bin 0 -> 183379 bytes
 .../derby/derby-repository-1.99.6.tar.gz        | Bin 0 -> 188204 bytes
 14 files changed, 419 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java
----------------------------------------------------------------------
diff --git a/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java b/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java
index df41fb1..4a502b0 100644
--- a/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java
+++ b/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java
@@ -27,6 +27,8 @@ public class CommonRepoUtils {
 
   public static final String QUOTE_CHARACTER = "\"";
 
+  public static final String SINGLE_QUOTO_CHARACTER = "\'";
+
   public static final String escapeTableName(String tableName) {
     return QUOTE_CHARACTER + tableName + QUOTE_CHARACTER;
   }
@@ -47,6 +49,10 @@ public class CommonRepoUtils {
     return QUOTE_CHARACTER + constraintName + QUOTE_CHARACTER;
   }
 
+  public static final String escapeLiteralString(String literalString) {
+    return SINGLE_QUOTO_CHARACTER + literalString + SINGLE_QUOTO_CHARACTER;
+  }
+
   public static final String getTableName(String schemaName, String tableName) {
     if (schemaName != null) {
       return escapeSchemaName(schemaName) + "." + escapeTableName(tableName);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/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 45c7447..0302150 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
@@ -312,6 +312,12 @@ public class DerbyRepositoryHandler extends CommonRepositoryHandler {
       runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT_TYPE, conn);
       runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT_PROPERTY, conn);
       runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT, conn);
+
+      runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME, conn);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL, conn);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME, conn);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn);
     }
 
     // last step upgrade the repository version to the latest value in the code

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java
index 6adf959..5081b82 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java
@@ -633,6 +633,35 @@ public final class DerbySchemaUpgradeQuery {
         + QUERY_SELECT_DIRECTION_CONFIG_BY_DIRECTION_NAME
       + ")";
 
+  public static final String QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME =
+      "UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
+        + " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME)
+        + " = " + CommonRepoUtils.escapeLiteralString("link_") + " || "
+        + "TRIM(CHAR(" + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_ID) + "))"
+        + " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " IS NULL";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL =
+      "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
+        + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME)
+        + " NOT NULL";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME =
+      "UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
+        + " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME)
+        + " = " + CommonRepoUtils.escapeLiteralString("job_") + " || "
+        + "TRIM(CHAR(" + CommonRepoUtils.escapeColumnName(COLUMN_SQB_ID) + "))"
+        + " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + " IS NULL";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL =
+      "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
+        + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME)
+        + " NOT NULL";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL =
+      "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_CONFIGURABLE_NAME)
+        + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQC_NAME)
+        + " NOT NULL";
+
   private DerbySchemaUpgradeQuery() {
     // Disable explicit object creation
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java
----------------------------------------------------------------------
diff --git a/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java b/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java
index 46493a3..47f12fe 100644
--- a/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java
+++ b/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java
@@ -42,7 +42,7 @@ public class MySqlSchemaCreateQuery {
   public static final String QUERY_CREATE_TABLE_SQ_CONFIGURABLE =
       "CREATE TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, CommonRepositorySchemaConstants.TABLE_SQ_CONFIGURABLE_NAME) + " ("
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
-          + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_NAME) + " VARCHAR(64),"
+          + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_NAME) + " VARCHAR(64) NOT NULL,"
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_TYPE) + " VARCHAR(32), "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_CLASS) + " VARCHAR(255), "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_VERSION) + " VARCHAR(64), "
@@ -135,7 +135,7 @@ public class MySqlSchemaCreateQuery {
       "CREATE TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, CommonRepositorySchemaConstants.TABLE_SQ_LINK_NAME) + " ("
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CONFIGURABLE) + " BIGINT, "
-          + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME) + " VARCHAR(32), "
+          + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME) + " VARCHAR(32) NOT NULL, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CREATION_DATE) + " TIMESTAMP, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CREATION_USER) + " VARCHAR(32) DEFAULT NULL, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_UPDATE_DATE) + " TIMESTAMP, "
@@ -154,7 +154,7 @@ public class MySqlSchemaCreateQuery {
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_FROM_LINK) + " BIGINT, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_TO_LINK) + " BIGINT, "
-          + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_NAME) + " VARCHAR(64), "
+          + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_NAME) + " VARCHAR(64) NOT NULL, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_CREATION_DATE) + " TIMESTAMP, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_CREATION_USER) + " VARCHAR(32) DEFAULT NULL, "
           + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_UPDATE_DATE) + " TIMESTAMP, "

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
----------------------------------------------------------------------
diff --git a/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
index 5ada2d0..400d706 100644
--- a/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
+++ b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java
@@ -139,6 +139,12 @@ public class PostgresqlRepositoryHandler extends CommonRepositoryHandler {
       runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT_TYPE, conn);
       runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT_PROPERTY, conn);
       runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT, conn);
+
+      runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME, conn);
+      runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL, conn);
+      runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME, conn);
+      runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn);
+      runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn);
     }
 
     try (PreparedStatement stmtDel = conn.prepareStatement(PostgresqlSchemaQuery.STMT_DELETE_SYSTEM);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlSchemaUpgradeQuery.java
----------------------------------------------------------------------
diff --git a/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlSchemaUpgradeQuery.java b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlSchemaUpgradeQuery.java
new file mode 100644
index 0000000..52954e6
--- /dev/null
+++ b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlSchemaUpgradeQuery.java
@@ -0,0 +1,61 @@
+/**
+ * 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.repository.postgresql;
+
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQB_ID;
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQC_NAME;
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQ_LNK_ID;
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME;
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQB_NAME;
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.SCHEMA_SQOOP;
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_CONFIGURABLE_NAME;
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_JOB_NAME;
+import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_LINK_NAME;
+
+import org.apache.sqoop.repository.common.CommonRepoUtils;
+
+public class PostgresqlSchemaUpgradeQuery {
+  public static final String QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME =
+      "UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
+        + " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME)
+        + " = " + CommonRepoUtils.escapeLiteralString("link_") + " || "
+        + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_ID)
+        + " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " IS NULL";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL =
+      "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
+        + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME)
+        + " SET NOT NULL";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME =
+      "UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
+        + " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME)
+        + " = " + CommonRepoUtils.escapeLiteralString("job_") + " || "
+        + CommonRepoUtils.escapeColumnName(COLUMN_SQB_ID)
+        + " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + " IS NULL";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL =
+      "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
+        + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME)
+        + " SET NOT NULL";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL =
+      "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_CONFIGURABLE_NAME)
+      + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQC_NAME)
+      + " SET NOT NULL";
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java b/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java
index 63b1267..8b5f380 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java
@@ -888,7 +888,13 @@ public final class ConfigFiller {
       nameInput.setValue(name);
     }
 
-    fillInputStringWithBundle(nameInput, reader, getResourceBundle());
+    do {
+      fillInputStringWithBundle(nameInput, reader, getResourceBundle());
+      if (StringUtils.isEmpty(nameInput.getValue())) {
+        errorMessage(nameInput, "Job name or link name cannot be null");
+        continue;
+      }
+    } while (false);
 
     return nameInput.getValue();
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
index 82043ea..386b701 100644
--- a/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
+++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
@@ -40,6 +40,7 @@ import org.apache.sqoop.test.infrastructure.providers.HadoopInfrastructureProvid
 import org.apache.sqoop.test.infrastructure.providers.InfrastructureProvider;
 import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProvider;
 import org.apache.sqoop.test.utils.HdfsUtils;
+import org.apache.sqoop.test.utils.SqoopUtils;
 import org.apache.sqoop.validation.Status;
 import org.testng.ITest;
 import org.testng.ITestContext;
@@ -330,6 +331,7 @@ public class SqoopTestCase implements ITest {
    * @param link
    */
   public void saveLink(MLink link) {
+    SqoopUtils.fillObjectName(link);
     assertEquals(Status.OK, getClient().saveLink(link));
     assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, link.getPersistenceId());
   }
@@ -340,6 +342,7 @@ public class SqoopTestCase implements ITest {
    * @param job
    */
   public void saveJob(MJob job) {
+    SqoopUtils.fillObjectName(job);
     assertEquals(Status.OK, getClient().saveJob(job));
     assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, job.getPersistenceId());
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java b/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java
index e3e7bfe..4452558 100644
--- a/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java
+++ b/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java
@@ -36,6 +36,7 @@ import org.apache.sqoop.submission.SubmissionStatus;
 import org.apache.sqoop.test.data.Cities;
 import org.apache.sqoop.test.data.ShortStories;
 import org.apache.sqoop.test.data.UbuntuReleases;
+import org.apache.sqoop.test.utils.SqoopUtils;
 import org.apache.sqoop.validation.Status;
 import org.testng.annotations.AfterSuite;
 import org.testng.annotations.BeforeSuite;
@@ -253,6 +254,7 @@ abstract public class ConnectorTestCase extends TomcatTestCase {
    * @param link
    */
   protected void saveLink(MLink link) {
+    SqoopUtils.fillObjectName(link);
     assertEquals(getClient().saveLink(link), Status.OK);
     assertNotSame(link.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
   }
@@ -265,7 +267,8 @@ abstract public class ConnectorTestCase extends TomcatTestCase {
    * @param job
    */
  protected void saveJob(MJob job) {
-    assertEquals(getClient().saveJob(job), Status.OK);
+   SqoopUtils.fillObjectName(job);
+   assertEquals(getClient().saveJob(job), Status.OK);
    assertNotSame(job.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/test/src/main/java/org/apache/sqoop/test/utils/SqoopUtils.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/utils/SqoopUtils.java b/test/src/main/java/org/apache/sqoop/test/utils/SqoopUtils.java
new file mode 100644
index 0000000..5964bcd
--- /dev/null
+++ b/test/src/main/java/org/apache/sqoop/test/utils/SqoopUtils.java
@@ -0,0 +1,43 @@
+/**
+ * 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.test.utils;
+
+import java.util.Random;
+
+import org.apache.sqoop.model.MAccountableEntity;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+
+public class SqoopUtils {
+  private static final Random rand = new Random();
+
+  public static void fillObjectName(MAccountableEntity object) {
+    String objectName = object.getName();
+    if (objectName != null && !objectName.isEmpty()) {
+      return;
+    }
+
+    String prefix = "";
+    if (object instanceof MLink) {
+      prefix = "link_";
+    } else if (object instanceof MJob) {
+      prefix = "job_";
+    }
+    object.setName(prefix + rand.nextLong());
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_5UpgradeTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_5UpgradeTest.java b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_5UpgradeTest.java
new file mode 100644
index 0000000..4183d8b
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_5UpgradeTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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.integration.repository.derby.upgrade;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.validation.Status;
+import org.testng.annotations.Test;
+
+/**
+ * This version contains the following structures:
+ * Generic JDBC Connector link with name "Link1" and id 1
+ * Generic JDBC Connector link with blank name and id 2
+ * HDFS Connector link with name "Link3" and id 3
+ * HDFS Connector link with blank name and id 4
+ * HDFS Connector link with blank name and id 5
+ * HDFS Connector link with blank name and id 6
+ * Job (-f 1 -t 3) with name "Import" and id 1
+ * Job (-f 1 -t 3) with name "Query" and id 2
+ * Job (-f 3 -t 1) with name "Export" and id 3
+ * Job (-f 3 -t 1) with blank name and id 4
+ * Job (-f 3 -t 1) with blank name and id 5
+ * Job (-f 1 -t 1) with name "SameConnector" and id 6
+ * Job with id 1 has been executed 3 times
+ * Job with id 2 has been executed 3 times
+ * Job with id 3 has been executed 1 times
+ * Link with id 4 has been disabled
+ * Link with id 5 has been disabled
+ * Job with id 4 has been disabled
+ * Job with id 5 has been disabled
+ */
+public class Derby1_99_5UpgradeTest extends DerbyRepositoryUpgradeTest {
+
+  @Override
+  public String getPathToRepositoryTarball() {
+    return "/repository/derby/derby-repository-1.99.5.tar.gz";
+  }
+
+  @Override
+  public int getNumberOfLinks() {
+    return 6;
+  }
+
+  @Override
+  public int getNumberOfJobs() {
+    return 6;
+  }
+
+  @Override
+  public Map<Integer, Integer> getNumberOfSubmissions() {
+    HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
+    ret.put(1, 3);
+    ret.put(2, 3);
+    ret.put(3, 1);
+    ret.put(4, 0);
+    ret.put(5, 0);
+    return ret;
+  }
+
+  @Override
+  public Integer[] getDisabledLinkIds() {
+    return new Integer[] {4, 5};
+  }
+
+  @Override
+  public Integer[] getDisabledJobIds() {
+    return new Integer[] {4, 5};
+  }
+
+  @Override
+  public Integer[] getDeleteLinkIds() {
+    return new Integer[] {1, 2, 3, 4, 5, 6};
+  }
+
+  @Override
+  public Integer[] getDeleteJobIds() {
+    return new Integer[] {1, 2, 3, 4, 5, 6};
+  }
+
+  @Test
+  public void testJobNameNotNull() {
+    assertEquals(getNumberOfJobs(), getClient().getJobs().size());
+    for(MJob job : getClient().getJobs()) {
+      assertNotNull(job.getName());
+    }
+
+    MJob job = getClient().createJob(1, 1);
+    assertNull(job.getName());
+    assertEquals(getClient().saveJob(job), Status.ERROR);
+  }
+
+  @Test
+  public void testLinkNameNotNull() {
+    assertEquals(getNumberOfLinks(), getClient().getLinks().size());
+    for(MLink link : getClient().getLinks()) {
+      assertNotNull(link.getName());
+    }
+
+    MLink link = getClient().createLink("generic-jdbc-connector");
+    assertNull(link.getName());
+    assertEquals(getClient().saveLink(link), Status.ERROR);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_6UpgradeTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_6UpgradeTest.java b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_6UpgradeTest.java
new file mode 100644
index 0000000..59980c0
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_6UpgradeTest.java
@@ -0,0 +1,126 @@
+/**
+ * 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.integration.repository.derby.upgrade;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.validation.Status;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+/**
+ * This version contains the following structures:
+ * Generic JDBC Connector link with name "Link1" and id 1
+ * Generic JDBC Connector link with blank name and id 2
+ * HDFS Connector link with name "Link3" and id 3
+ * HDFS Connector link with blank name and id 4
+ * HDFS Connector link with blank name and id 5
+ * HDFS Connector link with blank name and id 6
+ * Job (-f 1 -t 3) with name "Import" and id 1
+ * Job (-f 1 -t 3) with name "Query" and id 2
+ * Job (-f 3 -t 1) with name "Export" and id 3
+ * Job (-f 3 -t 1) with blank name and id 4
+ * Job (-f 3 -t 1) with blank name and id 5
+ * Job (-f 1 -t 1) with name "SameConnector" and id 6
+ * Job with id 1 has been executed 3 times
+ * Job with id 2 has been executed 3 times
+ * Job with id 3 has been executed 1 times
+ * Link with id 4 has been disabled
+ * Link with id 5 has been disabled
+ * Job with id 4 has been disabled
+ * Job with id 5 has been disabled
+ */
+public class Derby1_99_6UpgradeTest extends DerbyRepositoryUpgradeTest {
+
+  @Override
+  public String getPathToRepositoryTarball() {
+    return "/repository/derby/derby-repository-1.99.6.tar.gz";
+  }
+
+  @Override
+  public int getNumberOfLinks() {
+    return 6;
+  }
+
+  @Override
+  public int getNumberOfJobs() {
+    return 6;
+  }
+
+  @Override
+  public Map<Integer, Integer> getNumberOfSubmissions() {
+    HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
+    ret.put(1, 3);
+    ret.put(2, 3);
+    ret.put(3, 1);
+    ret.put(4, 0);
+    ret.put(5, 0);
+    return ret;
+  }
+
+  @Override
+  public Integer[] getDisabledLinkIds() {
+    return new Integer[] {4, 5};
+  }
+
+  @Override
+  public Integer[] getDisabledJobIds() {
+    return new Integer[] {4, 5};
+  }
+
+  @Override
+  public Integer[] getDeleteLinkIds() {
+    return new Integer[] {1, 2, 3, 4, 5, 6};
+  }
+
+  @Override
+  public Integer[] getDeleteJobIds() {
+    return new Integer[] {1, 2, 3, 4, 5, 6};
+  }
+
+  @Test
+  public void testJobNameNotNull() {
+    assertEquals(getNumberOfJobs(), getClient().getJobs().size());
+    for(MJob job : getClient().getJobs()) {
+      assertNotNull(job.getName());
+    }
+
+    MJob job = getClient().createJob(1, 1);
+    assertNull(job.getName());
+    assertEquals(getClient().saveJob(job), Status.ERROR);
+  }
+
+  @Test
+  public void testLinkNameNotNull() {
+    assertEquals(getNumberOfLinks(), getClient().getLinks().size());
+    for(MLink link : getClient().getLinks()) {
+      assertNotNull(link.getName());
+    }
+
+    MLink link = getClient().createLink("generic-jdbc-connector");
+    assertNull(link.getName());
+    assertEquals(getClient().saveLink(link), Status.ERROR);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/test/src/test/resources/repository/derby/derby-repository-1.99.5.tar.gz
----------------------------------------------------------------------
diff --git a/test/src/test/resources/repository/derby/derby-repository-1.99.5.tar.gz b/test/src/test/resources/repository/derby/derby-repository-1.99.5.tar.gz
new file mode 100644
index 0000000..b571425
Binary files /dev/null and b/test/src/test/resources/repository/derby/derby-repository-1.99.5.tar.gz differ

http://git-wip-us.apache.org/repos/asf/sqoop/blob/933839f0/test/src/test/resources/repository/derby/derby-repository-1.99.6.tar.gz
----------------------------------------------------------------------
diff --git a/test/src/test/resources/repository/derby/derby-repository-1.99.6.tar.gz b/test/src/test/resources/repository/derby/derby-repository-1.99.6.tar.gz
new file mode 100644
index 0000000..be366b0
Binary files /dev/null and b/test/src/test/resources/repository/derby/derby-repository-1.99.6.tar.gz differ