com\esri\arcgis\sample\util\QueryUtil.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package com.esri.arcgis.sample.util; import com.esri.adf.web.data.WebLayerInfo; import com.esri.adf.web.data.geometry.WebGeometry; import com.esri.adf.web.data.query.IdentifyCriteria; import com.esri.adf.web.data.query.PredefinedQueryCriteria; import com.esri.adf.web.data.query.TextCriteria; import com.esri.adf.web.data.query.WebQuery; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Utility to perform queries to the server */ public class QueryUtil { /** * Example: find feature at argument point in layer within argument tolerance */ public static List execute(WebQuery webQuery, String layerName, WebGeometry webGeometry, int tolerance) { IdentifyCriteria ic = new IdentifyCriteria(webGeometry, tolerance); return webQuery.query(ic, getQueryLayersIds(webQuery, layerName)); } /** * Example: find all features in layer within argument extent */ public static List execute(WebQuery webQuery, String layerName, WebGeometry webGeometry) { IdentifyCriteria ic = new IdentifyCriteria(webGeometry); return webQuery.query(ic, getQueryLayersIds(webQuery, layerName)); } /** * Example: find a feature in argument layer who's attribute matches argument * search text */ public static List execute(WebQuery webQuery, String layerName, String searchText) { TextCriteria tc = new TextCriteria(); tc.setSearchText(searchText); return webQuery.query(tc, getQueryLayersIds(webQuery, layerName)); } /** * Example: find 'California' in layer 'states' in column 'STATE_NAME' */ public static List execute(WebQuery webQuery, String layerName, String columnName, String searchText) { PredefinedQueryCriteria qc = new PredefinedQueryCriteria(); qc.setWhereClause(columnName + " = '" + searchText + "'"); return webQuery.query(qc, getQueryLayersIds(webQuery, layerName)); } /** * Get layer ids for argument layer names */ public static List getQueryLayersIds(WebQuery webQuery, String layerName) { List queryLayers = webQuery.getQueryLayers(); List layers = new ArrayList(); for (Iterator iter = queryLayers.iterator(); iter.hasNext();) { WebLayerInfo layer = (WebLayerInfo) iter.next(); if (layerName.equals(layer.getName())) { layers.add(layer); break; } } return layers; } }