cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [09/31] git commit: updated refs/heads/ui-restyle to ef74127
Date Mon, 30 Sep 2013 21:52:08 GMT
Added comments and finished off the work


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

Branch: refs/heads/ui-restyle
Commit: b60eef3e822b3f176e449b150594ae7a76bc306f
Parents: 5fd47cc
Author: Alex Huang <alex.huang@citrix.com>
Authored: Sat Sep 28 07:52:50 2013 -0700
Committer: Alex Huang <alex.huang@citrix.com>
Committed: Sat Sep 28 07:53:28 2013 -0700

----------------------------------------------------------------------
 .../cloud/agent/manager/AgentManagerImpl.java   |   7 +-
 .../dc/dao/StorageNetworkIpRangeDaoImpl.java    |  13 +-
 .../com/cloud/event/dao/UsageEventDaoImpl.java  |   2 +-
 .../src/com/cloud/host/dao/HostDaoImpl.java     | 269 ++++++++++---------
 .../com/cloud/user/AccountDetailsDaoImpl.java   |   7 +-
 .../db/TemplatePrimaryDataStoreDaoImpl.java     |  16 +-
 .../com/cloud/utils/db/GenericQueryBuilder.java |  74 +----
 .../cloud/utils/db/GenericSearchBuilder.java    | 226 +++++-----------
 .../db/src/com/cloud/utils/db/GroupBy.java      |   2 +-
 .../db/src/com/cloud/utils/db/SearchBase.java   | 213 ++++++++++++++-
 .../src/com/cloud/utils/db/SearchCriteria.java  |  83 ++----
 .../BareMetalPingServiceImpl.java               |   7 +-
 .../BaremetalDhcpManagerImpl.java               |  18 +-
 .../BaremetalKickStartServiceImpl.java          |   6 +-
 .../networkservice/BaremetalPxeElement.java     |  12 +-
 .../networkservice/BaremetalPxeManagerImpl.java |   8 +-
 .../com/cloud/ucs/manager/UcsManagerImpl.java   |  20 +-
 .../xen/discoverer/XcpServerDiscoverer.java     |  52 ++--
 .../api/query/dao/DiskOfferingJoinDaoImpl.java  |  25 +-
 .../consoleproxy/ConsoleProxyManagerImpl.java   |   5 +-
 .../network/StorageNetworkManagerImpl.java      |  12 +-
 .../src/com/cloud/storage/OCFS2ManagerImpl.java |  10 +-
 22 files changed, 561 insertions(+), 526 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
index 9c18753..51f6d72 100755
--- a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
@@ -97,9 +97,8 @@ import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.EntityManager;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.exception.HypervisorVersionChangedException;
@@ -1448,7 +1447,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             try {
                 List<Long> behindAgents = findAgentsBehindOnPing();
                 for (Long agentId : behindAgents) {
-                    GenericQueryBuilder<HostVO, HostVO> sc = GenericQueryBuilder.create(HostVO.class);
+                    QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
                     sc.and(sc.entity().getId(), Op.EQ, agentId);
                     HostVO h = sc.find();
                     if (h != null) {
@@ -1470,7 +1469,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                     }
                 }
 
-                GenericQueryBuilder<HostVO, HostVO> sc = GenericQueryBuilder.create(HostVO.class);
+                QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
                 sc.and(sc.entity().getResourceState(), Op.IN, ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance);
                 List<HostVO> hosts = sc.list();
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/engine/schema/src/com/cloud/dc/dao/StorageNetworkIpRangeDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/StorageNetworkIpRangeDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/StorageNetworkIpRangeDaoImpl.java
index f57acce..e1605d5 100755
--- a/engine/schema/src/com/cloud/dc/dao/StorageNetworkIpRangeDaoImpl.java
+++ b/engine/schema/src/com/cloud/dc/dao/StorageNetworkIpRangeDaoImpl.java
@@ -17,22 +17,17 @@
 package com.cloud.dc.dao;
 
 import java.util.List;
-import java.util.Map;
 
 import javax.ejb.Local;
-import javax.naming.ConfigurationException;
 
 import org.springframework.stereotype.Component;
 
 import com.cloud.dc.StorageNetworkIpRangeVO;
 import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
-import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
 
@@ -50,21 +45,21 @@ public class StorageNetworkIpRangeDaoImpl extends GenericDaoBase<StorageNetworkI
 	
 	@Override
     public List<StorageNetworkIpRangeVO> listByPodId(long podId) {
-		GenericQueryBuilder<StorageNetworkIpRangeVO, StorageNetworkIpRangeVO> sc = GenericQueryBuilder.create(StorageNetworkIpRangeVO.class);
+        QueryBuilder<StorageNetworkIpRangeVO> sc = QueryBuilder.create(StorageNetworkIpRangeVO.class);
 	    sc.and(sc.entity().getPodId(), Op.EQ, podId);
 		return sc.list();
     }
 
 	@Override
     public List<StorageNetworkIpRangeVO> listByRangeId(long rangeId) {
-		GenericQueryBuilder<StorageNetworkIpRangeVO, StorageNetworkIpRangeVO> sc = GenericQueryBuilder.create(StorageNetworkIpRangeVO.class);
+        QueryBuilder<StorageNetworkIpRangeVO> sc = QueryBuilder.create(StorageNetworkIpRangeVO.class);
 	    sc.and(sc.entity().getId(), Op.EQ, rangeId);
 		return sc.list();
     }
 
 	@Override
     public List<StorageNetworkIpRangeVO> listByDataCenterId(long dcId) {
-		GenericQueryBuilder<StorageNetworkIpRangeVO, StorageNetworkIpRangeVO> sc = GenericQueryBuilder.create(StorageNetworkIpRangeVO.class);
+        QueryBuilder<StorageNetworkIpRangeVO> sc = QueryBuilder.create(StorageNetworkIpRangeVO.class);
 	    sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId);
 		return sc.list();
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java b/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
index cda02ef..4f05bbe 100644
--- a/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
+++ b/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
@@ -66,7 +66,7 @@ public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implem
         IpeventsSearch.and("networktype", IpeventsSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
         IpeventsSearch.and().op("assignEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
         IpeventsSearch.or("releaseEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
-        IpeventsSearch.closeParen();
+        IpeventsSearch.cp();
         IpeventsSearch.done();
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
index d0d3a5c..4716810 100755
--- a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
+++ b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
@@ -64,7 +64,7 @@ import com.cloud.utils.db.UpdateBuilder;
 import com.cloud.utils.exception.CloudRuntimeException;
 
 @Component
-@Local(value = { HostDao.class })
+@Local(value = {HostDao.class})
 @DB(txn = false)
 @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1)
 public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao { //FIXME: , ExternalIdDao {
@@ -123,13 +123,17 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
     protected Attribute _msIdAttr;
     protected Attribute _pingTimeAttr;
 
-    @Inject protected HostDetailsDao _detailsDao;
-    @Inject protected HostTagsDao _hostTagsDao;
-    @Inject protected HostTransferMapDao _hostTransferDao;
-    @Inject protected ClusterDao _clusterDao;
+    @Inject
+    protected HostDetailsDao _detailsDao;
+    @Inject
+    protected HostTagsDao _hostTagsDao;
+    @Inject
+    protected HostTransferMapDao _hostTransferDao;
+    @Inject
+    protected ClusterDao _clusterDao;
 
     public HostDaoImpl() {
-    	super();
+        super();
     }
 
     @PostConstruct
@@ -271,18 +275,19 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
          * SearchCriteria.Op.LTEQ); UnmanagedDirectConnectSearch.cp(); UnmanagedDirectConnectSearch.cp();
          */
         try {
-        HostTransferSearch = _hostTransferDao.createSearchBuilder();
+            HostTransferSearch = _hostTransferDao.createSearchBuilder();
         } catch (Throwable e) {
-        	s_logger.debug("error", e);
+            s_logger.debug("error", e);
         }
         HostTransferSearch.and("id", HostTransferSearch.entity().getId(), SearchCriteria.Op.NULL);
-        UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(), JoinType.LEFTOUTER);
+        UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(),
+            JoinType.LEFTOUTER);
         ClusterManagedSearch = _clusterDao.createSearchBuilder();
         ClusterManagedSearch.and("managed", ClusterManagedSearch.entity().getManagedState(), SearchCriteria.Op.EQ);
-        UnmanagedDirectConnectSearch.join("ClusterManagedSearch", ClusterManagedSearch, ClusterManagedSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getClusterId(), JoinType.INNER);
+        UnmanagedDirectConnectSearch.join("ClusterManagedSearch", ClusterManagedSearch, ClusterManagedSearch.entity().getId(),
+            UnmanagedDirectConnectSearch.entity().getClusterId(), JoinType.INNER);
         UnmanagedDirectConnectSearch.done();
 
-
         DirectConnectSearch = createSearchBuilder();
         DirectConnectSearch.and("resource", DirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
         DirectConnectSearch.and("id", DirectConnectSearch.entity().getId(), SearchCriteria.Op.EQ);
@@ -386,7 +391,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
     public long countBy(long clusterId, ResourceState... states) {
         SearchCriteria<HostVO> sc = MaintenanceCountSearch.create();
 
-        sc.setParameters("resourceState", (Object[]) states);
+        sc.setParameters("resourceState", (Object[])states);
         sc.setParameters("cluster", clusterId);
 
         List<HostVO> hosts = listBy(sc);
@@ -482,7 +487,8 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
         return ownCluster;
     }
 
-    @Override @DB
+    @Override
+    @DB
     public List<HostVO> findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) {
         Transaction txn = Transaction.currentTxn();
 
@@ -580,24 +586,26 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
         return assignedHosts;
     }
 
-    @Override @DB
+    @Override
+    @DB
     public List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId) {
-    	Transaction txn = Transaction.currentTxn();
+        Transaction txn = Transaction.currentTxn();
 
-    	txn.start();
-    	SearchCriteria<HostVO> sc = UnmanagedApplianceSearch.create();
-    	sc.setParameters("lastPinged", lastPingSecondsAfter);
-        sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.BaremetalDhcp, Type.BaremetalPxe, Type.TrafficMonitor, Type.L2Networking);
-    	List<HostVO> hosts = lockRows(sc, null, true);
+        txn.start();
+        SearchCriteria<HostVO> sc = UnmanagedApplianceSearch.create();
+        sc.setParameters("lastPinged", lastPingSecondsAfter);
+        sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.BaremetalDhcp, Type.BaremetalPxe, Type.TrafficMonitor,
+            Type.L2Networking);
+        List<HostVO> hosts = lockRows(sc, null, true);
 
-    	for (HostVO host : hosts) {
-    		host.setManagementServerId(managementServerId);
-    		update(host.getId(), host);
-    	}
+        for (HostVO host : hosts) {
+            host.setManagementServerId(managementServerId);
+            update(host.getId(), host);
+        }
 
-    	txn.commit();
+        txn.commit();
 
-    	return hosts;
+        return hosts;
     }
 
     @Override
@@ -657,7 +665,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
         return listBy(sc);
     }
 
-
     @Override
     public List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag) {
         SearchBuilder<HostTagVO> hostTagSearch = null;
@@ -726,7 +733,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
         List<HostVO> result = new ArrayList<HostVO>();
         ResultSet rs = null;
         try {
-            String sql = "select h.id from host h left join  cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;" ;
+            String sql = "select h.id from host h left join  cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;";
             pstmt = txn.prepareStatement(sql);
             pstmt.setLong(1, timeout);
             rs = pstmt.executeQuery();
@@ -818,9 +825,9 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
     @DB
     public List<RunningHostCountInfo> getRunningHostCounts(Date cutTime) {
         String sql = "select * from (" + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid "
-                + "where h.status='Up' and h.type='SecondaryStorage' and m.last_update > ? " + "group by h.data_center_id, h.type " + "UNION ALL "
-                + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid "
-                + "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type";
+                     + "where h.status='Up' and h.type='SecondaryStorage' and m.last_update > ? " + "group by h.data_center_id, h.type " + "UNION ALL "
+                     + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid "
+                     + "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type";
 
         ArrayList<RunningHostCountInfo> l = new ArrayList<RunningHostCountInfo>();
 
@@ -870,90 +877,100 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
         return customSearch(sc, null).get(0);
     }
 
+    @Override
+    public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
+        HostVO host = findById(vo.getId());
+        if (host == null) {
+            if (event == Event.Remove && newStatus == Status.Removed) {
+                host = findByIdIncludingRemoved(vo.getId());
+            }
+        }
 
-	@Override
-	public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
-		HostVO host = findById(vo.getId());
-		if(host == null){
-		    if(event == Event.Remove && newStatus == Status.Removed){
-		        host = findByIdIncludingRemoved(vo.getId());
-		    }
-		}
-
-		if(host == null){
+        if (host == null) {
             return false;
-		}
-		long oldPingTime = host.getLastPinged();
-
-		SearchBuilder<HostVO> sb = createSearchBuilder();
-		sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
-		sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
-		sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
-		if (newStatus.checkManagementServer()) {
-			sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
-			sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
-			sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ);
-			sb.closeParen();
-		}
-		sb.done();
-
-		SearchCriteria<HostVO> sc = sb.create();
-
-		sc.setParameters("status", oldStatus);
-		sc.setParameters("id", host.getId());
-		sc.setParameters("update", host.getUpdated());
-		long oldUpdateCount = host.getUpdated();
-		if (newStatus.checkManagementServer()) {
-			sc.setParameters("ping", oldPingTime);
-			sc.setParameters("msid", host.getManagementServerId());
-		}
-
-		long newUpdateCount = host.incrUpdated();
-		UpdateBuilder ub = getUpdateBuilder(host);
-		ub.set(host, _statusAttr, newStatus);
-		if (newStatus.updateManagementServer()) {
-			if (newStatus.lostConnection()) {
-				ub.set(host, _msIdAttr, null);
-			} else {
-				ub.set(host, _msIdAttr, host.getManagementServerId());
-			}
-			if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) {
-				ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10);
-			}
-		}
-		if (event.equals(Event.ManagementServerDown)) {
-			ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60)));
-		}
-		int result = update(ub, sc, null);
-		assert result <= 1 : "How can this update " + result + " rows? ";
-
-		if (status_logger.isDebugEnabled() && result == 0) {
-			HostVO ho = findById(host.getId());
-			assert ho != null : "How how how? : " + host.getId();
-
-			StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString());
-			str.append(". Name=").append(host.getName());
-			str.append("; New=[status=").append(newStatus.toString()).append(":msid=")
-			        .append(newStatus.lostConnection() ? "null" : host.getManagementServerId()).append(":lastpinged=").append(host.getLastPinged()).append("]");
-			str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=")
-			        .append(oldPingTime).append("]");
-			str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=")
-			        .append(vo.getLastPinged()).append(":old update count=").append(oldUpdateCount).append("]");
-			status_logger.debug(str.toString());
-		} else {
-			StringBuilder msg = new StringBuilder("Agent status update: [");
-			msg.append("id = " + host.getId());
-			msg.append("; name = " + host.getName());
-			msg.append("; old status = " + oldStatus);
-			msg.append("; event = " + event);
-			msg.append("; new status = " + newStatus);
-			msg.append("; old update count = " + oldUpdateCount);
-			msg.append("; new update count = " + newUpdateCount + "]");
-			status_logger.debug(msg.toString());
-		}
-
-		return result > 0;
-	}
+        }
+        long oldPingTime = host.getLastPinged();
+
+        SearchBuilder<HostVO> sb = createSearchBuilder();
+        sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
+        sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
+        sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
+        if (newStatus.checkManagementServer()) {
+            sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
+            sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
+            sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ);
+            sb.cp();
+        }
+        sb.done();
+
+        SearchCriteria<HostVO> sc = sb.create();
+
+        sc.setParameters("status", oldStatus);
+        sc.setParameters("id", host.getId());
+        sc.setParameters("update", host.getUpdated());
+        long oldUpdateCount = host.getUpdated();
+        if (newStatus.checkManagementServer()) {
+            sc.setParameters("ping", oldPingTime);
+            sc.setParameters("msid", host.getManagementServerId());
+        }
+
+        long newUpdateCount = host.incrUpdated();
+        UpdateBuilder ub = getUpdateBuilder(host);
+        ub.set(host, _statusAttr, newStatus);
+        if (newStatus.updateManagementServer()) {
+            if (newStatus.lostConnection()) {
+                ub.set(host, _msIdAttr, null);
+            } else {
+                ub.set(host, _msIdAttr, host.getManagementServerId());
+            }
+            if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) {
+                ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10);
+            }
+        }
+        if (event.equals(Event.ManagementServerDown)) {
+            ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60)));
+        }
+        int result = update(ub, sc, null);
+        assert result <= 1 : "How can this update " + result + " rows? ";
+
+        if (status_logger.isDebugEnabled() && result == 0) {
+            HostVO ho = findById(host.getId());
+            assert ho != null : "How how how? : " + host.getId();
+
+            StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString());
+            str.append(". Name=").append(host.getName());
+            str.append("; New=[status=")
+                .append(newStatus.toString())
+                .append(":msid=")
+                .append(newStatus.lostConnection() ? "null" : host.getManagementServerId())
+                .append(":lastpinged=")
+                .append(host.getLastPinged())
+                .append("]");
+            str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=").append(oldPingTime).append("]");
+            str.append("; DB=[status=")
+                .append(vo.getStatus().toString())
+                .append(":msid=")
+                .append(vo.getManagementServerId())
+                .append(":lastpinged=")
+                .append(vo.getLastPinged())
+                .append(":old update count=")
+                .append(oldUpdateCount)
+                .append("]");
+            status_logger.debug(str.toString());
+        } else {
+            StringBuilder msg = new StringBuilder("Agent status update: [");
+            msg.append("id = " + host.getId());
+            msg.append("; name = " + host.getName());
+            msg.append("; old status = " + oldStatus);
+            msg.append("; event = " + event);
+            msg.append("; new status = " + newStatus);
+            msg.append("; old update count = " + oldUpdateCount);
+            msg.append("; new update count = " + newUpdateCount + "]");
+            status_logger.debug(msg.toString());
+        }
+
+        return result > 0;
+    }
 
     @Override
     public boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo) {
@@ -978,20 +995,20 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
             assert ho != null : "How how how? : " + host.getId();
 
             StringBuilder str = new StringBuilder("Unable to update resource state: [");
-			str.append("m = " + host.getId());
-			str.append("; name = " + host.getName());
-			str.append("; old state = " + oldState);
-			str.append("; event = " + event);
-			str.append("; new state = " + newState + "]");
-			state_logger.debug(str.toString());
+            str.append("m = " + host.getId());
+            str.append("; name = " + host.getName());
+            str.append("; old state = " + oldState);
+            str.append("; event = " + event);
+            str.append("; new state = " + newState + "]");
+            state_logger.debug(str.toString());
         } else {
-			StringBuilder msg = new StringBuilder("Resource state update: [");
-			msg.append("id = " + host.getId());
-			msg.append("; name = " + host.getName());
-			msg.append("; old state = " + oldState);
-			msg.append("; event = " + event);
-			msg.append("; new state = " + newState + "]");
-			state_logger.debug(msg.toString());
+            StringBuilder msg = new StringBuilder("Resource state update: [");
+            msg.append("id = " + host.getId());
+            msg.append("; name = " + host.getName());
+            msg.append("; old state = " + oldState);
+            msg.append("; event = " + event);
+            msg.append("; new state = " + newState + "]");
+            state_logger.debug(msg.toString());
         }
 
         return result > 0;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java b/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java
index 81ae636..30bbe73 100755
--- a/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java
+++ b/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java
@@ -27,11 +27,10 @@ import org.apache.cloudstack.framework.config.ConfigKey.Scope;
 import org.apache.cloudstack.framework.config.ScopedConfigStorage;
 
 import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.db.Transaction;
 
 @Local(value = {AccountDetailsDao.class})
@@ -46,7 +45,7 @@ public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long>
 
     @Override
     public Map<String, String> findDetails(long accountId) {
-        GenericQueryBuilder<AccountDetailVO, AccountDetailVO> sc = GenericQueryBuilder.create(AccountDetailVO.class);
+        QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class);
         sc.and(sc.entity().getAccountId(), Op.EQ, accountId);
         List<AccountDetailVO> results = sc.list();
         Map<String, String> details = new HashMap<String, String>(results.size());
@@ -72,7 +71,7 @@ public class AccountDetailsDaoImpl extends GenericDaoBase<AccountDetailVO, Long>
 
     @Override
     public AccountDetailVO findDetail(long accountId, String name) {
-        GenericQueryBuilder<AccountDetailVO, AccountDetailVO> sc = GenericQueryBuilder.create(AccountDetailVO.class);
+        QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class);
         sc.and(sc.entity().getAccountId(), Op.EQ, accountId);
         sc.and(sc.entity().getName(), Op.EQ, name);
         return sc.find();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/engine/storage/src/org/apache/cloudstack/storage/volume/db/TemplatePrimaryDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/db/TemplatePrimaryDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/volume/db/TemplatePrimaryDataStoreDaoImpl.java
index 456471b..50ab9e6 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/volume/db/TemplatePrimaryDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/db/TemplatePrimaryDataStoreDaoImpl.java
@@ -20,18 +20,18 @@ package org.apache.cloudstack.storage.volume.db;
 
 import java.util.Date;
 
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 
 import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
+import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.UpdateBuilder;
 
 @Component
@@ -50,8 +50,7 @@ public class TemplatePrimaryDataStoreDaoImpl extends GenericDaoBase<TemplatePrim
 
     @Override
     public TemplatePrimaryDataStoreVO findByTemplateIdAndPoolId(long templateId, long poolId) {
-        GenericQueryBuilder<TemplatePrimaryDataStoreVO, TemplatePrimaryDataStoreVO> sc = GenericQueryBuilder
-                .create(TemplatePrimaryDataStoreVO.class);
+        QueryBuilder<TemplatePrimaryDataStoreVO> sc = QueryBuilder.create(TemplatePrimaryDataStoreVO.class);
         sc.and(sc.entity().getTemplateId(), Op.EQ, templateId);
         sc.and(sc.entity().getPoolId(), Op.EQ, poolId);
         return sc.find();
@@ -59,8 +58,7 @@ public class TemplatePrimaryDataStoreDaoImpl extends GenericDaoBase<TemplatePrim
 
     @Override
     public TemplatePrimaryDataStoreVO findByTemplateIdAndPoolIdAndReady(long templateId, long poolId) {
-        GenericQueryBuilder<TemplatePrimaryDataStoreVO, TemplatePrimaryDataStoreVO> sc = GenericQueryBuilder
-                .create(TemplatePrimaryDataStoreVO.class);
+        QueryBuilder<TemplatePrimaryDataStoreVO> sc = QueryBuilder.create(TemplatePrimaryDataStoreVO.class);
         sc.and(sc.entity().getTemplateId(), Op.EQ, templateId);
         sc.and(sc.entity().getPoolId(), Op.EQ, poolId);
         sc.and(sc.entity().getState(), Op.EQ, ObjectInDataStoreStateMachine.State.Ready);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/framework/db/src/com/cloud/utils/db/GenericQueryBuilder.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/GenericQueryBuilder.java b/framework/db/src/com/cloud/utils/db/GenericQueryBuilder.java
index 570a10e..885bebb 100755
--- a/framework/db/src/com/cloud/utils/db/GenericQueryBuilder.java
+++ b/framework/db/src/com/cloud/utils/db/GenericQueryBuilder.java
@@ -17,16 +17,13 @@
 package com.cloud.utils.db;
 
 import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.UUID;
 
-import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
 
-public class GenericQueryBuilder<T, K> extends SearchBase<T, K> {
+public class GenericQueryBuilder<T, K> extends SearchBase<GenericQueryBuilder<T, K>, T, K> {
     final HashMap<String, Object[]> _params = new HashMap<String, Object[]>();
 
     protected GenericQueryBuilder(Class<T> entityType, Class<K> resultType) {
@@ -40,81 +37,31 @@ public class GenericQueryBuilder<T, K> extends SearchBase<T, K> {
         return new GenericQueryBuilder<T, K>(entityType, resultType);
     }
 
-    static public <T> GenericQueryBuilder<T, T> create(Class<T> entityType) {
-        return create(entityType, entityType);
-    }
-
-    public GenericQueryBuilder<T, K> or() {
-        constructCondition(null, " OR ", null, null);
-        return this;
-    }
-
-    public void selectField(Object... useless) {
-        assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
-        assert _specifiedAttrs.size() > 0 : "You didn't specify any attributes";
-
-        if (_selects == null) {
-            _selects = new ArrayList<Select>();
-        }
-
-        for (Attribute attr : _specifiedAttrs) {
-            Field field = null;
-            try {
-                field = _resultType.getDeclaredField(attr.field.getName());
-                field.setAccessible(true);
-            } catch (SecurityException e) {
-            } catch (NoSuchFieldException e) {
-            }
-            _selects.add(new Select(Func.NATIVE, attr, field, null));
-        }
-
-        _specifiedAttrs.clear();
-    }
-
     public GenericQueryBuilder<T, K> and(Object useless, Op op, Object... values) {
         String uuid = UUID.randomUUID().toString();
-        Condition condition = constructCondition(uuid, " AND ", _specifiedAttrs.get(0), op);
-        condition.setPresets(values);
+        constructCondition(uuid, " AND ", _specifiedAttrs.get(0), op);
+        _params.put(uuid, values);
         return this;
     }
 
     public GenericQueryBuilder<T, K> or(Object useless, Op op, Object... values) {
         String uuid = UUID.randomUUID().toString();
-        Condition condition = constructCondition(uuid, " OR ", _specifiedAttrs.get(0), op);
-        condition.setPresets(values);
+        constructCondition(uuid, " OR ", _specifiedAttrs.get(0), op);
+        _params.put(uuid, values);
         return this;
     }
 
     protected GenericQueryBuilder<T, K> left(Object useless, Op op, Object... values) {
         String uuid = UUID.randomUUID().toString();
-        Condition condition = constructCondition(uuid, " ( ", _specifiedAttrs.get(0), op);
-        condition.setPresets(values);
+        constructCondition(uuid, " ( ", _specifiedAttrs.get(0), op);
+        _params.put(uuid, values);
         return this;
     }
 
-    public GenericQueryBuilder<T, K> and() {
-        constructCondition(null, " AND ", null, null);
-        return this;
-    }
-
-    public GenericQueryBuilder<T, K> where() {
-        return and();
-    }
-
     public GenericQueryBuilder<T, K> op(Object useless, Op op, Object... values) {
         return left(useless, op, values);
     }
 
-    protected GenericQueryBuilder<T, K> right() {
-        Condition condition = new Condition("rp", " ) ", null, Op.RP);
-        _conditions.add(condition);
-        return this;
-    }
-
-    public GenericQueryBuilder<T, K> cp() {
-        return right();
-    }
-
     @SuppressWarnings("unchecked")
     public List<K> list() {
         finalize();
@@ -128,6 +75,13 @@ public class GenericQueryBuilder<T, K> extends SearchBase<T, K> {
         }
     }
 
+    @Override
+    public SearchCriteria<K> create() {
+        SearchCriteria<K> sc = super.create();
+        sc.setParameters(_params);
+        return sc;
+    }
+
     private boolean isSelectAll() {
         return _selects == null || _selects.size() == 0;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/framework/db/src/com/cloud/utils/db/GenericSearchBuilder.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/GenericSearchBuilder.java b/framework/db/src/com/cloud/utils/db/GenericSearchBuilder.java
index e171635..b9bef61 100755
--- a/framework/db/src/com/cloud/utils/db/GenericSearchBuilder.java
+++ b/framework/db/src/com/cloud/utils/db/GenericSearchBuilder.java
@@ -16,233 +16,155 @@
 // under the License.
 package com.cloud.utils.db;
 
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.UUID;
 
-import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
 
 /**
- * GenericSearchBuilder is used to build a search based on a VO object
- * a convenience class provided called SearchBuilder that provides
- * exactly that functionality.
+ * GenericSearchBuilder is used to build a search based on a VO object.  It
+ * can select the result into a native type, the entity object, or a composite
+ * object depending on what's needed.
+ * 
+ * The way to use GenericSearchBuilder is to use it to build a search at load
+ * time so it should be declared at class constructions.  It allows queries to
+ * be constructed completely in Java and parameters have String tokens that
+ * can be replaced during runtime with SearchCriteria.  Because
+ * GenericSearchBuilder is created at load time and SearchCriteria is used
+ * at runtime, the search query creation and the parameter value setting are
+ * separated in the code.  While that's tougher on the coder to maintain, what
+ * you gain is that all string constructions are done at load time rather than
+ * runtime and, more importantly, the proper construction can be checked when
+ * components are being loaded.  However, if you prefer to just construct
+ * the entire search at runtime, you can use GenericQueryBuilder.
  *
  * @param <T> VO object this Search is build for.
  * @param <K> Result object that should contain the results.
  */
-public class GenericSearchBuilder<T, K> extends SearchBase<T, K> {
+public class GenericSearchBuilder<T, K> extends SearchBase<GenericSearchBuilder<T, K>, T, K> {
     protected GenericSearchBuilder(Class<T> entityType, Class<K> resultType) {
         super(entityType, resultType);
     }
     
-    public GenericSearchBuilder<T, K> selectFields(Object... useless) {
-        if (_entity == null) {
-            throw new RuntimeException("SearchBuilder cannot be modified once it has been setup");
-        }
-        if (_specifiedAttrs.size() <= 0) {
-            throw new RuntimeException("You didn't specify any attributes");
-        }
-
-        if (_selects == null) {
-            _selects = new ArrayList<Select>();
-        }
-
-        for (Attribute attr : _specifiedAttrs) {
-            Field field = null;
-            try {
-                field = _resultType.getDeclaredField(attr.field.getName());
-                field.setAccessible(true);
-            } catch (SecurityException e) {
-            } catch (NoSuchFieldException e) {
-            }
-            _selects.add(new Select(Func.NATIVE, attr, field, null));
-        }
-
-        _specifiedAttrs.clear();
-
-        return this;
-    }
-
-    /**
-     * Specifies the field to select.
-     * 
-     * @param fieldName The field name of the result object to put the value of the field selected.  This can be null if you're selecting only one field and the result is not a complex object.
-     * @param func function to place.
-     * @param useless column to select.  Call this with this.entity() method.
-     * @param params parameters to the function.
-     * @return a SearchBuilder to build more search parts.
-     */
-    public GenericSearchBuilder<T, K> select(String fieldName, Func func, Object useless, Object... params) {
-        if (_entity == null) {
-            throw new RuntimeException("SearchBuilder cannot be modified once it has been setup");
-        }
-        if (_specifiedAttrs.size() > 1) {
-            throw new RuntimeException("You can't specify more than one field to search on");
-        }
-        if (func.getCount() != -1 && (func.getCount() != (params.length + 1))) {
-            throw new RuntimeException("The number of parameters does not match the function param count for " + func);
-        }
-        
-        if (_selects == null) {
-            _selects = new ArrayList<Select>();
-        }
-        
-        Field field = null;
-        if (fieldName != null) {
-            try {
-                field = _resultType.getDeclaredField(fieldName);
-                field.setAccessible(true);
-            } catch (SecurityException e) {
-                throw new RuntimeException("Unable to find " + fieldName, e);
-            } catch (NoSuchFieldException e) {
-                throw new RuntimeException("Unable to find " + fieldName, e);
-            }
-        } else {
-            if (_selects.size() != 0) {
-                throw new RuntimeException(
-                        "You're selecting more than one item and yet is not providing a container class to put these items in.  So what do you expect me to do.  Spin magic?");
-            }
-        }
-        
-        Select select = new Select(func, _specifiedAttrs.size() == 0 ? null : _specifiedAttrs.get(0), field, params);
-        _selects.add(select);
-        
-        _specifiedAttrs.clear();
-        
-        return this;
-    }
-    
     /**
      * Adds an AND condition to the SearchBuilder.
      * 
      * @param name param name you will use later to set the values in this search condition.
-     * @param useless SearchBuilder.entity().get*() which refers to the field that you're searching on.
+     * @param field SearchBuilder.entity().get*() which refers to the field that you're searching on.
      * @param op operation to apply to the field.
      * @return this
      */
-    public GenericSearchBuilder<T, K> and(String name, Object useless, Op op) {
+    public GenericSearchBuilder<T, K> and(String name, Object field, Op op) {
         constructCondition(name, " AND ", _specifiedAttrs.get(0), op);
         return this;
     }
     
-    public GenericSearchBuilder<T, K> and() {
-        constructCondition(null, " AND ", null, null);
-        return this;
-    }
-
-    public GenericSearchBuilder<T, K> and(Object useless, Op op, String name) {
+    /**
+     * Adds an AND condition.  Some prefer this method because it looks like
+     * the actual SQL query.
+     * 
+     * @param field field of entity object
+     * @param op operator of the search condition
+     * @param name param name used to later to set parameter value
+     * @return this
+     */
+    public GenericSearchBuilder<T, K> and(Object field, Op op, String name) {
         constructCondition(name, " AND ", _specifiedAttrs.get(0), op);
         return this;
     }
 
-    public Preset and(Object useless, Op op) {
+    /**
+     * Adds an AND condition but allows for a preset value to be set for this conditio.
+     * 
+     * @param field field of the entity object
+     * @param op operator of the search condition
+     * @return Preset which allows you to set the values
+     */
+    public Preset and(Object field, Op op) {
         Condition condition = constructCondition(UUID.randomUUID().toString(), " AND ", _specifiedAttrs.get(0), op);
         return new Preset(this, condition);
     }
 
-    public GenericSearchBuilder<T, K> or() {
-        constructCondition(null, " OR ", null, null);
-        return this;
-    }
-    
-    public GenericSearchBuilder<T, K> where(Object useless, Op op, String name) {
-        return and(name, useless, op);
+    /**
+     * Starts the search
+     * 
+     * @param field field of the entity object
+     * @param op operator
+     * @param name param name to refer to the value later.
+     * @return this
+     */
+    public GenericSearchBuilder<T, K> where(Object field, Op op, String name) {
+        return and(name, field, op);
     }
 
-    public Preset where(Object useless, Op op) {
-        return and(useless, op);
+    /**
+     * Starts the search but the value is already set during construction.
+     * 
+     * @param field field of the entity object
+     * @param op operator of the search condition
+     * @return Preset which allows you to set the values
+     */
+    public Preset where(Object field, Op op) {
+        return and(field, op);
     }
 
-    protected GenericSearchBuilder<T, K> left(Object useless, Op op, String name) {
+    protected GenericSearchBuilder<T, K> left(Object field, Op op, String name) {
         constructCondition(name, " ( ", _specifiedAttrs.get(0), op);
         return this;
     }
 
-    protected Preset left(Object useless, Op op) {
+    protected Preset left(Object field, Op op) {
         Condition condition = constructCondition(UUID.randomUUID().toString(), " ( ", _specifiedAttrs.get(0), op);
         return new Preset(this, condition);
     }
 
-    public GenericSearchBuilder<T, K> op(Object useless, Op op, String name) {
-        return left(useless, op, name);
+    /**
+     * open parenthesis
+     * @param field
+     * @param op
+     * @param name
+     * @return
+     */
+    public GenericSearchBuilder<T, K> op(Object field, Op op, String name) {
+        return left(field, op, name);
     }
 
-    public Preset op(Object useless, Op op) {
-        return left(useless, op);
+    public Preset op(Object field, Op op) {
+        return left(field, op);
     }
 
-    public GenericSearchBuilder<T, K> op(String name, Object useless, Op op) {
-        return left(useless, op, name);
-    }
-    
-    public GroupBy<GenericSearchBuilder<T, K>, T, K> groupBy(Object... useless) {
-        assert _groupBy == null : "Can't do more than one group bys";
-        GroupBy<GenericSearchBuilder<T, K>, T, K> groupBy = new GroupBy<GenericSearchBuilder<T, K>, T, K>(this);
-        _groupBy = groupBy;
-        
-        return groupBy;
+    public GenericSearchBuilder<T, K> op(String name, Object field, Op op) {
+        return left(field, op, name);
     }
     
     /**
      * Adds an OR condition to the SearchBuilder.
      * 
      * @param name param name you will use later to set the values in this search condition.
-     * @param useless SearchBuilder.entity().get*() which refers to the field that you're searching on.
+     * @param field SearchBuilder.entity().get*() which refers to the field that you're searching on.
      * @param op operation to apply to the field.
      * @return this
      */
-    public GenericSearchBuilder<T, K> or(String name, Object useless, Op op) {
+    public GenericSearchBuilder<T, K> or(String name, Object field, Op op) {
         constructCondition(name, " OR ", _specifiedAttrs.get(0), op);
         return this;
     }
     
-    public GenericSearchBuilder<T, K> or(Object useless, Op op, String name) {
+    public GenericSearchBuilder<T, K> or(Object field, Op op, String name) {
         constructCondition(name, " OR ", _specifiedAttrs.get(0), op);
         return this;
     }
 
-    public Preset or(Object useless, Op op) {
+    public Preset or(Object field, Op op) {
         Condition condition = constructCondition(UUID.randomUUID().toString(), " OR ", _specifiedAttrs.get(0), op);
         return new Preset(this, condition);
     }
 
-    public GenericSearchBuilder<T, K> join(String name, GenericSearchBuilder<?, ?> builder, Object useless, Object useless2, JoinBuilder.JoinType joinType) {
-        assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
-        assert _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
-        assert builder._entity != null : "SearchBuilder cannot be modified once it has been setup";
-        assert builder._specifiedAttrs.size() == 1 : "You didn't select the attribute.";
-        assert builder != this : "You can't add yourself, can you?  Really think about it!";
-        
-        JoinBuilder<SearchBase<?, ?>> t = new JoinBuilder<SearchBase<?, ?>>(builder, _specifiedAttrs.get(0), builder._specifiedAttrs.get(0), joinType);
-        if (_joins == null) {
-            _joins = new HashMap<String, JoinBuilder<SearchBase<?, ?>>>();
-        }
-        _joins.put(name, t);
-        
-        builder._specifiedAttrs.clear();
-        _specifiedAttrs.clear();
-        return this;
-    }
-    
-
     public SearchCriteria<K> create(String name, Object... values) {
         SearchCriteria<K> sc = create();
         sc.setParameters(name, values);
         return sc;
     }
     
-    protected GenericSearchBuilder<T, K> right() {
-        Condition condition = new Condition("rp", " ) ", null, Op.RP);
-        _conditions.add(condition);
-        return this;
-    }
-    
-    public GenericSearchBuilder<T, K> cp() {
-        return right();
-    }
-    
     /**
      * Marks the SearchBuilder as completed in building the search conditions.
      */

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/framework/db/src/com/cloud/utils/db/GroupBy.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/GroupBy.java b/framework/db/src/com/cloud/utils/db/GroupBy.java
index b3f88da..726f442 100644
--- a/framework/db/src/com/cloud/utils/db/GroupBy.java
+++ b/framework/db/src/com/cloud/utils/db/GroupBy.java
@@ -23,7 +23,7 @@ import com.cloud.utils.Pair;
 import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
 
-public class GroupBy<J extends SearchBase<T, R>, T, R> {
+public class GroupBy<J extends SearchBase<?, T, R>, T, R> {
     J _builder;
     List<Pair<Func, Attribute>> _groupBys;
     Having _having;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/framework/db/src/com/cloud/utils/db/SearchBase.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/SearchBase.java b/framework/db/src/com/cloud/utils/db/SearchBase.java
index b28ac17..99c4679 100644
--- a/framework/db/src/com/cloud/utils/db/SearchBase.java
+++ b/framework/db/src/com/cloud/utils/db/SearchBase.java
@@ -20,7 +20,20 @@ import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.SearchCriteria.SelectType;
 import com.cloud.utils.exception.CloudRuntimeException;
 
-public abstract class SearchBase<T, K> {
+/**
+ * SearchBase contains the methods that are used to build up search
+ * queries.  While this class is public it's not really meant for public
+ * consumption.  Unfortunately, it has to be public for methods to be mocked.
+ * 
+ * @see GenericSearchBuilder
+ * @see GenericQueryBuilder
+ *
+ * @param <J> Child class that inherited from SearchBase
+ * @param <T> Entity Type to perform the searches on
+ * @param <K> Type to place the search results.  This can be a native type,
+ *            composite object, or the entity type itself.
+ */
+public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
 
     final Map<String, Attribute> _attrs;
     final Class<T> _entityBeanType;
@@ -30,9 +43,9 @@ public abstract class SearchBase<T, K> {
     final ArrayList<Condition> _conditions;
     final ArrayList<Attribute> _specifiedAttrs;
 
-    protected HashMap<String, JoinBuilder<SearchBase<?, ?>>> _joins;
+    protected HashMap<String, JoinBuilder<SearchBase<?, ?, ?>>> _joins;
     protected ArrayList<Select> _selects;
-    protected GroupBy<? extends SearchBase<T, K>, T, K> _groupBy = null;
+    protected GroupBy<J, T, K> _groupBy = null;
     protected SelectType _selectType;
     T _entity;
 
@@ -52,6 +65,134 @@ public abstract class SearchBase<T, K> {
         _specifiedAttrs = new ArrayList<Attribute>();
     }
 
+    /**
+     * Specifies how the search query should be grouped
+     * 
+     * @param fields fields of the entity object that should be grouped on.  The order is important.
+     * @return GroupBy object to perform more operations on.
+     * @see GroupBy
+     */
+    @SuppressWarnings("unchecked")
+    public GroupBy<J, T, K> groupBy(Object... fields) {
+        assert _groupBy == null : "Can't do more than one group bys";
+        _groupBy = new GroupBy<J, T, K>((J)this);
+        return _groupBy;
+    }
+
+    /**
+     * Specifies what to select in the search.
+     * 
+     * @param fieldName The field name of the result object to put the value of the field selected.  This can be null if you're selecting only one field and the result is not a complex object.
+     * @param func function to place.
+     * @param field column to select.  Call this with this.entity() method.
+     * @param params parameters to the function.
+     * @return itself to build more search parts.
+     */
+    @SuppressWarnings("unchecked")
+    public J select(String fieldName, Func func, Object field, Object... params) {
+        if (_entity == null) {
+            throw new RuntimeException("SearchBuilder cannot be modified once it has been setup");
+        }
+        if (_specifiedAttrs.size() > 1) {
+            throw new RuntimeException("You can't specify more than one field to search on");
+        }
+        if (func.getCount() != -1 && (func.getCount() != (params.length + 1))) {
+            throw new RuntimeException("The number of parameters does not match the function param count for " + func);
+        }
+
+        if (_selects == null) {
+            _selects = new ArrayList<Select>();
+        }
+
+        Field declaredField = null;
+        if (fieldName != null) {
+            try {
+                declaredField = _resultType.getDeclaredField(fieldName);
+                declaredField.setAccessible(true);
+            } catch (SecurityException e) {
+                throw new RuntimeException("Unable to find " + fieldName, e);
+            } catch (NoSuchFieldException e) {
+                throw new RuntimeException("Unable to find " + fieldName, e);
+            }
+        } else {
+            if (_selects.size() != 0) {
+                throw new RuntimeException(
+                    "You're selecting more than one item and yet is not providing a container class to put these items in.  So what do you expect me to do.  Spin magic?");
+            }
+        }
+
+        Select select = new Select(func, _specifiedAttrs.size() == 0 ? null : _specifiedAttrs.get(0), declaredField, params);
+        _selects.add(select);
+
+        _specifiedAttrs.clear();
+
+        return (J)this;
+    }
+
+    /**
+     * Select fields from the entity object to be selected in the search query.
+     * 
+     * @param fields fields from the entity object
+     * @return itself
+     */
+    @SuppressWarnings("unchecked")
+    public J selectFields(Object... fields) {
+        if (_entity == null) {
+            throw new RuntimeException("SearchBuilder cannot be modified once it has been setup");
+        }
+        if (_specifiedAttrs.size() <= 0) {
+            throw new RuntimeException("You didn't specify any attributes");
+        }
+
+        if (_selects == null) {
+            _selects = new ArrayList<Select>();
+        }
+
+        for (Attribute attr : _specifiedAttrs) {
+            Field field = null;
+            try {
+                field = _resultType.getDeclaredField(attr.field.getName());
+                field.setAccessible(true);
+            } catch (SecurityException e) {
+            } catch (NoSuchFieldException e) {
+            }
+            _selects.add(new Select(Func.NATIVE, attr, field, null));
+        }
+
+        _specifiedAttrs.clear();
+
+        return (J)this;
+    }
+
+    /**
+     * joins this search with another search
+     * 
+     * @param name name given to the other search.  used for setJoinParameters.
+     * @param builder The other search
+     * @param joinField1 field of the first table used to perform the join
+     * @param joinField2 field of the second table used to perform the join
+     * @param joinType type of join
+     * @return itself
+     */
+    @SuppressWarnings("unchecked")
+    public J join(String name, SearchBase<?, ?, ?> builder, Object joinField1, Object joinField2, JoinBuilder.JoinType joinType) {
+        assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
+        assert _specifiedAttrs.size() == 1 : "You didn't select the attribute.";
+        assert builder._entity != null : "SearchBuilder cannot be modified once it has been setup";
+        assert builder._specifiedAttrs.size() == 1 : "You didn't select the attribute.";
+        assert builder != this : "You can't add yourself, can you?  Really think about it!";
+
+        JoinBuilder<SearchBase<?, ?, ?>> t = new JoinBuilder<SearchBase<?, ?, ?>>(builder, _specifiedAttrs.get(0), builder._specifiedAttrs.get(0), joinType);
+        if (_joins == null) {
+            _joins = new HashMap<String, JoinBuilder<SearchBase<?, ?, ?>>>();
+        }
+        _joins.put(name, t);
+
+        builder._specifiedAttrs.clear();
+        _specifiedAttrs.clear();
+        return (J)this;
+    }
+
     public SelectType getSelectType() {
         return _selectType;
     }
@@ -62,6 +203,10 @@ public abstract class SearchBase<T, K> {
         _specifiedAttrs.add(attr);
     }
 
+    /**
+     * @return entity object.  This allows the caller to use the entity return
+     * to specify the field to be selected in many of the search parameters.
+     */
     public T entity() {
         return _entity;
     }
@@ -101,10 +246,68 @@ public abstract class SearchBase<T, K> {
     }
 
     /**
+     * Adds an OR condition to the search.  Normally you should use this to
+     * perform an 'OR' with a big conditional in parenthesis.  For example,
+     * 
+     * search.or().op(entity.getId(), Op.Eq, "abc").cp()
+     * 
+     * The above fragment produces something similar to
+     * 
+     * "OR (id = $abc) where abc is the token to be replaced by a value later.
+     * 
+     * @return this
+     */
+    @SuppressWarnings("unchecked")
+    public J or() {
+        constructCondition(null, " OR ", null, null);
+        return (J)this;
+    }
+
+    /**
+     * Adds an AND condition to the search.  Normally you should use this to
+     * perform an 'AND' with a big conditional in parenthesis.  For example,
+     * 
+     * search.and().op(entity.getId(), Op.Eq, "abc").cp()
+     * 
+     * The above fragment produces something similar to
+     * 
+     * "AND (id = $abc) where abc is the token to be replaced by a value later.
+     * 
+     * @return this
+     */
+    @SuppressWarnings("unchecked")
+    public J and() {
+        constructCondition(null, " AND ", null, null);
+        return (J)this;
+    }
+
+    /**
+     * Closes a parenthesis that's started by op()
+     * @return this
+     */
+    @SuppressWarnings("unchecked")
+    public J cp() {
+        Condition condition = new Condition(null, " ) ", null, Op.RP);
+        _conditions.add(condition);
+        return (J)this;
+    }
+
+    /**
+     * Writes an open parenthesis into the search
+     * @return this
+     */
+    @SuppressWarnings("unchecked")
+    public J op() {
+        Condition condition = new Condition(null, " ( ", null, Op.RP);
+        _conditions.add(condition);
+        return (J)this;
+    }
+
+    /**
      * Marks the SearchBuilder as completed in building the search conditions.
      */
     @Override
-    public synchronized void finalize() {
+    protected synchronized void finalize() {
         if (_entity != null) {
             Factory factory = (Factory)_entity;
             factory.setCallback(0, null);
@@ -112,7 +315,7 @@ public abstract class SearchBase<T, K> {
         }
 
         if (_joins != null) {
-            for (JoinBuilder<SearchBase<?, ?>> join : _joins.values()) {
+            for (JoinBuilder<SearchBase<?, ?, ?>> join : _joins.values()) {
                 join.getT().finalize();
             }
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/framework/db/src/com/cloud/utils/db/SearchCriteria.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/SearchCriteria.java b/framework/db/src/com/cloud/utils/db/SearchCriteria.java
index a1f6408..3b20686 100755
--- a/framework/db/src/com/cloud/utils/db/SearchCriteria.java
+++ b/framework/db/src/com/cloud/utils/db/SearchCriteria.java
@@ -56,6 +56,7 @@ public class SearchCriteria<K> {
 
         private final String op;
         int params;
+
         Op(String op, int params) {
             this.op = op;
             this.params = params;
@@ -113,27 +114,12 @@ public class SearchCriteria<K> {
     private int _counter;
     private HashMap<String, JoinBuilder<SearchCriteria<?>>> _joins;
     private final ArrayList<Select> _selects;
-    private final GroupBy<? extends SearchBase<?, K>, ?, K> _groupBy;
+    private final GroupBy<? extends SearchBase<?, ?, K>, ?, K> _groupBy;
     private final List<Object> _groupByValues;
     private final Class<K> _resultType;
     private final SelectType _selectType;
 
-    protected SearchCriteria(Map<String, Attribute> attrs, ArrayList<Condition> conditions, ArrayList<Select> selects, SelectType selectType, Class<K> resultType,
-            HashMap<String, Object[]> params) {
-        this._attrs = attrs;
-        this._conditions = conditions;
-        this._selects = selects;
-        this._selectType = selectType;
-        this._resultType = resultType;
-        this._params = params;
-        this._additionals = new ArrayList<Condition>();
-        this._counter = 0;
-        this._joins = null;
-        this._groupBy = null;
-        this._groupByValues = null;
-    }
-
-    protected SearchCriteria(SearchBase<?, K> sb) {
+    protected SearchCriteria(SearchBase<?, ?, K> sb) {
         this._attrs = sb._attrs;
         this._conditions = sb._conditions;
         this._additionals = new ArrayList<Condition>();
@@ -141,9 +127,9 @@ public class SearchCriteria<K> {
         this._joins = null;
         if (sb._joins != null) {
             _joins = new HashMap<String, JoinBuilder<SearchCriteria<?>>>(sb._joins.size());
-            for (Map.Entry<String, JoinBuilder<SearchBase<?, ?>>> entry : sb._joins.entrySet()) {
-                JoinBuilder<SearchBase<?, ?>> value = entry.getValue();
-                _joins.put(entry.getKey(), new JoinBuilder<SearchCriteria<?>>(value.getT().create(),value.getFirstAttribute(), value.getSecondAttribute(), value.getType()));
+            for (Map.Entry<String, JoinBuilder<SearchBase<?, ?, ?>>> entry : sb._joins.entrySet()) {
+                JoinBuilder<SearchBase<?, ?, ?>> value = entry.getValue();
+                _joins.put(entry.getKey(), new JoinBuilder<SearchCriteria<?>>(value.getT().create(), value.getFirstAttribute(), value.getSecondAttribute(), value.getType()));
             }
         }
         _selects = sb._selects;
@@ -157,6 +143,10 @@ public class SearchCriteria<K> {
         _selectType = sb._selectType;
     }
 
+    protected void setParameters(HashMap<String, Object[]> parameters) {
+        _params = parameters;
+    }
+
     public SelectType getSelectType() {
         return _selectType;
     }
@@ -202,22 +192,22 @@ public class SearchCriteria<K> {
     }
 
     protected JoinBuilder<SearchCriteria<?>> findJoin(Map<String, JoinBuilder<SearchCriteria<?>>> jbmap, String joinName) {
-    	JoinBuilder<SearchCriteria<?>> jb = jbmap.get(joinName);
-    	if (jb != null) {
-    		return jb;
-    	}
-    	
-    	for (JoinBuilder<SearchCriteria<?>> j2 : jbmap.values()) {
-    		SearchCriteria<?> sc = j2.getT();
-    		if(sc._joins != null)
-    		    jb = findJoin(sc._joins, joinName);
-    		if (jb != null) {
-    			return jb;
-    		}
-    	}
-    	
-    	assert (false) : "Unable to find a join by the name " + joinName;
-    	return null;
+        JoinBuilder<SearchCriteria<?>> jb = jbmap.get(joinName);
+        if (jb != null) {
+            return jb;
+        }
+
+        for (JoinBuilder<SearchCriteria<?>> j2 : jbmap.values()) {
+            SearchCriteria<?> sc = j2.getT();
+            if (sc._joins != null)
+                jb = findJoin(sc._joins, joinName);
+            if (jb != null) {
+                return jb;
+            }
+        }
+
+        assert (false) : "Unable to find a join by the name " + joinName;
+        return null;
     }
 
     public void setJoinParameters(String joinName, String conditionName, Object... params) {
@@ -227,18 +217,6 @@ public class SearchCriteria<K> {
 
     }
 
-    public void addJoinAnd(String joinName, String field, Op op, Object... values) {
-        JoinBuilder<SearchCriteria<?>> join = _joins.get(joinName);
-        assert (join != null) : "Incorrect join name specified: " + joinName;
-        join.getT().addAnd(field, op, values);
-    }
-
-    public void addJoinOr(String joinName, String field, Op op, Object... values) {
-        JoinBuilder<SearchCriteria<?>> join = _joins.get(joinName);
-        assert (join != null) : "Incorrect join name specified: " + joinName;
-        join.getT().addOr(field, op, values);
-    }
-
     public SearchCriteria<?> getJoin(String joinName) {
         return _joins.get(joinName).getT();
     }
@@ -257,30 +235,27 @@ public class SearchCriteria<K> {
         return _resultType;
     }
 
+    @Deprecated
     public void addAnd(String field, Op op, Object... values) {
         String name = Integer.toString(_counter++);
         addCondition(name, " AND ", field, op);
         setParameters(name, values);
     }
 
+    @Deprecated
     public void addAnd(Attribute attr, Op op, Object... values) {
         String name = Integer.toString(_counter++);
         addCondition(name, " AND ", attr, op);
         setParameters(name, values);
     }
 
+    @Deprecated
     public void addOr(String field, Op op, Object... values) {
         String name = Integer.toString(_counter++);
         addCondition(name, " OR ", field, op);
         setParameters(name, values);
     }
 
-    public void addOr(Attribute attr, Op op, Object... values) {
-        String name = Integer.toString(_counter++);
-        addCondition(name, " OR ", attr, op);
-        setParameters(name, values);
-    }
-
     protected void addCondition(String conditionName, String cond, String fieldName, Op op) {
         Attribute attr = _attrs.get(fieldName);
         assert attr != null : "Unable to find field: " + fieldName;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java
index c8a178e..314c957 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java
@@ -23,7 +23,6 @@
 package com.cloud.baremetal.networkservice;
 
 import java.net.URI;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -36,7 +35,6 @@ import org.apache.log4j.Logger;
 import org.apache.cloudstack.api.AddBaremetalPxeCmd;
 import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd;
 import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
@@ -62,9 +60,8 @@ import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ServerResource;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.NicProfile;
@@ -84,7 +81,7 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements
 	
 	@Override
     public boolean prepare(VirtualMachineProfile profile, NicProfile pxeNic, DeployDestination dest, ReservationContext context) {
-	    GenericQueryBuilder<BaremetalPxeVO, BaremetalPxeVO> sc = GenericQueryBuilder.create(BaremetalPxeVO.class);
+        QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
         sc.and(sc.entity().getDeviceType(), Op.EQ, BaremetalPxeType.PING.toString());
         sc.and(sc.entity().getPodId(), Op.EQ, dest.getPod().getId());
         BaremetalPxeVO pxeVo = sc.find();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
index 930ca1b..9e1fd65 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
@@ -5,20 +5,20 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
-// 
+//
 // Unless required by applicable law or agreed to in writing,
 // software distributed under the License is distributed on an
 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-// 
+//
 // Automatically generated by addcopyright.py at 01/29/2013
 // Apache License, Version 2.0 (the "License"); you may not use this
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// 
+//
 // Automatically generated by addcopyright.py at 04/03/2012
 package com.cloud.baremetal.networkservice;
 
@@ -32,9 +32,10 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.AddBaremetalDhcpCmd;
 import org.apache.cloudstack.api.ListBaremetalDhcpCmd;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -45,7 +46,6 @@ import com.cloud.baremetal.database.BaremetalDhcpDao;
 import com.cloud.baremetal.database.BaremetalDhcpVO;
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.HostPodVO;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.HostPodDao;
 import com.cloud.deploy.DeployDestination;
@@ -67,14 +67,12 @@ import com.cloud.resource.ServerResource;
 import com.cloud.resource.UnableDeleteHostException;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.ReservationContext;
-import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.dao.NicDao;
 import com.cloud.vm.dao.UserVmDao;
@@ -311,7 +309,7 @@ public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDh
             return responses;
         }
 
-        GenericQueryBuilder<BaremetalDhcpVO, BaremetalDhcpVO> sc = GenericQueryBuilder.create(BaremetalDhcpVO.class);
+        QueryBuilder<BaremetalDhcpVO> sc = QueryBuilder.create(BaremetalDhcpVO.class);
         if (cmd.getDeviceType() != null) {
         	sc.and(sc.entity().getDeviceType(), Op.EQ, cmd.getDeviceType());
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
index 661f391..aa0ff1c 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
@@ -32,7 +32,6 @@ import org.apache.log4j.Logger;
 import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
 import org.apache.cloudstack.api.AddBaremetalPxeCmd;
 import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
@@ -57,9 +56,8 @@ import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.NicProfile;
@@ -87,7 +85,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
     @Override
     public boolean prepare(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context) {
         NetworkVO nwVO = _nwDao.findById(nic.getNetworkId());
-        GenericQueryBuilder<BaremetalPxeVO, BaremetalPxeVO> sc = GenericQueryBuilder.create(BaremetalPxeVO.class);
+        QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
         sc.and(sc.entity().getDeviceType(), Op.EQ, BaremetalPxeType.KICK_START.toString());
         sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, nwVO.getPhysicalNetworkId());
         BaremetalPxeVO pxeVo = sc.find();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java
index f869fe6..244ce8c 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java
@@ -5,16 +5,16 @@
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at
-// 
+//
 //   http://www.apache.org/licenses/LICENSE-2.0
-// 
+//
 // Unless required by applicable law or agreed to in writing,
 // software distributed under the License is distributed on an
 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-// 
+//
 // Automatically generated by addcopyright.py at 01/29/2013
 package com.cloud.baremetal.networkservice;
 
@@ -46,16 +46,14 @@ import com.cloud.network.element.NetworkElement;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VMInstanceVO;
-import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.Type;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.dao.NicDao;
@@ -91,7 +89,7 @@ public class BaremetalPxeElement extends AdapterBase implements NetworkElement {
     private boolean canHandle(DeployDestination dest, TrafficType trafficType, GuestType networkType) {
         Pod pod = dest.getPod();
         if (pod != null && dest.getDataCenter().getNetworkType() == NetworkType.Basic && trafficType == TrafficType.Guest) {
-            GenericQueryBuilder<BaremetalPxeVO, BaremetalPxeVO> sc = GenericQueryBuilder.create(BaremetalPxeVO.class);
+            QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
             sc.and(sc.entity().getPodId(), Op.EQ, pod.getId());
             return sc.find() != null;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java
index ae3898b..ef6ec31 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java
@@ -36,9 +36,8 @@ import org.apache.log4j.Logger;
 import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
 import org.apache.cloudstack.api.AddBaremetalPxeCmd;
 import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd;
-import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
-import org.apache.log4j.Logger;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -62,9 +61,8 @@ import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.StringUtils;
 import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicVO;
@@ -220,7 +218,7 @@ public class BaremetalPxeManagerImpl extends ManagerBase implements BaremetalPxe
         }
         PhysicalNetworkVO phy = phys.get(0);
         
-        GenericQueryBuilder<BaremetalPxeVO, BaremetalPxeVO> sc = GenericQueryBuilder.create(BaremetalPxeVO.class);
+        QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
         //TODO: handle both kickstart and PING
         //sc.addAnd(sc.getEntity().getPodId(), Op.EQ, vm.getPodIdToDeployIn());
         sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, phy.getId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
index dec4a79..8da9da0 100755
--- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
+++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java
@@ -30,8 +30,11 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.AddUcsManagerCmd;
 import org.apache.cloudstack.api.AssociateUcsProfileToBladeCmd;
+import org.apache.cloudstack.api.DeleteUcsManagerCmd;
 import org.apache.cloudstack.api.ListUcsBladeCmd;
 import org.apache.cloudstack.api.ListUcsManagerCmd;
 import org.apache.cloudstack.api.ListUcsProfileCmd;
@@ -40,8 +43,6 @@ import org.apache.cloudstack.api.response.UcsBladeResponse;
 import org.apache.cloudstack.api.response.UcsManagerResponse;
 import org.apache.cloudstack.api.response.UcsProfileResponse;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.log4j.Logger;
-import org.apache.cloudstack.api.DeleteUcsManagerCmd;
 
 import com.cloud.configuration.Config;
 import com.cloud.dc.ClusterDetailsDao;
@@ -60,9 +61,8 @@ import com.cloud.ucs.structure.UcsCookie;
 import com.cloud.ucs.structure.UcsProfile;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.xmlobject.XmlObject;
@@ -132,7 +132,7 @@ public class UcsManagerImpl implements UcsManager {
 		}
 
     	private void syncBlades(UcsManagerVO mgr) {
-    		GenericQueryBuilder<UcsBladeVO, UcsBladeVO> q = GenericQueryBuilder.create(UcsBladeVO.class);
+            QueryBuilder<UcsBladeVO> q = QueryBuilder.create(UcsBladeVO.class);
     		q.and(q.entity().getUcsManagerId(), Op.EQ, mgr.getId());
     		List<UcsBladeVO> pblades = q.list();
     		if (pblades.isEmpty()) {
@@ -210,7 +210,7 @@ public class UcsManagerImpl implements UcsManager {
     @Override
     @DB
     public UcsManagerResponse addUcsManager(AddUcsManagerCmd cmd) {
-        GenericQueryBuilder<UcsManagerVO, UcsManagerVO> q = GenericQueryBuilder.create(UcsManagerVO.class);
+        QueryBuilder<UcsManagerVO> q = QueryBuilder.create(UcsManagerVO.class);
         q.and(q.entity().getUrl(), Op.EQ, cmd.getUrl());
         UcsManagerVO mgrvo = q.find();
         if (mgrvo != null) {
@@ -342,7 +342,7 @@ public class UcsManagerImpl implements UcsManager {
 
     @Override
     public UcsBladeResponse associateProfileToBlade(AssociateUcsProfileToBladeCmd cmd) {
-        GenericQueryBuilder<UcsBladeVO, UcsBladeVO> q = GenericQueryBuilder.create(UcsBladeVO.class);
+        QueryBuilder<UcsBladeVO> q = QueryBuilder.create(UcsBladeVO.class);
         q.and(q.entity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
         q.and(q.entity().getId(), Op.EQ, cmd.getBladeId());
         UcsBladeVO bvo = q.find();
@@ -424,7 +424,7 @@ public class UcsManagerImpl implements UcsManager {
             return response;
     	}
     	
-        GenericQueryBuilder<UcsManagerVO, UcsManagerVO> serv = GenericQueryBuilder.create(UcsManagerVO.class);
+        QueryBuilder<UcsManagerVO> serv = QueryBuilder.create(UcsManagerVO.class);
         serv.and(serv.entity().getZoneId(), Op.EQ, cmd.getZoneId());
         List<UcsManagerVO> vos = serv.list();
 
@@ -454,7 +454,7 @@ public class UcsManagerImpl implements UcsManager {
     
     @Override
     public ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd) {
-        GenericQueryBuilder<UcsBladeVO, UcsBladeVO> serv = GenericQueryBuilder.create(UcsBladeVO.class);
+        QueryBuilder<UcsBladeVO> serv = QueryBuilder.create(UcsBladeVO.class);
         serv.and(serv.entity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
         List<UcsBladeVO> vos = serv.list();
         
@@ -509,7 +509,7 @@ public class UcsManagerImpl implements UcsManager {
 
 	@Override
 	public void deleteUcsManager(Long id) {
-        GenericQueryBuilder<UcsBladeVO, UcsBladeVO> serv = GenericQueryBuilder.create(UcsBladeVO.class);
+        QueryBuilder<UcsBladeVO> serv = QueryBuilder.create(UcsBladeVO.class);
         serv.and(serv.entity().getUcsManagerId(), Op.EQ, id);
         List<UcsBladeVO> vos = serv.list();
         for (UcsBladeVO vo : vos) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b60eef3e/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java
index bb357ca..bb058e3 100755
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java
@@ -16,6 +16,31 @@
 // under the License.
 package com.cloud.hypervisor.xen.discoverer;
 
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import javax.persistence.EntityExistsException;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Host;
+import com.xensource.xenapi.Pool;
+import com.xensource.xenapi.Session;
+import com.xensource.xenapi.Types.SessionAuthenticationFailed;
+import com.xensource.xenapi.Types.XenAPIException;
+
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
 import com.cloud.agent.api.AgentControlAnswer;
@@ -69,33 +94,10 @@ import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.user.Account;
 import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.GenericQueryBuilder;
-import com.cloud.utils.db.GenericQueryBuilder;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.exception.HypervisorVersionChangedException;
-import com.xensource.xenapi.Connection;
-import com.xensource.xenapi.Host;
-import com.xensource.xenapi.Pool;
-import com.xensource.xenapi.Session;
-import com.xensource.xenapi.Types.SessionAuthenticationFailed;
-import com.xensource.xenapi.Types.XenAPIException;
-import org.apache.log4j.Logger;
-import org.apache.xmlrpc.XmlRpcException;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-import javax.persistence.EntityExistsException;
-import java.net.InetAddress;
-import java.net.URI;
-import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.Set;
 
 @Local(value=Discoverer.class)
 public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
@@ -126,7 +128,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
         try {
             _clusterDao.update(cluster.getId(), cluster);
         } catch (EntityExistsException e) {
-            GenericQueryBuilder<ClusterVO, ClusterVO> sc = GenericQueryBuilder.create(ClusterVO.class);
+            QueryBuilder<ClusterVO> sc = QueryBuilder.create(ClusterVO.class);
             sc.and(sc.entity().getGuid(), Op.EQ, guid);
             List<ClusterVO> clusters = sc.list();
             ClusterVO clu = clusters.get(0);


Mime
View raw message