mirror of
https://github.com/apache/sqoop.git
synced 2025-05-11 22:41:50 +08:00
SQOOP-2588: Sqoop2: CommonRepositoryHandler#inUseLink only check if link is used in the from side of a job
(Dian Fu via Jarek Jarcec Cecho)
This commit is contained in:
parent
5d4dd08e2c
commit
6be57ae7e6
@ -448,6 +448,7 @@ public boolean inUseLink(String linkName, Connection conn) {
|
||||
|
||||
try (PreparedStatement stmt = conn.prepareStatement(crudQueries.getStmtSelectJobsForLinkCheck())) {
|
||||
stmt.setString(1, linkName);
|
||||
stmt.setString(2, linkName);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
|
||||
// Should be always valid in case of count(*) query
|
||||
|
@ -397,12 +397,18 @@ public class CommonRepositoryInsertUpdateDeleteSelectQuery {
|
||||
|
||||
// DML: Check if there are jobs for given link
|
||||
private static final String STMT_SELECT_JOBS_FOR_LINK_CHECK =
|
||||
"SELECT"
|
||||
+ " count(*)"
|
||||
"SELECT SUM(CNT) FROM ("
|
||||
+ " SELECT count(*) as CNT"
|
||||
+ " FROM " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
|
||||
+ " INNER JOIN " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
|
||||
+ " ON " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_FROM_LINK) + " = " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_ID)
|
||||
+ " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " = ? ";
|
||||
+ " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " = ? "
|
||||
+ " UNION ALL"
|
||||
+ " SELECT count(*) as CNT"
|
||||
+ " FROM " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
|
||||
+ " INNER JOIN " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
|
||||
+ " ON " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_TO_LINK) + " = " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_ID)
|
||||
+ " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " = ? ) as JOB_COUNT";
|
||||
|
||||
//DML: Select all jobs
|
||||
private static final String STMT_SELECT_JOB_ALL =
|
||||
|
@ -668,7 +668,7 @@ public void loadJobs(int version) throws Exception {
|
||||
case 7:
|
||||
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 + index + "', 1, 1)");
|
||||
+ name + index + "', 1, 2)");
|
||||
}
|
||||
|
||||
// Odd IDs inputs have values
|
||||
|
@ -210,10 +210,12 @@ public void testInUseLink() throws Exception {
|
||||
loadLinksForLatestVersion();
|
||||
|
||||
assertFalse(handler.inUseLink("CA", getDerbyDatabaseConnection()));
|
||||
assertFalse(handler.inUseLink("CB", getDerbyDatabaseConnection()));
|
||||
|
||||
loadJobsForLatestVersion();
|
||||
|
||||
assertTrue(handler.inUseLink("CA", getDerbyDatabaseConnection()));
|
||||
assertTrue(handler.inUseLink("CB", getDerbyDatabaseConnection()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -217,16 +217,20 @@ public void testInUseLink() throws Exception {
|
||||
// Create job and submission and make that job in use to make sure link is
|
||||
// in use.
|
||||
MLink linkA = handler.findLink(LINK_A_NAME, provider.getConnection());
|
||||
MLink linkB = handler.findLink(LINK_B_NAME, provider.getConnection());
|
||||
MJob job = getJob("Job-A",
|
||||
handler.findConnector("A", provider.getConnection()),
|
||||
handler.findConnector("B", provider.getConnection()), linkA,
|
||||
handler.findLink(LINK_B_NAME, provider.getConnection()));
|
||||
handler.findConnector("B", provider.getConnection()),
|
||||
linkA,
|
||||
linkB);
|
||||
handler.createJob(job, provider.getConnection());
|
||||
MSubmission submission = getSubmission(job, SubmissionStatus.RUNNING);
|
||||
handler.createSubmission(submission, provider.getConnection());
|
||||
|
||||
assertTrue(handler.inUseLink(linkA.getName(),
|
||||
provider.getConnection()));
|
||||
assertTrue(handler.inUseLink(linkB.getName(),
|
||||
provider.getConnection()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -212,16 +212,18 @@ public void testInUseLink() throws Exception {
|
||||
|
||||
// Create job and submission and make that job in use to make sure link is in use.
|
||||
MLink linkA = handler.findLink(LINK_A_NAME, provider.getConnection());
|
||||
MLink linkB = handler.findLink(LINK_B_NAME, provider.getConnection());
|
||||
MJob job = getJob("Job-A",
|
||||
handler.findConnector("A", provider.getConnection()),
|
||||
handler.findConnector("B", provider.getConnection()),
|
||||
linkA,
|
||||
handler.findLink(LINK_B_NAME, provider.getConnection()));
|
||||
linkB);
|
||||
handler.createJob(job, provider.getConnection());
|
||||
MSubmission submission = getSubmission(job, SubmissionStatus.RUNNING);
|
||||
handler.createSubmission(submission, provider.getConnection());
|
||||
|
||||
assertTrue(handler.inUseLink(linkA.getName(), provider.getConnection()));
|
||||
assertTrue(handler.inUseLink(linkB.getName(), provider.getConnection()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user