/** * the method returns a comma-seperated list of fields, that are affected by a <tt>WFSQuery</tt> * against the subbmitted table. If all fields of the submitted table shall be selected to method * just returns "*". * * <p>example: * * <p>"table1.ID,table1.NAME,table1.VALUE" */ protected String getAffectedFields(String table, FeatureType ft, WFSQuery query) throws Exception { Debug.debugMethodBegin(this, "getAffectedFields"); String s = null; StringBuffer sb = new StringBuffer(1000); String[] props = query.getPropertyNames(); if (props == null || props.length == 0) { HashMap map = ft.getMappings(); if (map == null || map.size() == 0) { sb.append(" * "); } else { // map the database field names to the property names Iterator iterator = map.keySet().iterator(); while (iterator.hasNext()) { String prop = (String) iterator.next(); String[] field = (String[]) map.get(prop); s = field[0]; String tabName = getTableName(ft, s); String[] alias = ft.getAlias(prop); if (table.equals(tabName) && alias != null && !(s.equals(alias[0]))) { sb.append(s + " AS \"" + alias[0] + "\","); } else { if (table.equals(tabName)) { sb.append(s + ","); } } } } } else { for (int i = 0; i < props.length; i++) { if (props[i].equals("COUNT(*)")) { // if a count statement shall performed the result will be // returned in a column named 'COUNTCOUNT' sb.append(props[i] + " AS COUNTCOUNT,"); } else { String[] s_ = ft.getDatastoreField(props[i]); if (s_ == null) { String ex = "Field/property '" + props[i] + "' is not known " + "by the datastore!"; throw new Exception(ex); } s = s_[0]; String tabName = getTableName(ft, s); String[] alias = ft.getAlias(props[i]); if (table.equals(tabName) && alias != null && !(s.equals(alias[0]))) { sb.append(s + " AS \"" + alias[0] + "\","); } else { if (table.equalsIgnoreCase(tabName)) { sb.append(s + ","); } } } } } s = sb.toString(); if (s.length() > 0) { s = s.substring(0, s.length() - 1); } else { throw new Exception("No valid target field for SQL statement selected"); // s = " * "; } Debug.debugMethodEnd(); return s; }