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/25 02:07:43 UTC
git commit: SQOOP-1619: Sqoop2: Enforce Unique constraint for name on
configurable table
Repository: sqoop
Updated Branches:
refs/heads/sqoop2 24e9b4c5b -> d8e9ebc45
SQOOP-1619: Sqoop2: Enforce Unique constraint for name on configurable table
(Veena Basavaraj via Abraham Elmahrek)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/d8e9ebc4
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/d8e9ebc4
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/d8e9ebc4
Branch: refs/heads/sqoop2
Commit: d8e9ebc45cdfd10cb2efa2a1fb74c8b50f708e49
Parents: 24e9b4c
Author: Abraham Elmahrek <ab...@elmahrek.com>
Authored: Fri Oct 24 17:06:32 2014 -0700
Committer: Abraham Elmahrek <ab...@elmahrek.com>
Committed: Fri Oct 24 17:07:17 2014 -0700
----------------------------------------------------------------------
.../derby/DerbyRepositoryHandler.java | 2 +-
.../repository/derby/DerbySchemaConstants.java | 3 +
.../repository/derby/DerbySchemaQuery.java | 5 ++
.../sqoop/repository/derby/DerbyTestCase.java | 87 +++++++++++---------
.../derby/TestRespositorySchemaUpgrade.java | 42 ++++------
5 files changed, 75 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/d8e9ebc4/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 633e9df..b4b5f3e 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
@@ -437,13 +437,13 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
renameEntitiesForConnectionAndForm(conn);
// Change direction from VARCHAR to BIGINT + foreign key.
updateDirections(conn, insertDirections(conn));
-
renameConnectorToConfigurable(conn);
}
// Add unique constraints on job and links for version 4 onwards
if (repositoryVersion > 3) {
runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_UNIQUE_CONSTRAINT_NAME, conn);
runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_ADD_UNIQUE_CONSTRAINT_NAME, conn);
+ runQuery(QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ADD_UNIQUE_CONSTRAINT_NAME, conn);
}
// last step upgrade the repository version to the latest value in the code
upgradeRepositoryVersion(conn);
http://git-wip-us.apache.org/repos/asf/sqoop/blob/d8e9ebc4/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 de08261..f579b93 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
@@ -68,6 +68,9 @@ public final class DerbySchemaConstants {
public static final String COLUMN_SQC_TYPE = "SQC_TYPE";
+ public static final String CONSTRAINT_SQ_CONFIGURABLE_UNIQUE_NAME = CONSTRAINT_PREFIX + "SQC_NAME_UNIQUE";
+ public static final String CONSTRAINT_SQ_CONFIGURABLE_UNIQUE = SCHEMA_PREFIX + CONSTRAINT_SQ_CONFIGURABLE_UNIQUE_NAME;
+
// SQ_CONNECTOR_DIRECTIONS
public static final String TABLE_SQ_CONNECTOR_DIRECTIONS_NAME = "SQ_CONNECTOR_DIRECTIONS";
http://git-wip-us.apache.org/repos/asf/sqoop/blob/d8e9ebc4/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 ce1830e..0a5b467 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
@@ -1423,6 +1423,11 @@ public static final String STMT_SELECT_DEPRECATED_OR_NEW_SYSTEM_VERSION =
STMT_SELECT_SQ_CONFIG_DIRECTIONS_ALL + " WHERE "
+ COLUMN_SQ_CFG_DIR_CONFIG + " = ?";
+ //add unique constraint on the configurable table
+ public static final String QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ADD_UNIQUE_CONSTRAINT_NAME = "ALTER TABLE "
+ + TABLE_SQ_CONFIGURABLE + " ADD CONSTRAINT " + CONSTRAINT_SQ_CONFIGURABLE_UNIQUE + " UNIQUE ("
+ + COLUMN_SQC_NAME + ")";
+
private DerbySchemaQuery() {
// Disable explicit object creation
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/d8e9ebc4/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 b22dbd5..528653c 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
@@ -219,8 +219,9 @@ abstract public class DerbyTestCase {
runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_CONSTRAINT_SQB_SQN_TO);
runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_REMOVE_COLUMN_SQB_TYPE);
renameEntitiesForConnectionAndForm();
- // add the name constraints
+ // add the name constraint for job
runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_UNIQUE_CONSTRAINT_NAME);
+ // add the name constraint for link
runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_ADD_UNIQUE_CONSTRAINT_NAME);
runQuery(QUERY_UPGRADE_TABLE_SQ_CONFIG_DROP_COLUMN_SQ_CFG_DIRECTION_VARCHAR);
@@ -231,6 +232,8 @@ abstract public class DerbyTestCase {
runQuery(STMT_INSERT_DIRECTION, direction.toString());
}
renameConnectorToConfigurable();
+ // add the name constraint for configurable
+ runQuery(QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ADD_UNIQUE_CONSTRAINT_NAME);
}
// deprecated repository version
@@ -625,47 +628,55 @@ abstract public class DerbyTestCase {
}
}
- public void loadJobsForLatestVersion() throws Exception {
- loadJobs(DerbyRepoConstants.LATEST_DERBY_REPOSITORY_VERSION);
+ /**
+ * testing job with non unique name objects into repository.
+ *
+ * @param version
+ * system version 4
+ * @throws Exception
+ */
+ public void loadNonUniqueJobsInVersion4() throws Exception {
+ int index = 0;
+ // insert JAs
+ for (String name : new String[] { "JA", "JA", "JA", "JA" }) {
+ runQuery("INSERT INTO SQOOP.SQ_JOB(SQB_NAME, SQB_FROM_LINK, SQB_TO_LINK)" + " VALUES('"
+ + name + index + "', 1, 1)");
+ }
}
- protected void removeDuplicateLinkNames(int version) throws Exception {
- switch (version) {
- case 2:
- // nothing to do
- break;
- case 4:
- Map<String, List<Long>> nameIdMap = getNameToIdListMap(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);
- }
- }
- }
- break;
- }
+ /**
+ * testing link with non unique name objects into repository.
+ *
+ * @param version
+ * system version 4
+ * @throws Exception
+ */
+ public void loadNonUniqueLinksInVersion4() throws Exception {
+
+ // Insert two links - CA and CA
+ runInsertQuery("INSERT INTO SQOOP.SQ_LINK(SQ_LNK_NAME, SQ_LNK_CONFIGURABLE) " + "VALUES('CA', 1)");
+ runQuery("INSERT INTO SQOOP.SQ_LINK(SQ_LNK_NAME, SQ_LNK_CONFIGURABLE) " + "VALUES('CA', 1)");
}
- protected void removeDuplicateJobNames(int version) throws Exception {
- switch (version) {
- case 2:
- // nothing to do
- break;
- case 4:
- Map<String, List<Long>> nameIdMap = getNameToIdListMap(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);
- }
- }
- }
- }
+ /**
+ * testing configurable with non unique name objects into repository.
+ *
+ * @param version
+ * system version 4
+ * @throws Exception
+ */
+ public void loadNonUniqueConfigurablesInVersion4() throws Exception {
+
+ // Insert two configurable - CB and CB
+ runInsertQuery("INSERT INTO SQOOP.SQ_CONFIGURABLE(SQC_NAME, SQC_CLASS, SQC_VERSION, SQC_TYPE)"
+ + "VALUES('CB', 'org.apache.sqoop.test.B', '1.0-test', 'CONNECTOR')");
+ runInsertQuery("INSERT INTO SQOOP.SQ_CONFIGURABLE(SQC_NAME, SQC_CLASS, SQC_VERSION, SQC_TYPE)"
+ + "VALUES('CB', 'org.apache.sqoop.test.B', '1.0-test', 'CONNECTOR')");
+
+ }
+
+ public void loadJobsForLatestVersion() throws Exception {
+ loadJobs(DerbyRepoConstants.LATEST_DERBY_REPOSITORY_VERSION);
}
/**
http://git-wip-us.apache.org/repos/asf/sqoop/blob/d8e9ebc4/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java
index d4c4009..7687be7 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java
@@ -21,8 +21,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.sql.Connection;
+import java.sql.SQLIntegrityConstraintViolationException;
-import org.apache.sqoop.common.SqoopException;
import org.junit.Before;
import org.junit.Test;
@@ -50,42 +50,34 @@ public class TestRespositorySchemaUpgrade extends DerbyTestCase {
assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection()));
}
- // TODO(VB): This should really test for a specific SQL exception that violates the constraints
- @Test(expected=SqoopException.class)
- public void testUpgradeVersion4WithLinkNameAndJobNameDuplicateFailure() throws Exception {
+ @Test(expected=SQLIntegrityConstraintViolationException.class)
+ public void testUpgradeVersion4WithNonUniqueJobNameFailure() throws Exception {
super.createOrUpgradeSchema(4);
- super.loadConnectorAndDriverConfig(4);
- super.loadConnectionsOrLinks(4);
- super.loadJobs(4);
- // no removing of dupes for job name and link names, hence there should be a exception due to the unique name constraint
- handler.createOrUpgradeRepository(getDerbyDatabaseConnection());
- assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection()));
+ // try loading duplicate job names in version 4 and it should throw an exception
+ super.loadNonUniqueJobsInVersion4();
}
- // TODO: VB: follow up with the constraint code, which really does not test with examples that has
- // duplicate names, the id list is always of size 1
- //@Test
- public void testUpgradeVersion4WithLinkNameAndJobNameWithNoDuplication() throws Exception {
+ @Test(expected=SQLIntegrityConstraintViolationException.class)
+ public void testUpgradeVersion4WithNonUniqueLinkNamesAdded() throws Exception {
super.createOrUpgradeSchema(4);
- super.loadConnectorAndDriverConfig(4);
- super.loadConnectionsOrLinks(4);
- super.loadJobs(4);
- super.removeDuplicateLinkNames(4);
- super.removeDuplicateJobNames(4);
- // removing duplicate job name and link name, hence there should be no exception with unique name constraint
- handler.createOrUpgradeRepository(getDerbyDatabaseConnection());
- assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection()));
+ // try loading duplicate link names in version 4 and it should throw an exception
+ super.loadNonUniqueLinksInVersion4();
+ }
+
+ @Test(expected=SQLIntegrityConstraintViolationException.class)
+ public void testUpgradeVersion4WithNonUniqueConfigurableNamesAdded() throws Exception {
+ super.createOrUpgradeSchema(4);
+ // try loading duplicate configurable names in version 4 and it should throw an exception
+ super.loadNonUniqueConfigurablesInVersion4();
}
@Test
public void testUpgradeRepoVersion2ToVersion4() throws Exception {
+ // in case of version 2 schema there is no unique job/ link constraint
super.createOrUpgradeSchema(2);
assertFalse(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection()));
loadConnectorAndDriverConfig(2);
super.loadConnectionsOrLinks(2);
super.loadJobs(2);
- super.removeDuplicateLinkNames(2);
- super.removeDuplicateJobNames(2);
- // in case of version 2 schema there is no unique job/ link constraint
handler.createOrUpgradeRepository(getDerbyDatabaseConnection());
assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection()));
}