From a2e87bef0173974799427550770caa620d165b29 Mon Sep 17 00:00:00 2001 From: Jarek Jarcec Cecho Date: Wed, 12 Nov 2014 23:41:59 -0800 Subject: [PATCH] SQOOP-1723: Sqoop2: findJobsByConnector fails (Veena Basavaraj via Jarek Jarcec Cecho) --- .../common/CommonRepositoryHandler.java | 8 ++-- ...positoryInsertUpdateDeleteSelectQuery.java | 14 ++++--- .../derby/DerbyRepositoryHandler.java | 2 + ...bySchemaInsertUpdateDeleteSelectQuery.java | 32 ---------------- .../repository/derby/TestJobHandling.java | 35 ++++++++++++++++-- .../repository/derby/TestLinkHandling.java | 37 +++++++++++++++++-- 6 files changed, 79 insertions(+), 49 deletions(-) diff --git a/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepositoryHandler.java b/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepositoryHandler.java index 9f4ecbc1..42c40e65 100644 --- a/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepositoryHandler.java +++ b/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepositoryHandler.java @@ -149,7 +149,8 @@ public void registerConnector(MConnector mc, Connection conn) { public List findJobsForConnector(long connectorId, Connection conn) { PreparedStatement stmt = null; try { - stmt = conn.prepareStatement(CommonRepositoryInsertUpdateDeleteSelectQuery.STMT_SELECT_ALL_JOBS_FOR_CONNECTOR_CONFIGURABLE); + stmt = conn + .prepareStatement(CommonRepositoryInsertUpdateDeleteSelectQuery.STMT_SELECT_ALL_JOBS_FOR_CONNECTOR_CONFIGURABLE); stmt.setLong(1, connectorId); stmt.setLong(2, connectorId); return loadJobs(stmt, conn); @@ -894,10 +895,9 @@ public MJob findJob(String name, Connection conn) { public List findJobs(Connection conn) { PreparedStatement stmt = null; try { - stmt = conn.prepareStatement(CommonRepositoryInsertUpdateDeleteSelectQuery.STMT_SELECT_JOB); - + stmt = conn + .prepareStatement(CommonRepositoryInsertUpdateDeleteSelectQuery.STMT_SELECT_JOB_ALL); return loadJobs(stmt, conn); - } catch (SQLException ex) { logException(ex); throw new SqoopException(CommonRepositoryError.COMMON_0028, ex); diff --git a/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepositoryInsertUpdateDeleteSelectQuery.java b/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepositoryInsertUpdateDeleteSelectQuery.java index 921f12f9..bff56a69 100644 --- a/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepositoryInsertUpdateDeleteSelectQuery.java +++ b/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepositoryInsertUpdateDeleteSelectQuery.java @@ -343,7 +343,7 @@ public class CommonRepositoryInsertUpdateDeleteSelectQuery { + " WHERE " + COLUMN_SQ_LNK_ID + " = ? "; //DML: Select all jobs - public static final String STMT_SELECT_JOB = + public static final String STMT_SELECT_JOB_ALL = "SELECT " + "FROM_CONNECTOR." + COLUMN_SQ_LNK_CONFIGURABLE + ", " + "TO_CONNECTOR." + COLUMN_SQ_LNK_CONFIGURABLE + ", " @@ -364,17 +364,19 @@ public class CommonRepositoryInsertUpdateDeleteSelectQuery { // DML: Select one specific job public static final String STMT_SELECT_JOB_SINGLE_BY_ID = - STMT_SELECT_JOB + " WHERE " + COLUMN_SQB_ID + " = ?"; + STMT_SELECT_JOB_ALL + + " WHERE " + COLUMN_SQB_ID + " = ?"; // DML: Select one specific job public static final String STMT_SELECT_JOB_SINGLE_BY_NAME = - STMT_SELECT_JOB + " WHERE " + COLUMN_SQB_NAME + " = ?"; + STMT_SELECT_JOB_ALL + + " WHERE " + COLUMN_SQB_NAME + " = ?"; // DML: Select all jobs for a Connector public static final String STMT_SELECT_ALL_JOBS_FOR_CONNECTOR_CONFIGURABLE = - STMT_SELECT_JOB - + " WHERE FROM_LINK." + COLUMN_SQ_LNK_CONFIGURABLE + " = ? OR TO_LINK." - + COLUMN_SQ_LNK_CONFIGURABLE + " = ?"; + STMT_SELECT_JOB_ALL + + " WHERE FROM_CONNECTOR." + COLUMN_SQ_LNK_CONFIGURABLE + " = ?" + + " OR TO_CONNECTOR." + COLUMN_SQ_LNK_CONFIGURABLE + " = ?"; /**********SUBMISSION TABLE **************/ // DML: Insert new submission 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 4d99a52a..b5c9efc9 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 @@ -19,6 +19,8 @@ import static org.apache.sqoop.repository.derby.DerbySchemaCreateQuery.*; import static org.apache.sqoop.repository.derby.DerbySchemaInsertUpdateDeleteSelectQuery.*; +import static org.apache.sqoop.repository.common.CommonRepositoryInsertUpdateDeleteSelectQuery.*; + import static org.apache.sqoop.repository.derby.DerbySchemaUpgradeQuery.*; import java.net.URL; import java.sql.Connection; diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaInsertUpdateDeleteSelectQuery.java b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaInsertUpdateDeleteSelectQuery.java index 4cbaf5ad..5ffd9396 100644 --- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaInsertUpdateDeleteSelectQuery.java +++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaInsertUpdateDeleteSelectQuery.java @@ -83,28 +83,6 @@ public final class DerbySchemaInsertUpdateDeleteSelectQuery { + COLUMN_SQN_UPDATE_USER + ", " + COLUMN_SQN_UPDATE_DATE + ") VALUES (?, ?, ?, ?, ?, ?, ?)"; - /**********JOB TABLE **************/ - //DML: Select all jobs - public static final String STMT_SELECT_JOB = - "SELECT " - + "FROM_CONNECTOR." + COLUMN_SQ_LNK_CONFIGURABLE + ", " - + "TO_CONNECTOR." + COLUMN_SQ_LNK_CONFIGURABLE + ", " - + "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; - - /******* CONFIG and CONNECTOR DIRECTIONS ****/ public static final String STMT_INSERT_DIRECTION = "INSERT INTO " + TABLE_SQ_DIRECTION + " " + "(" + COLUMN_SQD_NAME + ") VALUES (?)"; @@ -115,16 +93,6 @@ public final class DerbySchemaInsertUpdateDeleteSelectQuery { + COLUMN_SQ_CFG_DIRECTION + " FROM " + TABLE_SQ_CONFIG; - public static final String STMT_INSERT_SQ_CONNECTOR_DIRECTIONS = - "INSERT INTO " + TABLE_SQ_CONNECTOR_DIRECTIONS + " " - + "(" + COLUMN_SQCD_CONNECTOR + ", " + COLUMN_SQCD_DIRECTION + ")" - + " VALUES (?, ?)"; - - public static final String STMT_INSERT_SQ_CONFIG_DIRECTIONS = - "INSERT INTO " + TABLE_SQ_CONFIG_DIRECTIONS + " " - + "(" + COLUMN_SQ_CFG_DIR_CONFIG + ", " + COLUMN_SQ_CFG_DIR_DIRECTION + ")" - + " VALUES (?, ?)"; - private DerbySchemaInsertUpdateDeleteSelectQuery() { // Disable explicit object creation } 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 45a96ad6..309e6b25 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 @@ -108,19 +108,46 @@ public void testFindJobs() throws Exception { assertEquals(0, list.size()); loadJobsForLatestVersion(); - // Load all two connections on loaded repository + // Load all two links on loaded repository list = handler.findJobs(derbyConnection); assertEquals(4, list.size()); assertEquals("JA0", list.get(0).getName()); - assertEquals("JB0", list.get(1).getName()); - assertEquals("JC0", list.get(2).getName()); - assertEquals("JD0", list.get(3).getName()); } + @Test + public void testFindJobsByConnector() throws Exception { + List list; + // Load empty list on empty repository + list = handler.findJobs(derbyConnection); + assertEquals(0, list.size()); + loadJobsForLatestVersion(); + + // Load all 4 jobs on loaded repository + list = handler.findJobsForConnector(1, derbyConnection); + assertEquals(4, list.size()); + + assertEquals("JA0", list.get(0).getName()); + assertEquals("JB0", list.get(1).getName()); + assertEquals("JC0", list.get(2).getName()); + assertEquals("JD0", list.get(3).getName()); + } + + @Test + public void testFindJobsForNonExistingConnector() throws Exception { + List list; + // Load empty list on empty repository + list = handler.findJobs(derbyConnection); + assertEquals(0, list.size()); + loadJobsForLatestVersion(); + + list = handler.findJobsForConnector(11, derbyConnection); + assertEquals(0, list.size()); + } + @Test public void testExistsJob() throws Exception { // There shouldn't be anything on empty repository 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 8ab384a5..6274d114 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 @@ -63,7 +63,7 @@ public void testFindLink() throws Exception { assertEquals(CommonRepositoryError.COMMON_0021, ex.getErrorCode()); } - // Load prepared connections into database + // Load prepared links into database loadLinksForLatestVersion(); MLink linkA = handler.findLink(1, getDerbyDatabaseConnection()); @@ -85,7 +85,7 @@ public void testFindLink() throws Exception { public void testFindLinkByName() throws Exception { // Let's try to find non existing link assertNull(handler.findLink("non-existing", getDerbyDatabaseConnection())); - // Load prepared connections into database + // Load prepared links into database loadLinksForLatestVersion(); MLink linkA = handler.findLink("CA", getDerbyDatabaseConnection()); @@ -113,7 +113,7 @@ public void testFindLinks() throws Exception { loadLinksForLatestVersion(); - // Load all two connections on loaded repository + // Load all two links on loaded repository list = handler.findLinks(getDerbyDatabaseConnection()); assertEquals(2, list.size()); @@ -121,6 +121,37 @@ public void testFindLinks() throws Exception { assertEquals("CB", list.get(1).getName()); } + @Test + public void testFindLinksByConnector() throws Exception { + List list; + + // Load empty list on empty repository + list = handler.findLinks(getDerbyDatabaseConnection()); + assertEquals(0, list.size()); + + loadLinksForLatestVersion(); + + // Load all two links on loaded repository + list = handler.findLinksForConnector(1, getDerbyDatabaseConnection()); + assertEquals(2, list.size()); + + assertEquals("CA", list.get(0).getName()); + assertEquals("CB", list.get(1).getName()); + } + + public void testFindLinksByNonExistingConnector() throws Exception { + List list; + + // Load empty list on empty repository + list = handler.findLinks(getDerbyDatabaseConnection()); + assertEquals(0, list.size()); + + loadLinksForLatestVersion(); + + list = handler.findLinksForConnector(2, getDerbyDatabaseConnection()); + assertEquals(0, list.size()); + } + @Test public void testExistsLink() throws Exception { // There shouldn't be anything on empty repository