From: <pn...@hy...> - 2009-04-29 18:40:24
|
Author: pnguyen Date: 2009-04-29 11:40:16 -0700 (Wed, 29 Apr 2009) New Revision: 13106 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=13106 Modified: trunk/src/org/hyperic/hq/appdef/server/session/PlatformDAO.java trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java Log: HHQ-3059: backend apis to manage network hierarchies (integration testing changes - subject to further refactoring) Modified: trunk/src/org/hyperic/hq/appdef/server/session/PlatformDAO.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/PlatformDAO.java 2009-04-29 08:06:55 UTC (rev 13105) +++ trunk/src/org/hyperic/hq/appdef/server/session/PlatformDAO.java 2009-04-29 18:40:16 UTC (rev 13106) @@ -31,6 +31,7 @@ import java.util.List; import org.hibernate.Criteria; +import org.hibernate.Query; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.hibernate.type.IntegerType; @@ -241,7 +242,9 @@ } public List findParentByNetworkRelation(List platformTypeIds, + String platformName, Boolean hasChildren) { + String nameEx = null; String sql = "select {p.*} from EAM_PLATFORM p " + "join EAM_RESOURCE r on p.resource_id = r.id " + "where p.platform_type_id in (:ids) "; @@ -253,15 +256,29 @@ " and e.rel_id = " + AuthzConstants.RELATION_NETWORK_ID + " and e.distance = 0) "; } + if (platformName != null && platformName.trim().length() > 0) { + HQDialect dialect = Util.getHQDialect(); + nameEx = dialect.getRegExSQL("r.sort_name", ":regex", true, false); + String fqdnEx = dialect.getRegExSQL("p.fqdn", ":regex", true, false); + + sql += " and (" + fqdnEx + " or " + nameEx + ") "; + } - return getSession() - .createSQLQuery(sql) - .addEntity("p", Platform.class) - .setParameterList("ids", platformTypeIds, new IntegerType()) - .list(); + Query query = getSession() + .createSQLQuery(sql) + .addEntity("p", Platform.class) + .setParameterList("ids", platformTypeIds, new IntegerType()); + + if (nameEx != null) { + query.setString("regex", platformName); + } + + return query.list(); } - public List findByNoNetworkRelation(List platformTypeIds) { + public List findByNoNetworkRelation(List platformTypeIds, + String platformName) { + String nameEx = null; String sql = "select {p.*} from EAM_PLATFORM p " + "join EAM_RESOURCE r on p.resource_id = r.id " + "where p.platform_type_id in (:ids) " + @@ -270,11 +287,24 @@ " where e.rel_id = " + AuthzConstants.RELATION_NETWORK_ID + " and e.to_id = p.resource_id ) "; - return getSession() - .createSQLQuery(sql) - .addEntity("p", Platform.class) - .setParameterList("ids", platformTypeIds, new IntegerType()) - .list(); + if (platformName != null && platformName.trim().length() > 0) { + HQDialect dialect = Util.getHQDialect(); + nameEx = dialect.getRegExSQL("r.sort_name", ":regex", true, false); + String fqdnEx = dialect.getRegExSQL("p.fqdn", ":regex", true, false); + + sql += " and (" + fqdnEx + " or " + nameEx + ") "; + } + + Query query = getSession() + .createSQLQuery(sql) + .addEntity("p", Platform.class) + .setParameterList("ids", platformTypeIds, new IntegerType()); + + if (nameEx != null) { + query.setString("regex", platformName); + } + + return query.list(); } public List findByType(Integer pid) Modified: trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java 2009-04-29 08:06:55 UTC (rev 13105) +++ trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java 2009-04-29 18:40:16 UTC (rev 13106) @@ -1163,9 +1163,11 @@ */ public List findParentPlatformPojosByNetworkRelation(AuthzSubject subj, List platformTypeIds, + String platformName, Boolean hasChildren) { return getPlatformDAO() - .findParentByNetworkRelation(platformTypeIds, hasChildren); + .findParentByNetworkRelation( + platformTypeIds, platformName, hasChildren); } /** @@ -1176,8 +1178,10 @@ * @ejb:interface-method */ public List findPlatformPojosByNoNetworkRelation(AuthzSubject subj, - List platformTypeIds) { - return getPlatformDAO().findByNoNetworkRelation(platformTypeIds); + List platformTypeIds, + String platformName) { + return getPlatformDAO().findByNoNetworkRelation( + platformTypeIds, platformName); } /** |