sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-1075: Sqoop2: Persist Framework metadata version in repository
Date Tue, 30 Jul 2013 03:28:00 GMT
Updated Branches:
  refs/heads/sqoop2 69ecc93d4 -> a7d9b1b33


SQOOP-1075: Sqoop2: Persist Framework metadata version in repository

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

Branch: refs/heads/sqoop2
Commit: a7d9b1b3389582215053490590163e24f8ba25d9
Parents: 69ecc93
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon Jul 29 20:27:16 2013 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Mon Jul 29 20:27:16 2013 -0700

----------------------------------------------------------------------
 .../apache/sqoop/client/TestSqoopClient.java    |  3 +-
 .../org/apache/sqoop/json/FrameworkBean.java    |  5 +-
 .../sqoop/json/util/FormSerialization.java      |  1 +
 .../java/org/apache/sqoop/model/MConnector.java |  8 +--
 .../java/org/apache/sqoop/model/MFramework.java | 24 +++++--
 .../java/org/apache/sqoop/json/TestUtil.java    |  2 +-
 .../org/apache/sqoop/model/TestMFramework.java  |  2 +-
 .../sqoop/framework/FrameworkManager.java       |  5 +-
 .../sqoop/repository/TestJdbcRepository.java    |  7 ++-
 .../repository/derby/DerbyRepoConstants.java    |  2 +
 .../sqoop/repository/derby/DerbyRepoError.java  |  1 +
 .../derby/DerbyRepositoryHandler.java           | 66 +++++++++++++++++++-
 .../sqoop/repository/derby/DerbyTestCase.java   |  6 +-
 .../repository/derby/TestFrameworkHandling.java | 55 ++++++++++++++++
 14 files changed, 165 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/client/src/test/java/org/apache/sqoop/client/TestSqoopClient.java
----------------------------------------------------------------------
diff --git a/client/src/test/java/org/apache/sqoop/client/TestSqoopClient.java b/client/src/test/java/org/apache/sqoop/client/TestSqoopClient.java
index 1778cf1..3e0544a 100644
--- a/client/src/test/java/org/apache/sqoop/client/TestSqoopClient.java
+++ b/client/src/test/java/org/apache/sqoop/client/TestSqoopClient.java
@@ -184,7 +184,8 @@ public class TestSqoopClient {
   }
 
   private MFramework framework() {
-    MFramework framework = new MFramework(new MConnectionForms(null), new LinkedList<MJobForms>());
+    MFramework framework = new MFramework(new MConnectionForms(null),
+      new LinkedList<MJobForms>(), "1");
     framework.setPersistenceId(1);
     return framework;
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/common/src/main/java/org/apache/sqoop/json/FrameworkBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/FrameworkBean.java b/common/src/main/java/org/apache/sqoop/json/FrameworkBean.java
index ad4753b..eb79f98 100644
--- a/common/src/main/java/org/apache/sqoop/json/FrameworkBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/FrameworkBean.java
@@ -75,6 +75,7 @@ public class FrameworkBean implements JsonBean {
 
     JSONObject result = new JSONObject();
     result.put(ID, framework.getPersistenceId());
+    result.put(FRAMEWORK_VERSION, framework.getVersion());
     result.put(CON_FORMS, conForms);
     result.put(JOB_FORMS, jobForms);
     result.put(RESOURCES, extractResourceBundle(bundle));
@@ -85,6 +86,7 @@ public class FrameworkBean implements JsonBean {
   @SuppressWarnings("unchecked")
   public void restore(JSONObject jsonObject) {
     long id = (Long) jsonObject.get(ID);
+    String frameworkVersion = (String) jsonObject.get(FRAMEWORK_VERSION);
 
     List<MForm> connForms = restoreForms((JSONArray) jsonObject.get(CON_FORMS));
 
@@ -101,7 +103,8 @@ public class FrameworkBean implements JsonBean {
       jobs.add(new MJobForms(type, job));
     }
 
-    framework = new MFramework(new MConnectionForms(connForms), jobs);
+    framework = new MFramework(new MConnectionForms(connForms), jobs,
+      frameworkVersion);
     framework.setPersistenceId(id);
 
     bundle = restoreResourceBundle((JSONObject) jsonObject.get(RESOURCES));

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java b/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
index 978789b..3daf8d2 100644
--- a/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
+++ b/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
@@ -44,6 +44,7 @@ public final class FormSerialization {
   public static final String ID = "id";
   public static final String NAME = "name";
   public static final String VERSION = "version";
+  public static final String FRAMEWORK_VERSION = "framework-version";
   public static final String CLASS = "class";
   public static final String CREATED = "created";
   public static final String UPDATED = "updated";

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/common/src/main/java/org/apache/sqoop/model/MConnector.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MConnector.java b/common/src/main/java/org/apache/sqoop/model/MConnector.java
index 1c2c422..43fad27 100644
--- a/common/src/main/java/org/apache/sqoop/model/MConnector.java
+++ b/common/src/main/java/org/apache/sqoop/model/MConnector.java
@@ -30,11 +30,10 @@ public final class MConnector extends MFramework {
 
   private final String uniqueName;
   private final String className;
-  private final String version;
 
   public MConnector(String uniqueName, String className, String version,
       MConnectionForms connectionForms, List<MJobForms> jobForms) {
-    super(connectionForms, jobForms);
+    super(connectionForms, jobForms, version);
 
     if (uniqueName == null || className == null) {
       throw new NullPointerException();
@@ -42,7 +41,6 @@ public final class MConnector extends MFramework {
 
     this.uniqueName = uniqueName;
     this.className = className;
-    this.version = version;
   }
 
   public String getUniqueName() {
@@ -53,10 +51,6 @@ public final class MConnector extends MFramework {
     return className;
   }
 
-  public String getVersion() {
-    return version;
-  }
-
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder("connector-");

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/common/src/main/java/org/apache/sqoop/model/MFramework.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MFramework.java b/common/src/main/java/org/apache/sqoop/model/MFramework.java
index 694f022..c742459 100644
--- a/common/src/main/java/org/apache/sqoop/model/MFramework.java
+++ b/common/src/main/java/org/apache/sqoop/model/MFramework.java
@@ -32,8 +32,11 @@ public class MFramework extends MPersistableEntity implements MClonable
{
 
   private final MConnectionForms connectionForms;
   private final Map<MJob.Type, MJobForms> jobs;
+  String version;
 
-  public MFramework(MConnectionForms connectionForms, List<MJobForms> jobForms) {
+  public MFramework(MConnectionForms connectionForms, List<MJobForms> jobForms,
+    String version) {
+    this.version = version;
     this.connectionForms = connectionForms;
     this.jobs = new HashMap<MJob.Type, MJobForms>();
 
@@ -52,6 +55,7 @@ public class MFramework extends MPersistableEntity implements MClonable
{
   public String toString() {
     StringBuilder sb = new StringBuilder("framework-");
     sb.append(getPersistenceId()).append(":");
+    sb.append("version = " + version);
     sb.append(", ").append(connectionForms.toString());
     for(MJobForms entry: jobs.values()) {
       sb.append(entry.toString());
@@ -71,7 +75,9 @@ public class MFramework extends MPersistableEntity implements MClonable
{
     }
 
     MFramework mo = (MFramework) other;
-    return connectionForms.equals(mo.connectionForms) && jobs.equals(mo.jobs);
+    return version.equals(mo.getVersion()) &&
+      connectionForms.equals(mo.connectionForms) &&
+      jobs.equals(mo.jobs);
   }
 
   @Override
@@ -81,7 +87,7 @@ public class MFramework extends MPersistableEntity implements MClonable
{
     for(MJobForms entry: jobs.values()) {
       result = 31 * result + entry.hashCode();
     }
-
+    result = 31 * result + version.hashCode();
     return result;
   }
 
@@ -108,9 +114,19 @@ public class MFramework extends MPersistableEntity implements MClonable
{
         copyJobForms.add(entry.clone(cloneWithValue));
       }
     }
-    MFramework copy = new MFramework(this.getConnectionForms().clone(cloneWithValue), copyJobForms);
+    MFramework copy = new MFramework(this.getConnectionForms().clone(cloneWithValue),
+      copyJobForms, this.version);
     copy.setPersistenceId(this.getPersistenceId());
     return copy;
   }
+
+  public String getVersion() {
+    return version;
+  }
+
+  public void setVersion(String version) {
+    this.version = version;
+  }
+
 }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/common/src/test/java/org/apache/sqoop/json/TestUtil.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestUtil.java b/common/src/test/java/org/apache/sqoop/json/TestUtil.java
index b88d7a4..69dcb66 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestUtil.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestUtil.java
@@ -44,7 +44,7 @@ public class TestUtil {
   }
 
   public static MFramework getFramework() {
-    return new MFramework(getConnectionForms(), getAllJobForms());
+    return new MFramework(getConnectionForms(), getAllJobForms(), "1");
   }
 
   public static MConnection getConnection(String name) {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/common/src/test/java/org/apache/sqoop/model/TestMFramework.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMFramework.java b/common/src/test/java/org/apache/sqoop/model/TestMFramework.java
index a5366ca..15d9676 100644
--- a/common/src/test/java/org/apache/sqoop/model/TestMFramework.java
+++ b/common/src/test/java/org/apache/sqoop/model/TestMFramework.java
@@ -37,7 +37,7 @@ public class TestMFramework {
     jobForms.add(new MJobForms(MJob.Type.IMPORT, new ArrayList<MForm>()));
 
     try {
-      new MFramework(connectionForms, jobForms);
+      new MFramework(connectionForms, jobForms, "1");
       fail("We we're expecting exception for invalid usage");
     } catch(Exception ex) {
       // Expected case

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java b/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
index ad6cd0f..424285c 100644
--- a/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
+++ b/core/src/main/java/org/apache/sqoop/framework/FrameworkManager.java
@@ -111,6 +111,8 @@ public class FrameworkManager implements Reconfigurable {
    */
   private static final boolean DEFAULT_AUTO_UPGRADE = false;
 
+  public static final String CURRENT_FRAMEWORK_VERSION = "1";
+
   public Class getJobConfigurationClass(MJob.Type jobType) {
       switch (jobType) {
           case IMPORT:
@@ -134,7 +136,8 @@ public class FrameworkManager implements Reconfigurable {
       FormUtils.toForms(getJobConfigurationClass(MJob.Type.IMPORT))));
     jobForms.add(new MJobForms(MJob.Type.EXPORT,
       FormUtils.toForms(getJobConfigurationClass(MJob.Type.EXPORT))));
-    mFramework = new MFramework(connectionForms, jobForms);
+    mFramework = new MFramework(connectionForms, jobForms,
+      CURRENT_FRAMEWORK_VERSION);
 
     // Build validator
     validator = new FrameworkValidator();

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/core/src/test/java/org/apache/sqoop/repository/TestJdbcRepository.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/repository/TestJdbcRepository.java b/core/src/test/java/org/apache/sqoop/repository/TestJdbcRepository.java
index 247e165..40a6eca 100644
--- a/core/src/test/java/org/apache/sqoop/repository/TestJdbcRepository.java
+++ b/core/src/test/java/org/apache/sqoop/repository/TestJdbcRepository.java
@@ -924,7 +924,7 @@ public class TestJdbcRepository {
     doNothing().when(repoHandler).updateFramework(any(MFramework.class), any(Connection.class));
     doReturn(true).when(repoHandler).existsConnection(anyLong(), any(Connection.class));
     doReturn(true).when(repoHandler).existsJob(anyLong(), any(Connection.class));
-    doNothing().when(repoHandler).updateConnection(any(MConnection.class), any(Connection.class));;
+    doNothing().when(repoHandler).updateConnection(any(MConnection.class), any(Connection.class));
 
     SqoopException exception = new SqoopException(RepositoryError.JDBCREPO_0000,
         "update job error.");
@@ -969,13 +969,14 @@ public class TestJdbcRepository {
     jobForms.add(new MJobForms(MJob.Type.IMPORT, FormUtils.toForms(ImportJobConfiguration.class)));
 
     MFramework framework = new MFramework(new MConnectionForms(new LinkedList<MForm>()),
-        jobForms);
+      jobForms, FrameworkManager.CURRENT_FRAMEWORK_VERSION);
     framework.setPersistenceId(1);
     return framework;
   }
 
   private MFramework anotherFramework() {
-    MFramework framework = new MFramework(null, new LinkedList<MJobForms>());
+    MFramework framework = new MFramework(null, new LinkedList<MJobForms>(),
+      FrameworkManager.CURRENT_FRAMEWORK_VERSION);
     framework.setPersistenceId(1);
     return framework;
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConstants.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConstants.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConstants.java
index 607b8d5..bb01f03 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConstants.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConstants.java
@@ -23,6 +23,8 @@ public final class DerbyRepoConstants {
 
   public static final String SYSKEY_VERSION = "version";
 
+  public static final String SYSKEY_FRAMEWORK_VERSION = "framework.version";
+
   /**
    * Expected version of the repository structures.
    *

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
index 455eb64..e4b30f9 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
@@ -178,6 +178,7 @@ public enum DerbyRepoError implements ErrorCode {
   /** Can't enable/disable job **/
   DERBYREPO_0043("Can't enable/disable job"),
 
+  DERBYREPO_0044("Update of framework failed"),
   ;
 
   private final String message;

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/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 771673d..f025ee9 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
@@ -41,6 +41,7 @@ import javax.sql.DataSource;
 import org.apache.log4j.Logger;
 import org.apache.commons.lang.StringUtils;
 import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.framework.FrameworkManager;
 import org.apache.sqoop.model.MBooleanInput;
 import org.apache.sqoop.model.MConnection;
 import org.apache.sqoop.model.MConnectionForms;
@@ -308,6 +309,59 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
     }
   }
 
+  /**
+   * Detect version of the framework
+   *
+   * @param conn Connection to metadata repository
+   * @return Version of the MFramework
+   */
+  private String detectFrameworkVersion (Connection conn) {
+    ResultSet rs = null;
+    PreparedStatement stmt = null;
+    try {
+      stmt = conn.prepareStatement(DerbySchemaQuery.STMT_SELECT_SYSTEM);
+      stmt.setString(1, DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION);
+      rs = stmt.executeQuery();
+      if(!rs.next()) {
+        return null;
+      }
+      return rs.getString(1);
+    } catch (SQLException e) {
+      LOG.info("Can't fetch framework version.", e);
+      return null;
+    } finally {
+      closeResultSets(rs);
+      closeStatements(stmt);
+    }
+  }
+
+  /**
+   * Create or update framework version
+   * @param conn Connection to the metadata repository
+   * @param mFramework
+   */
+  private void createOrUpdateFrameworkVersion(Connection conn,
+      MFramework mFramework) {
+    ResultSet rs = null;
+    PreparedStatement stmt = null;
+    try {
+      stmt = conn.prepareStatement(STMT_DELETE_SYSTEM);
+      stmt.setString(1, DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION);
+      stmt.executeUpdate();
+      closeStatements(stmt);
+
+      stmt = conn.prepareStatement(STMT_INSERT_SYSTEM);
+      stmt.setString(1, DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION);
+      stmt.setString(2, mFramework.getVersion());
+      stmt.executeUpdate();
+    } catch (SQLException e) {
+      logException(e);
+      throw new SqoopException(DerbyRepoError.DERBYREPO_0044, e);
+    } finally {
+      closeResultSets(rs);
+      closeStatements(stmt);
+    }
+  }
 
   /**
    * {@inheritDoc}
@@ -466,6 +520,7 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
     } finally {
       closeStatements(baseFormStmt, baseInputStmt);
     }
+    createOrUpdateFrameworkVersion(conn, mf);
   }
 
   /**
@@ -493,7 +548,7 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
       }
 
       mf = new MFramework(new MConnectionForms(connectionForms),
-        convertToJobList(jobForms));
+        convertToJobList(jobForms), detectFrameworkVersion(conn));
 
       // We're using hardcoded value for framework metadata as they are
       // represented as NULL in the database.
@@ -846,10 +901,11 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
 
     } catch (SQLException e) {
       logException(e, mFramework);
-      throw new SqoopException(DerbyRepoError.DERBYREPO_0038, e);
+      throw new SqoopException(DerbyRepoError.DERBYREPO_0044, e);
     } finally {
       closeStatements(deleteForm, deleteInput);
     }
+    createOrUpdateFrameworkVersion(conn, mFramework);
     insertFormsForFramework(mFramework, conn);
 
   }
@@ -1975,6 +2031,9 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
    * @param resultSets Result sets to close
    */
   private void closeResultSets(ResultSet ... resultSets) {
+    if(resultSets == null) {
+      return;
+    }
     for (ResultSet rs : resultSets) {
       if(rs != null) {
         try {
@@ -1994,6 +2053,9 @@ public class DerbyRepositoryHandler extends JdbcRepositoryHandler {
    * @param stmts Statements to close
    */
   private void closeStatements(Statement... stmts) {
+    if(stmts == null) {
+      return;
+    }
     for (Statement stmt : stmts) {
       if(stmt != null) {
         try {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/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 b766b09..eac87b8 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
@@ -18,6 +18,7 @@
 package org.apache.sqoop.repository.derby;
 
 import junit.framework.TestCase;
+import org.apache.sqoop.framework.FrameworkManager;
 import org.apache.sqoop.model.MConnection;
 import org.apache.sqoop.model.MConnectionForms;
 import org.apache.sqoop.model.MConnector;
@@ -102,6 +103,8 @@ abstract public class DerbyTestCase extends TestCase {
     runQuery(QUERY_UPGRADE_TABLE_SQ_CONNECTION_ADD_COLUMN_ENABLED);
     runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_ENABLED);
     runQuery("INSERT INTO SQOOP.SQ_SYSTEM(SQM_KEY, SQM_VALUE) VALUES('version', '2')");
+    runQuery("INSERT INTO SQOOP.SQ_SYSTEM(SQM_KEY, SQM_VALUE) " +
+      "VALUES('framework.version', '1')");
   }
 
   /**
@@ -303,7 +306,8 @@ abstract public class DerbyTestCase extends TestCase {
   }
 
   protected MFramework getFramework() {
-    return new MFramework(getConnectionForms(), getJobForms());
+    return new MFramework(getConnectionForms(), getJobForms(),
+      FrameworkManager.CURRENT_FRAMEWORK_VERSION);
   }
 
   protected void fillConnection(MConnection connection) {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/a7d9b1b3/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
index 66611d4..50d1235 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
@@ -17,8 +17,13 @@
  */
 package org.apache.sqoop.repository.derby;
 
+import org.apache.sqoop.framework.FrameworkManager;
 import org.apache.sqoop.model.MFramework;
 
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
 /**
  * Test framework methods on Derby repository.
  */
@@ -71,5 +76,55 @@ public class TestFrameworkHandling extends DerbyTestCase {
     MFramework retrieved = handler.findFramework(getDerbyConnection());
     assertNotNull(retrieved);
     assertEquals(framework, retrieved);
+    assertEquals(framework.getVersion(), retrieved.getVersion());
+  }
+
+  private String getFrameworkVersion() throws Exception {
+    final String frameworkVersionQuery =
+      "SELECT SQM_VALUE FROM SQOOP.SQ_SYSTEM WHERE SQM_KEY=?";
+    String retVal = null;
+    PreparedStatement preparedStmt = null;
+    ResultSet resultSet = null;
+    try {
+      preparedStmt =
+        getDerbyConnection().prepareStatement(frameworkVersionQuery);
+      preparedStmt.setString(1, DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION);
+      resultSet = preparedStmt.executeQuery();
+      if(resultSet.next())
+        retVal = resultSet.getString(1);
+      return retVal;
+    } finally {
+      if(preparedStmt !=null) {
+        try {
+          preparedStmt.close();
+        } catch(SQLException e) {
+        }
+      }
+      if(resultSet != null) {
+        try {
+          resultSet.close();
+        } catch(SQLException e) {
+        }
+      }
+    }
   }
+
+  public void testFrameworkVersion() throws Exception {
+    handler.registerFramework(getFramework(), getDerbyConnection());
+
+    final String lowerVersion = Integer.toString(
+      Integer.parseInt(FrameworkManager.CURRENT_FRAMEWORK_VERSION) - 1);
+    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, getFrameworkVersion());
+    runQuery("UPDATE SQOOP.SQ_SYSTEM SET SQM_VALUE='" + lowerVersion +
+      "' WHERE SQM_KEY = '" + DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION + "'");
+    assertEquals(lowerVersion, getFrameworkVersion());
+
+    MFramework framework = getFramework();
+    handler.updateFramework(framework, getDerbyConnection());
+
+    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, framework.getVersion());
+
+    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, getFrameworkVersion());
+  }
+
 }


Mime
View raw message