sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [50/52] [abbrv] git commit: SQOOP-1477: Sqoop2: Make link and job name unique identifier
Date Fri, 10 Oct 2014 02:52:19 GMT
SQOOP-1477: Sqoop2: Make link and job name unique identifier

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

Branch: refs/heads/SQOOP-1367
Commit: 4c964a97be674ead165844274d48fea9ff69fe65
Parents: c78b75a
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Tue Oct 7 11:38:09 2014 -0700
Committer: Abraham Elmahrek <abraham@elmahrek.com>
Committed: Thu Oct 9 18:22:51 2014 -0700

----------------------------------------------------------------------
 .../sqoop/repository/RepositoryError.java       |  2 +-
 .../derby/DerbyRepositoryHandler.java           | 18 +++--
 .../repository/derby/DerbySchemaConstants.java  | 10 +++
 .../repository/derby/DerbySchemaQuery.java      | 44 +++++-------
 .../sqoop/repository/derby/DerbyTestCase.java   | 19 ++++--
 .../sqoop/repository/derby/TestInternals.java   | 71 ++++++++++++++++++++
 .../sqoop/repository/derby/TestJobHandling.java | 23 +++++--
 .../repository/derby/TestLinkHandling.java      | 12 ++++
 8 files changed, 156 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/4c964a97/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java b/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
index 54e37d9..0c93b50 100644
--- a/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
+++ b/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
@@ -122,7 +122,7 @@ public enum RepositoryError implements ErrorCode {
   JDBCREPO_0026("Upgrade required but not allowed"),
 
   /** Invalid links or jobs when upgrading connector **/
-  JDBCREPO_0027("Invalid links or jobs when upgrading connector");
+  JDBCREPO_0027("Invalid links or jobs when upgrading connector")
 
   ;
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/4c964a97/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 39702ca..73d8387 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
@@ -415,6 +415,10 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
       // Wait to remove SQB_TYPE (IMPORT/EXPORT) until we update data.
       // Data updates depend on knowledge of the type of job.
       runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_REMOVE_COLUMN_SQB_TYPE, conn);
+
+      // Add unique constraints on job and links.
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_UNIQUE_CONSTRAINT_NAME, conn);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_ADD_UNIQUE_CONSTRAINT_NAME, conn);
     }
 
     ResultSet rs = null;
@@ -849,7 +853,7 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
     PreparedStatement stmt = null;
     ResultSet rs = null;
     try {
-      stmt = conn.prepareStatement(STMT_SELECT_LINK_CHECK);
+      stmt = conn.prepareStatement(STMT_SELECT_LINK_CHECK_BY_ID);
       stmt.setLong(1, id);
       rs = stmt.executeQuery();
 
@@ -1164,9 +1168,9 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
                         job.getJobConfig(Direction.TO).getConfigs(),
                         conn);
       createInputValues(STMT_INSERT_JOB_INPUT,
-                        job.getPersistenceId(),
-                        job.getDriverConfig().getConfigs(),
-                        conn);
+          job.getPersistenceId(),
+          job.getDriverConfig().getConfigs(),
+          conn);
 
     } catch (SQLException ex) {
       logException(ex, job);
@@ -1184,7 +1188,7 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
     PreparedStatement stmt = null;
     ResultSet rs = null;
     try {
-      stmt = conn.prepareStatement(STMT_SELECT_JOB_CHECK);
+      stmt = conn.prepareStatement(STMT_SELECT_JOB_CHECK_BY_ID);
       stmt.setLong(1, id);
       rs = stmt.executeQuery();
 
@@ -1279,7 +1283,7 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
   public MJob findJob(long id, Connection conn) {
     PreparedStatement stmt = null;
     try {
-      stmt = conn.prepareStatement(STMT_SELECT_JOB_SINGLE);
+      stmt = conn.prepareStatement(STMT_SELECT_JOB_SINGLE_BY_ID);
       stmt.setLong(1, id);
 
       List<MJob> jobs = loadJobs(stmt, conn);
@@ -1307,7 +1311,7 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
   public List<MJob> findJobs(Connection conn) {
     PreparedStatement stmt = null;
     try {
-      stmt = conn.prepareStatement(STMT_SELECT_JOB_ALL);
+      stmt = conn.prepareStatement(STMT_SELECT_JOB);
 
       return loadJobs(stmt, conn);
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/4c964a97/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
index fc3ec18..ad749ed 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
@@ -133,6 +133,10 @@ public final class DerbySchemaConstants {
 
   public static final String CONSTRAINT_SQ_LNK_SQC = SCHEMA_PREFIX + CONSTRAINT_SQ_LNK_SQC_NAME;
 
+  public static final String CONSTRAINT_SQ_LNK_NAME_UNIQUE_NAME = CONSTRAINT_PREFIX + "SQ_LNK_NAME_UNIQUE";
+
+  public static final String CONSTRAINT_SQ_LNK_NAME_UNIQUE = SCHEMA_PREFIX + CONSTRAINT_SQ_LNK_NAME_UNIQUE_NAME;
+
   // SQ_JOB
 
   public static final String TABLE_SQ_JOB_NAME = "SQ_JOB";
@@ -174,6 +178,12 @@ public final class DerbySchemaConstants {
 
   public static final String CONSTRAINT_SQB_SQ_LNK_TO = SCHEMA_PREFIX + CONSTRAINT_SQB_SQ_LNK_TO_NAME;
 
+  public static final String CONSTRAINT_SQB_NAME_UNIQUE_NAME = CONSTRAINT_PREFIX + "SQB_NAME_UNIQUE";
+
+  public static final String CONSTRAINT_SQB_NAME_UNIQUE = SCHEMA_PREFIX + CONSTRAINT_SQB_NAME_UNIQUE_NAME;
+
+  // SQ_CONNECTION_INPUT
+
   public static final String TABLE_SQ_LINK_INPUT_NAME =
     "SQ_LINK_INPUT";
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/4c964a97/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
index 951d9b4..478afe2 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
@@ -694,7 +694,7 @@ public final class DerbySchemaQuery {
     + " WHERE " + COLUMN_SQ_LNK_CONNECTOR + " = ?";
 
   // DML: Check if given link exists
-  public static final String STMT_SELECT_LINK_CHECK =
+  public static final String STMT_SELECT_LINK_CHECK_BY_ID =
     "SELECT count(*) FROM " + TABLE_SQ_LINK
     + " WHERE " + COLUMN_SQ_LNK_ID + " = ?";
 
@@ -743,7 +743,7 @@ public final class DerbySchemaQuery {
     + " WHERE " + COLUMN_SQB_ID + " = ?";
 
   // DML: Check if given job exists
-  public static final String STMT_SELECT_JOB_CHECK =
+  public static final String STMT_SELECT_JOB_CHECK_BY_ID =
     "SELECT count(*) FROM " + TABLE_SQ_JOB
     + " WHERE " + COLUMN_SQB_ID + " = ?";
 
@@ -756,29 +756,8 @@ public final class DerbySchemaQuery {
       + " ON " + COLUMN_SQB_FROM_LINK + " = " + COLUMN_SQ_LNK_ID
     + " WHERE " + COLUMN_SQ_LNK_ID + " = ? ";
 
-  // DML: Select one specific job
-  public static final String STMT_SELECT_JOB_SINGLE =
-    "SELECT "
-    + "FROM_CONNECTOR." + COLUMN_SQ_LNK_CONNECTOR + ", "
-    + "TO_CONNECTOR." + COLUMN_SQ_LNK_CONNECTOR + ", "
-    + "job." + COLUMN_SQB_ID + ", "
-    + "job." + COLUMN_SQB_NAME + ", "
-    + "job." + COLUMN_SQB_FROM_LINK + ", "
-    + "job." + COLUMN_SQB_TO_LINK + ", "
-    + "job." + COLUMN_SQB_ENABLED + ", "
-    + "job." + COLUMN_SQB_CREATION_USER + ", "
-    + "job." + COLUMN_SQB_CREATION_DATE + ", "
-    + "job." + COLUMN_SQB_UPDATE_USER + ", "
-    + "job." + COLUMN_SQB_UPDATE_DATE
-    + " FROM " + TABLE_SQ_JOB + " job"
-    + " LEFT JOIN " + TABLE_SQ_LINK
-    + " FROM_CONNECTOR ON " + COLUMN_SQB_FROM_LINK + " = FROM_CONNECTOR." + COLUMN_SQ_LNK_ID
-    + " LEFT JOIN " + TABLE_SQ_LINK
-    + " TO_CONNECTOR ON " + COLUMN_SQB_TO_LINK + " = TO_CONNECTOR." + COLUMN_SQ_LNK_ID
-    + " WHERE " + COLUMN_SQB_ID + " = ?";
-
   // DML: Select all jobs
-  public static final String STMT_SELECT_JOB_ALL =
+  public static final String STMT_SELECT_JOB =
     "SELECT "
     + "FROM_LINK." + COLUMN_SQ_LNK_CONNECTOR + ", "
     + "TO_LINK." + COLUMN_SQ_LNK_CONNECTOR + ", "
@@ -797,9 +776,14 @@ public final class DerbySchemaQuery {
       + " LEFT JOIN " + TABLE_SQ_LINK + " TO_LINK"
         + " ON " + COLUMN_SQB_TO_LINK + " = TO_LINK." + COLUMN_SQ_LNK_ID;
 
+  // DML: Select one specific job
+  public static final String STMT_SELECT_JOB_SINGLE_BY_ID =
+      STMT_SELECT_JOB + " WHERE " + COLUMN_SQB_ID + " = ?";
+
   // DML: Select all jobs for a Connector
-  public static final String STMT_SELECT_ALL_JOBS_FOR_CONNECTOR = STMT_SELECT_JOB_ALL
-    + " WHERE FROM_LINK." + COLUMN_SQ_LNK_CONNECTOR + " = ? OR TO_LINK." + COLUMN_SQ_LNK_CONNECTOR
+ " = ?";
+  public static final String STMT_SELECT_ALL_JOBS_FOR_CONNECTOR = STMT_SELECT_JOB
+      + " WHERE FROM_LINK." + COLUMN_SQ_LNK_CONNECTOR + " = ? OR TO_LINK."
+      + COLUMN_SQ_LNK_CONNECTOR + " = ?";
 
   // DML: Insert new submission
   public static final String STMT_INSERT_SUBMISSION =
@@ -1066,6 +1050,14 @@ public final class DerbySchemaQuery {
   public static final String QUERY_UPGRADE_TABLE_SQ_JOB_REMOVE_COLUMN_SQB_TYPE =
       "ALTER TABLE " + TABLE_SQ_JOB + " DROP COLUMN " + COLUMN_SQB_TYPE;
 
+  public static final String QUERY_UPGRADE_TABLE_SQ_JOB_ADD_UNIQUE_CONSTRAINT_NAME =
+      "ALTER TABLE " + TABLE_SQ_JOB + " ADD CONSTRAINT "
+          + CONSTRAINT_SQB_NAME_UNIQUE + " UNIQUE (" + COLUMN_SQB_NAME + ")";
+
+  public static final String QUERY_UPGRADE_TABLE_SQ_LINK_ADD_UNIQUE_CONSTRAINT_NAME =
+      "ALTER TABLE " + TABLE_SQ_LINK + " ADD CONSTRAINT "
+          + CONSTRAINT_SQ_LNK_NAME_UNIQUE + " UNIQUE (" + COLUMN_SQ_LNK_NAME + ")";
+
   private DerbySchemaQuery() {
     // Disable explicit object creation
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/4c964a97/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
index bf72626..2da084f 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
@@ -37,12 +37,14 @@ import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_T
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_UPDATE_USER;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_JOB_ADD_CONSTRAINT_SQB_SQ_LNK_FROM;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_JOB_ADD_CONSTRAINT_SQB_SQ_LNK_TO;
+import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_JOB_ADD_UNIQUE_CONSTRAINT_NAME;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_JOB_REMOVE_COLUMN_SQB_TYPE;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_JOB_REMOVE_CONSTRAINT_SQB_SQ_LNK;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_JOB_RENAME_COLUMN_SQB_LINK_TO_SQB_FROM_LINK;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_LINK_ADD_COLUMN_CREATION_USER;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_LINK_ADD_COLUMN_ENABLED;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_LINK_ADD_COLUMN_UPDATE_USER;
+import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_LINK_ADD_UNIQUE_CONSTRAINT_NAME;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_SUBMISSION_ADD_COLUMN_CREATION_USER;
 import static org.apache.sqoop.repository.derby.DerbySchemaQuery.QUERY_UPGRADE_TABLE_SQ_SUBMISSION_ADD_COLUMN_UPDATE_USER;
 import static org.junit.Assert.assertEquals;
@@ -152,11 +154,13 @@ abstract public class DerbyTestCase {
       runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_CONSTRAINT_SQB_SQ_LNK_FROM);
       runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_CONSTRAINT_SQB_SQ_LNK_TO);
       runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_REMOVE_COLUMN_SQB_TYPE);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_UNIQUE_CONSTRAINT_NAME);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_ADD_UNIQUE_CONSTRAINT_NAME);
     }
 
     runQuery("INSERT INTO SQOOP.SQ_SYSTEM(SQM_KEY, SQM_VALUE) VALUES('version', '"  + version
+ "')");
     runQuery("INSERT INTO SQOOP.SQ_SYSTEM(SQM_KEY, SQM_VALUE) " +
-      "VALUES('" + DerbyRepoConstants.SYSKEY_DRIVER_VERSION + "', '1')");
+        "VALUES('" + DerbyRepoConstants.SYSKEY_DRIVER_VERSION + "', '1')");
   }
 
   protected void createSchema() throws Exception {
@@ -169,13 +173,19 @@ abstract public class DerbyTestCase {
    * @param query Query to execute
    * @throws Exception
    */
-  protected void runQuery(String query, String... args) throws Exception {
+  protected void runQuery(String query, Object... args) throws Exception {
     PreparedStatement stmt = null;
     try {
       stmt = getDerbyDatabaseConnection().prepareStatement(query);
 
       for (int i = 0; i < args.length; ++i) {
-        stmt.setString(i + 1, args[i]);
+        if (args[i] instanceof String) {
+          stmt.setString(i + 1, (String)args[i]);
+        } else if (args[i] instanceof Long) {
+          stmt.setLong(i + 1, (Long)args[i]);
+        } else {
+          stmt.setString(i + 1, args[i].toString());
+        }
       }
 
       stmt.execute();
@@ -436,6 +446,7 @@ abstract public class DerbyTestCase {
    * @throws Exception
    */
   public void loadJobs(int version) throws Exception {
+    int index = 0;
     switch (version) {
       case 2:
         for(String type : new String[] {"IMPORT", "EXPORT"}) {
@@ -468,7 +479,7 @@ abstract public class DerbyTestCase {
       case 4:
         for (String name : new String[]{"JA", "JB", "JC", "JD"}) {
           runQuery("INSERT INTO SQOOP.SQ_JOB(SQB_NAME, SQB_FROM_LINK, SQB_TO_LINK)"
-              + " VALUES('" + name + "', 1, 1)");
+              + " VALUES('" + name + index + "', 1, 1)");
         }
 
         // Odd IDs inputs have values

http://git-wip-us.apache.org/repos/asf/sqoop/blob/4c964a97/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
index 1292168..0eb9df4 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
@@ -17,10 +17,18 @@
  */
 package org.apache.sqoop.repository.derby;
 
+import org.apache.sqoop.common.SqoopException;
 import org.junit.Before;
 import org.junit.Test;
 
 import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -53,6 +61,17 @@ public class TestInternals extends DerbyTestCase {
     assertTrue(handler.haveSuitableInternals(getDerbyDatabaseConnection()));
   }
 
+  @Test(expected=SqoopException.class)
+  public void testUpgradeVersion2ToVersion4DuplicateFailure() throws Exception {
+    createSchema(2);
+    assertFalse(handler.haveSuitableInternals(getDerbyDatabaseConnection()));
+    loadConnectorAndDriverConfig(2);
+    loadLinks(2);
+    loadJobs(2);
+    handler.createOrUpdateInternals(getDerbyDatabaseConnection());
+    assertTrue(handler.haveSuitableInternals(getDerbyDatabaseConnection()));
+  }
+
   @Test
   public void testUpgradeVersion2ToVersion4() throws Exception {
     createSchema(2);
@@ -60,10 +79,62 @@ public class TestInternals extends DerbyTestCase {
     loadConnectorAndDriverConfig(2);
     loadLinks(2);
     loadJobs(2);
+    renameLinks();
+    renameJobs();
     handler.createOrUpdateInternals(getDerbyDatabaseConnection());
     assertTrue(handler.haveSuitableInternals(getDerbyDatabaseConnection()));
   }
 
+  private Map<String, List<Long>> getNameIdMap(PreparedStatement ps) throws SQLException
{
+    Map<String, List<Long>> nameIdMap = new TreeMap<String, List<Long>>();
+    ResultSet rs = null;
+
+    try {
+      rs = ps.executeQuery();
+      while(rs.next()) {
+        if (!nameIdMap.containsKey(rs.getString(1))) {
+          nameIdMap.put(rs.getString(1), new LinkedList<Long>());
+        }
+        nameIdMap.get(rs.getString(1)).add(rs.getLong(2));
+      }
+    } finally {
+      if(rs != null) {
+        rs.close();
+      }
+      if(ps != null) {
+        ps.close();
+      }
+    }
+
+    return nameIdMap;
+  }
+
+  private void renameLinks() throws Exception {
+    Map<String, List<Long>> nameIdMap =
+        getNameIdMap(getDerbyDatabaseConnection().prepareStatement("SELECT SQ_LNK_NAME, SQ_LNK_ID
FROM SQOOP.SQ_LINK"));;
+
+    for (String name : nameIdMap.keySet()) {
+      if (nameIdMap.get(name).size() > 1) {
+        for (Long id : nameIdMap.get(name)) {
+          runQuery("UPDATE SQOOP.SQ_LINK SET SQ_LNK_NAME=? WHERE SQ_LNK_ID=?", name + "-"
+ id, id);
+        }
+      }
+    }
+  }
+
+  private void renameJobs() throws Exception {
+    Map<String, List<Long>> nameIdMap =
+        getNameIdMap(getDerbyDatabaseConnection().prepareStatement("SELECT SQB_NAME, SQB_ID
FROM SQOOP.SQ_JOB"));;
+
+    for (String name : nameIdMap.keySet()) {
+      if (nameIdMap.get(name).size() > 1) {
+        for (Long id : nameIdMap.get(name)) {
+          runQuery("UPDATE SQOOP.SQ_JOB SET SQB_NAME=? WHERE SQB_ID=?", name + "-" + id,
id);
+        }
+      }
+    }
+  }
+
   private class TestDerbyRepositoryHandler extends DerbyRepositoryHandler {
     protected long registerHdfsConnector(Connection conn) {
       try {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/4c964a97/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
index 595b1c8..0752923 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java
@@ -76,7 +76,7 @@ public class TestJobHandling extends DerbyTestCase {
     MJob firstJob = handler.findJob(1, derbyConnection);
     assertNotNull(firstJob);
     assertEquals(1, firstJob.getPersistenceId());
-    assertEquals("JA", firstJob.getName());
+    assertEquals("JA0", firstJob.getName());
 
     List<MConfig> configs;
 
@@ -114,13 +114,13 @@ public class TestJobHandling extends DerbyTestCase {
     list = handler.findJobs(derbyConnection);
     assertEquals(4, list.size());
 
-    assertEquals("JA", list.get(0).getName());
+    assertEquals("JA0", list.get(0).getName());
 
-    assertEquals("JB", list.get(1).getName());
+    assertEquals("JB0", list.get(1).getName());
 
-    assertEquals("JC", list.get(2).getName());
+    assertEquals("JC0", list.get(2).getName());
 
-    assertEquals("JD", list.get(3).getName());
+    assertEquals("JD0", list.get(3).getName());
   }
 
   @Test
@@ -193,6 +193,19 @@ public class TestJobHandling extends DerbyTestCase {
     assertCountForTable("SQOOP.SQ_JOB_INPUT", 12);
   }
 
+  @Test(expected=SqoopException.class)
+  public void testCreateDuplicateJob() throws Exception {
+    // Duplicate jobs
+    MJob job = getJob();
+    fillJob(job);
+    job.setName("test");
+    handler.createJob(job, getDerbyDatabaseConnection());
+    assertEquals(1, job.getPersistenceId());
+
+    job.setPersistenceId(MJob.PERSISTANCE_ID_DEFAULT);
+    handler.createJob(job, getDerbyDatabaseConnection());
+  }
+
   @Test
   public void testUpdateJob() throws Exception {
     loadJobs();

http://git-wip-us.apache.org/repos/asf/sqoop/blob/4c964a97/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java
index 38e632a..bbfe5bb 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java
@@ -147,6 +147,18 @@ public class TestLinkHandling extends DerbyTestCase {
     assertCountForTable("SQOOP.SQ_LINK_INPUT", 4);
   }
 
+  @Test(expected=SqoopException.class)
+  public void testCreateDuplicateLink() throws Exception {
+    MLink link = getLink();
+    fillLink(link);
+    link.setName("test");
+    handler.createLink(link, getDerbyDatabaseConnection());
+    assertEquals(1, link.getPersistenceId());
+
+    link.setPersistenceId(MLink.PERSISTANCE_ID_DEFAULT);
+    handler.createLink(link, getDerbyDatabaseConnection());
+  }
+
   @Test
   public void testInUseLink() throws Exception {
     loadLinks();


Mime
View raw message