eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject eagle git commit: [EAGLE-687] updating SiteEntityToRelation to accept null values
Date Tue, 03 Jan 2017 02:10:51 GMT
Repository: eagle
Updated Branches:
  refs/heads/master 8b3729f97 -> d2fee6e6f


[EAGLE-687] updating SiteEntityToRelation to accept null values

Currently if you create site with any of the field set to NULL, it will throw
explored the way to use preparedStatements with explicitly specified parameters but that would
require quite a large refactoring on entire metadata module.
so came up with the fix that is based on current assumptions in SiteEntityServiceJDBCImpl
which is forming the sql in particular way that suits in SiteEntityToRelation.accept method.

Author: Jay <jhsonline@gmail.com>

Closes #758 from jhsenjaliya/EAGLE-687.


Project: http://git-wip-us.apache.org/repos/asf/eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/eagle/commit/d2fee6e6
Tree: http://git-wip-us.apache.org/repos/asf/eagle/tree/d2fee6e6
Diff: http://git-wip-us.apache.org/repos/asf/eagle/diff/d2fee6e6

Branch: refs/heads/master
Commit: d2fee6e6ff319f6a35e4c8209bd89d2d4e864c5c
Parents: 8b3729f
Author: Jay <jhsonline@gmail.com>
Authored: Tue Jan 3 10:10:37 2017 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Tue Jan 3 10:10:37 2017 +0800

----------------------------------------------------------------------
 .../jdbc/service/orm/SiteEntityToRelation.java  |  8 +++++---
 .../jdbc/SiteEntityServiceJDBCImplTest.java     | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/eagle/blob/d2fee6e6/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/orm/SiteEntityToRelation.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/orm/SiteEntityToRelation.java
b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/orm/SiteEntityToRelation.java
index 910dec2..ae633d2 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/orm/SiteEntityToRelation.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/orm/SiteEntityToRelation.java
@@ -29,15 +29,17 @@ public class SiteEntityToRelation implements ThrowableConsumer2<PreparedStatemen
     @Override
     public void accept(PreparedStatement statement, SiteEntity entity) throws SQLException
{
         int parameterIndex = 1;
-        if (StringUtils.isNotBlank(entity.getSiteId())) {
+        boolean addNullValue = (statement.getParameterMetaData().getParameterCount() >
5);
+
+        if (addNullValue || StringUtils.isNotBlank(entity.getSiteId())) {
             statement.setString(parameterIndex, entity.getSiteId());
             parameterIndex++;
         }
-        if (StringUtils.isNotBlank(entity.getSiteName())) {
+        if (addNullValue || StringUtils.isNotBlank(entity.getSiteName())) {
             statement.setString(parameterIndex, entity.getSiteName());
             parameterIndex++;
         }
-        if (StringUtils.isNotBlank(entity.getDescription())) {
+        if (addNullValue || StringUtils.isNotBlank(entity.getDescription())) {
             statement.setString(parameterIndex, entity.getDescription());
             parameterIndex++;
         }

http://git-wip-us.apache.org/repos/asf/eagle/blob/d2fee6e6/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/SiteEntityServiceJDBCImplTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/SiteEntityServiceJDBCImplTest.java
b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/SiteEntityServiceJDBCImplTest.java
index adb730f..88ed729 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/SiteEntityServiceJDBCImplTest.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/SiteEntityServiceJDBCImplTest.java
@@ -52,7 +52,27 @@ public class SiteEntityServiceJDBCImplTest extends JDBCMetadataTestBase
{
         Assert.assertEquals("testdesc", siteEntityFromDB.getDescription());
         Assert.assertEquals(createdTime, siteEntityFromDB.getCreatedTime());
         Assert.assertEquals(modifiedTime, siteEntityFromDB.getModifiedTime());
+    }
+
+    @Test
+    public void testInsertSiteEntityWithNullValues() throws SQLException {
+        SiteEntity siteEntity = new SiteEntity();
+        siteEntity.setSiteId("test-null-site");
 
+        siteEntityService.create(siteEntity);
+        String uuid = siteEntity.getUuid();
+        long createdTime = siteEntity.getCreatedTime();
+        long modifiedTime = siteEntity.getModifiedTime();
+
+        Collection<SiteEntity> results = siteEntityService.findAll();
+        Assert.assertEquals(1, results.size());
+        SiteEntity siteEntityFromDB = results.iterator().next();
+        Assert.assertEquals(uuid, siteEntityFromDB.getUuid());
+        Assert.assertEquals("test-null-site", siteEntityFromDB.getSiteId());
+        Assert.assertNull(siteEntityFromDB.getSiteName());
+        Assert.assertNull(siteEntityFromDB.getDescription());
+        Assert.assertEquals(createdTime, siteEntityFromDB.getCreatedTime());
+        Assert.assertEquals(modifiedTime, siteEntityFromDB.getModifiedTime());
     }
 
     @Test(expected = IllegalArgumentException.class)


Mime
View raw message