sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1368623 - in /sqoop/branches/sqoop2: common/src/main/java/org/apache/sqoop/model/ common/src/test/java/org/apache/sqoop/model/ core/src/main/java/org/apache/sqoop/connector/ repository/repository-derby/src/main/java/org/apache/sqoop/reposi...
Date Thu, 02 Aug 2012 17:51:31 GMT
Author: blee
Date: Thu Aug  2 17:51:30 2012
New Revision: 1368623

URL: http://svn.apache.org/viewvc?rev=1368623&view=rev
Log:
SQOOP-534: Add ability to find out if MPersistableEntity do already have persistent ID

Added:
    sqoop/branches/sqoop2/common/src/test/java/org/apache/sqoop/model/
    sqoop/branches/sqoop2/common/src/test/java/org/apache/sqoop/model/TestMPersistableEntity.java
  (with props)
Modified:
    sqoop/branches/sqoop2/common/src/main/java/org/apache/sqoop/model/MPersistableEntity.java
    sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
    sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java

Modified: sqoop/branches/sqoop2/common/src/main/java/org/apache/sqoop/model/MPersistableEntity.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/common/src/main/java/org/apache/sqoop/model/MPersistableEntity.java?rev=1368623&r1=1368622&r2=1368623&view=diff
==============================================================================
--- sqoop/branches/sqoop2/common/src/main/java/org/apache/sqoop/model/MPersistableEntity.java
(original)
+++ sqoop/branches/sqoop2/common/src/main/java/org/apache/sqoop/model/MPersistableEntity.java
Thu Aug  2 17:51:30 2012
@@ -22,7 +22,9 @@ package org.apache.sqoop.model;
  */
 public abstract class MPersistableEntity {
 
-  private long persistenceId = -1L;
+  public static final long PERSISTANCE_ID_DEFAULT = -1L;
+
+  private long persistenceId = PERSISTANCE_ID_DEFAULT;
 
   protected MPersistableEntity() {
     // Default constructor
@@ -36,6 +38,10 @@ public abstract class MPersistableEntity
     return persistenceId;
   }
 
+  public boolean hasPersistenceId() {
+    return persistenceId != PERSISTANCE_ID_DEFAULT;
+  }
+
   @Override
   public abstract String toString();
 }

Added: sqoop/branches/sqoop2/common/src/test/java/org/apache/sqoop/model/TestMPersistableEntity.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/common/src/test/java/org/apache/sqoop/model/TestMPersistableEntity.java?rev=1368623&view=auto
==============================================================================
--- sqoop/branches/sqoop2/common/src/test/java/org/apache/sqoop/model/TestMPersistableEntity.java
(added)
+++ sqoop/branches/sqoop2/common/src/test/java/org/apache/sqoop/model/TestMPersistableEntity.java
Thu Aug  2 17:51:30 2012
@@ -0,0 +1,32 @@
+package org.apache.sqoop.model;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+public class TestMPersistableEntity {
+
+  @Test
+  public void testPersistableId() {
+    PersistentId id = new PersistentId();
+
+    assertFalse(id.hasPersistenceId());
+
+    id.setPersistenceId(666);
+    assertTrue(id.hasPersistenceId());
+    assertEquals(666, id.getPersistenceId());
+  }
+
+  /**
+   * Testing class extending MPersistableEntity.
+   *
+   * Empty implementation with purpose to just test methods available
+   * directly in the abstract class.
+   */
+  public static class PersistentId extends MPersistableEntity {
+    @Override
+    public String toString() {
+      return null;
+    }
+  }
+
+}

Propchange: sqoop/branches/sqoop2/common/src/test/java/org/apache/sqoop/model/TestMPersistableEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java?rev=1368623&r1=1368622&r2=1368623&view=diff
==============================================================================
--- sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
(original)
+++ sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
Thu Aug  2 17:51:30 2012
@@ -135,12 +135,11 @@ public class ConnectorManager {
           }
         }
 
-        long connectorId = handler.getMetadata().getPersistenceId();
         String connectorName = handler.getUniqueName();
-        if (connectorId == -1) {
+        if (!handler.getMetadata().hasPersistenceId()) {
           throw new SqoopException(ConnectorError.CONN_0010, connectorName);
         }
-        nameMap.put(connectorId, connectorName);
+        nameMap.put(handler.getMetadata().getPersistenceId(), connectorName);
       }
       rtx.commit();
     } catch (Exception ex) {

Modified: sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java?rev=1368623&r1=1368622&r2=1368623&view=diff
==============================================================================
--- sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
(original)
+++ sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
Thu Aug  2 17:51:30 2012
@@ -69,7 +69,7 @@ public class DerbyRepositoryHandler impl
 
   @Override
   public void registerConnector(MConnector mc, Connection conn) {
-    if (mc.getPersistenceId() != -1L) {
+    if (mc.hasPersistenceId()) {
       throw new SqoopException(DerbyRepoError.DERBYREPO_0011,
           mc.getUniqueName());
     }



Mime
View raw message