ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-4420. ORA-01795: maximum number of expressions in a list is 1000 in Ambari Server log. (swagle)
Date Fri, 24 Jan 2014 23:22:31 GMT
Updated Branches:
  refs/heads/branch-1.4.4 1ac860878 -> 70c9163ce


AMBARI-4420. ORA-01795: maximum number of expressions in a list is 1000 in Ambari Server log.
(swagle)


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

Branch: refs/heads/branch-1.4.4
Commit: 70c9163cee723adb38945ed5692b73ab77bd7ef8
Parents: 1ac8608
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Fri Jan 24 14:40:50 2014 -0800
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Fri Jan 24 14:40:50 2014 -0800

----------------------------------------------------------------------
 .../apache/ambari/server/orm/dao/DaoUtils.java  |  4 +++-
 .../server/orm/dao/HostRoleCommandDAO.java      | 23 +++++++++++++++-----
 2 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/70c9163c/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
index f35b483..f181706 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
@@ -29,6 +29,8 @@ import java.util.List;
 @Singleton
 class DaoUtils {
 
+  public static final int ORACLE_LIST_LIMIT = 999;
+
   public <T> List<T> selectList(TypedQuery<T> query, Object... parameters)
{
     setParameters(query, parameters);
     try {
@@ -63,7 +65,7 @@ class DaoUtils {
 
   public void setParameters(Query query, Object... parameters) {
     for (int i = 0; i < parameters.length; i++) {
-      query.setParameter(i+1, parameters[i]);
+      query.setParameter(i + 1, parameters[i]);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/70c9163c/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
index 5678887..e70f5c7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
@@ -18,11 +18,11 @@
 
 package org.apache.ambari.server.orm.dao;
 
+import com.google.common.collect.Lists;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
 import com.google.inject.persist.Transactional;
-import org.apache.ambari.server.Role;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
@@ -31,9 +31,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.persistence.EntityManager;
-import javax.persistence.Query;
 import javax.persistence.TypedQuery;
-
 import java.util.*;
 
 @Singleton
@@ -52,12 +50,27 @@ public class HostRoleCommandDAO {
   }
 
   @Transactional
-  public List<HostRoleCommandEntity> findByPKs(Collection<Long> taskIds) {
+  public List<HostRoleCommandEntity> findByPKs(List<Long> taskIds) {
     TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery(
         "SELECT task FROM HostRoleCommandEntity task WHERE task.taskId IN ?1 " +
             "ORDER BY task.taskId",
         HostRoleCommandEntity.class);
-    return daoUtils.selectList(query, taskIds);
+
+
+    //TODO temp fix unnecessary for dbms different from oracle
+    List<HostRoleCommandEntity> result;
+
+    if (taskIds.size() > DaoUtils.ORACLE_LIST_LIMIT) {
+      result = new ArrayList<HostRoleCommandEntity>();
+      List<List<Long>> lists = Lists.partition(taskIds, DaoUtils.ORACLE_LIST_LIMIT);
+      for (List<Long> list : lists) {
+        result.addAll(daoUtils.selectList(query, list));
+      }
+    } else {
+      result = daoUtils.selectList(query, taskIds);
+    }
+
+    return result;
   }
 
   @Transactional


Mime
View raw message