You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2011/09/28 06:23:10 UTC

svn commit: r1176716 - in /oodt/trunk: ./ xmlps/src/main/conf/ xmlps/src/main/java/org/apache/oodt/xmlps/mapping/ xmlps/src/main/java/org/apache/oodt/xmlps/product/ xmlps/src/main/java/org/apache/oodt/xmlps/profile/ xmlps/src/test/java/org/apache/oodt/...

Author: mattmann
Date: Wed Sep 28 04:23:09 2011
New Revision: 1176716

URL: http://svn.apache.org/viewvc?rev=1176716&view=rev
Log:
- fix for OODT-61 appendTableName property for mapping files in XMLPS breaks columnname-based lookup in ResultSet (contributed by Ricky Nguyen)

Added:
    oodt/trunk/xmlps/src/test/resources/test-same-col-name-ps.xml
Modified:
    oodt/trunk/CHANGES.txt
    oodt/trunk/xmlps/src/main/conf/example-ps.xml
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldScope.java
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldType.java
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/Mapping.java
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingField.java
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingReader.java
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/DBMSExecutor.java
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java
    oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/profile/DBMSExecutor.java
    oodt/trunk/xmlps/src/test/java/org/apache/oodt/xmlps/mapping/TestMappingReader.java

Modified: oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Wed Sep 28 04:23:09 2011
@@ -4,6 +4,9 @@ Apache OODT Change Log
 Release 0.4: Current Development
 --------------------------------------------
 
+* OODT-61 appendTableName property for mapping files in XMLPS 
+  breaks columnname-based lookup in ResultSet (Ricky Nguyen, mattmann)
+
 * OODT-318 Fix for Jenkins builds and java.io.tmpdir issue 
   for testing via Maven (mattann, Olivier Lamy)
   

Modified: oodt/trunk/xmlps/src/main/conf/example-ps.xml
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/conf/example-ps.xml?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/conf/example-ps.xml (original)
+++ oodt/trunk/xmlps/src/main/conf/example-ps.xml Wed Sep 28 04:23:09 2011
@@ -25,19 +25,19 @@ limitations under the License.
 	<!-- 
 		field:
 		
-		type (required):   dyanmic or constant. If you choose dynamic, then the field
+		type (required):   dynamic or constant. If you choose dynamic, then the field
 		value is read from the row in the ResultSet returned
 		from the database. If constant, then each returned row
 		from the ResultSet is annotated with the value specified
 		in the 'value' attribute.
 		
-	    name (required):   the name of the attribute that you want returned
+	  name (required):   the name of the attribute that you want returned
 		in the product server.
 		
 		string (optional): whether or not the internal db representation at the local
 		site for this field is a STRING, or something else (e.g., a number, etc.). Possible 
 		values for this attribute are "true", to indicate that the field is a string, or
-		"false", to indicate that it is something else. If this attribute is ommited, a value
+		"false", to indicate that it is something else. If this attribute is omitted, a value
 		of "false" is assumed, and the attribute will not be quoted in the where clause of
 		the underlying SQL statement generated.
 		
@@ -51,16 +51,11 @@ limitations under the License.
 		
 		value (optional):  is necessary to provide if type='constant' is selected.
 		
-		scope (optional):  limits the scope of a field's existance: acceptable values
+		scope (optional):  limits the scope of a field's existence: acceptable values
 		are &quot;query&quot;, which signifies that the field is only applicable when
 		translating queries: and &quot;return&quot;, which signifies the field is only
 		applicable as a return field when converting database results into CDEResults.
 		
-		appendTableName (optional): if specified and set to true, during conversion of 
-		CDEs to SDEs, the table name associated with the field will be prefixed to the field 
-		name, and concatenated with a &quot;.&quot; if not specified (or set to false), then 
-		table name is omitted during translation. 
-		
 	-->
 	<field type="dynamic" name="CDE_NAME1" dbname="site_specific_name1" table="Table1" />
 	<field type="dynamic" name="CDE_NAME2" dbname="site_specific_name2" table="Table2" />

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldScope.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldScope.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldScope.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldScope.java Wed Sep 28 04:23:09 2011
@@ -18,59 +18,18 @@
 package org.apache.oodt.xmlps.mapping;
 
 /**
- * 
+ *
  * <p>
  * Defines the scope of a {@link MappingField}.
  * </p>.
  */
-public abstract class FieldScope {
+public enum FieldScope {
 
-    public static FieldScope QUERY = new QueryFieldScope();
+  QUERY,
+  RETURN;
 
-    public static FieldScope RETURN = new ReturnFieldScope();
-
-    private static final String SCOPE_QUERY = "query";
-
-    private static final String SCOPE_RETURN = "return";
-
-    protected abstract String getType();
-
-    @Override
-    public boolean equals(Object o) {
-        if (!(o instanceof FieldScope)) {
-            return false;
-        }
-
-        FieldScope other = (FieldScope) o;
-        return this.getType().equals(other.getType());
-    }
-
-    private static final class QueryFieldScope extends FieldScope {
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see org.apache.oodt.xmlps.mapping.FieldScope#getType()
-         */
-        @Override
-        protected String getType() {
-            return SCOPE_QUERY;
-        }
-
-    }
-
-    private static final class ReturnFieldScope extends FieldScope {
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see org.apache.oodt.xmlps.mapping.FieldScope#getType()
-         */
-        @Override
-        protected String getType() {
-            return SCOPE_RETURN;
-        }
-
-    }
+  public String getType() {
+    return toString().toLowerCase();
+  }
 
 }

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldType.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldType.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldType.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/FieldType.java Wed Sep 28 04:23:09 2011
@@ -18,64 +18,18 @@
 package org.apache.oodt.xmlps.mapping;
 
 /**
- * 
+ *
  * <p>
  * Defines the type of a {@link MappingField}
  * </p>.
  */
-public abstract class FieldType {
+public enum FieldType {
 
-    private static final String TYPE_DYNAMIC = "dynamic";
+  DYNAMIC,
+  CONSTANT;
 
-    private static final String TYPE_CONSTANT = "constant";
-
-    public static final FieldType DYNAMIC = new DynamicFieldType();
-
-    public static final FieldType CONSTANT = new ConstantFieldType();
-
-    protected abstract String getType();
-    
-    @Override
-    public boolean equals(Object o){
-        if(!(o instanceof FieldType)){
-            return false;
-        }
-        
-        FieldType other = (FieldType)o;
-        return this.getType().equals(other.getType());
-    }
-
-    private static class DynamicFieldType extends FieldType {
-
-        public DynamicFieldType() {
-
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see org.apache.oodt.xmlps.mapping.FieldType#getType()
-         */
-        @Override
-        protected String getType() {
-            return TYPE_DYNAMIC;
-        }
-
-    }
-
-    private static class ConstantFieldType extends FieldType {
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see org.apache.oodt.xmlps.mapping.FieldType#getType()
-         */
-        @Override
-        protected String getType() {
-            // TODO Auto-generated method stub
-            return TYPE_CONSTANT;
-        }
-
-    }
+  public String getType() {
+    return toString().toLowerCase();
+  }
 
 }

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/Mapping.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/Mapping.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/Mapping.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/Mapping.java Wed Sep 28 04:23:09 2011
@@ -19,13 +19,12 @@ package org.apache.oodt.xmlps.mapping;
 
 //JDK imports
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
 /**
- * 
+ *
  * <p>
  * An Mapping is a {@link List} of {@link MappingField}s that define the
  * translation of common ontological queries into queries against a local site's
@@ -35,16 +34,16 @@ import java.util.TreeMap;
  */
 public class Mapping {
 
-  private Map<String, MappingField> fields;
+  private final Map<String, MappingField> fields;
 
-  private DatabaseTableGroup tables;
+  private final DatabaseTableGroup tables;
 
   private String id;
 
   private String name;
 
   /**
-     * 
+     *
      */
   public Mapping() {
     this.fields = new TreeMap<String, MappingField>();
@@ -72,33 +71,13 @@ public class Mapping {
       return null;
     }
 
-    for (Iterator<String> i = this.fields.keySet().iterator(); i.hasNext();) {
-      String commonName = i.next();
-      MappingField fld = this.fields.get(commonName);
-      if (getFieldLocalName(fld).equals(localName)) {
+    for (MappingField fld : this.fields.values()) {
+      if (fld.getLocalName().equals(localName)) {
         return fld;
       }
     }
 
     return null;
-
-  }
-
-  public String getFieldLocalName(MappingField fld) {
-    String newFldName = fld.getName();
-    if (fld.getDbName() != null && !fld.getDbName().equals("")) {
-      newFldName = fld.getDbName();
-    }
-
-    if (fld.isAppendTableName()) {
-      if (fld.getTableName() != null && !fld.getTableName().equals("")) {
-        newFldName = fld.getTableName() + "." + newFldName;
-      } else {
-        newFldName = getDefaultTable() + "." + newFldName;
-      }
-    }
-
-    return newFldName;
   }
 
   public MappingField getFieldByName(String name) {
@@ -112,7 +91,7 @@ public class Mapping {
       return true; // leave it out
     }
 
-    if (fld.getType().equals(FieldType.CONSTANT)) {
+    if (fld.getType() == FieldType.CONSTANT) {
       return true;
     } else
       return false;

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingField.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingField.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingField.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingField.java Wed Sep 28 04:23:09 2011
@@ -20,13 +20,12 @@ package org.apache.oodt.xmlps.mapping;
 //OODT imports
 import org.apache.oodt.xmlps.mapping.funcs.MappingFunc;
 
-//JDK imports
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 
 /**
- * 
+ *
  * <p>
  * A field within a mapping.xml file that defines the relationship between CDEs
  * and the underlying attributes of a local site's DBMS.
@@ -51,8 +50,6 @@ public class MappingField {
 
   private boolean string;
 
-  private boolean appendTableName;
-
   /**
    * @param name
    * @param type
@@ -66,7 +63,7 @@ public class MappingField {
    */
   public MappingField(String name, FieldType type, String dbName,
       String tableName, String constantValue, FieldScope scope,
-      List<MappingFunc> funcs, boolean string, boolean appendTableName) {
+      List<MappingFunc> funcs, boolean string) {
     super();
     this.name = name;
     this.type = type;
@@ -76,11 +73,10 @@ public class MappingField {
     this.scope = scope;
     this.funcs = funcs;
     this.string = string;
-    this.appendTableName = appendTableName;
   }
 
   /**
-     * 
+     *
      */
   public MappingField() {
     this.name = null;
@@ -89,7 +85,6 @@ public class MappingField {
     this.constantValue = null;
     this.scope = null;
     this.string = false;
-    this.appendTableName = false;
     this.funcs = new Vector<MappingFunc>();
   }
 
@@ -198,6 +193,7 @@ public class MappingField {
     this.funcs = funcs;
   }
 
+  @Override
   public String toString() {
     StringBuffer rStr = new StringBuffer("[name=");
     rStr.append(this.name);
@@ -215,8 +211,6 @@ public class MappingField {
     rStr.append(printClassNames(this.funcs));
     rStr.append(",string=");
     rStr.append(String.valueOf(this.string));
-    rStr.append(",appendTableName=");
-    rStr.append(String.valueOf(this.appendTableName));
     rStr.append("]");
     return rStr.toString();
   }
@@ -255,16 +249,18 @@ public class MappingField {
   }
 
   /**
-   * @param appendTableName
-   *          determines whether the Mapping should append DB table name to
-   *          field name when constructing queries, retrieving results from
-   *          ResultSets, etc.
-   */
-  public void setAppendTableName(boolean appendTableName) {
-    this.appendTableName = appendTableName;
+   * If dbname exists and is not empty, it is used as the field name.
+   * If the table exists and is not empty,
+   * return tableName.fieldName, otherwise return fieldName.
+   * @return the column name understood by the local db
+   */
+  public String getLocalName() {
+    String dbColName = getName();
+    if (getDbName() != null && !getDbName().isEmpty())
+      dbColName = getDbName();
+    if (getTableName() == null || getTableName().isEmpty())
+      return dbColName;
+    return getTableName() + "." + dbColName;
   }
 
-  public boolean isAppendTableName() {
-    return appendTableName;
-  }
 }

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingReader.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingReader.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingReader.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/mapping/MappingReader.java Wed Sep 28 04:23:09 2011
@@ -22,13 +22,13 @@ import org.apache.oodt.commons.xml.XMLUt
 import org.apache.oodt.xmlps.mapping.funcs.MappingFunc;
 import org.apache.oodt.xmlps.util.GenericCDEObjectFactory;
 
-//JDK imports
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.List;
 import java.util.Properties;
 import java.util.Vector;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -36,7 +36,7 @@ import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 /**
- * 
+ *
  * <p>
  * A static final reader class for reading {@link Mapping}s.
  * </p>
@@ -119,6 +119,8 @@ public final class MappingReader impleme
     if (fldNodes != null && fldNodes.getLength() > 0) {
       for (int i = 0; i < fldNodes.getLength(); i++) {
         MappingField fld = readField((Element) fldNodes.item(i));
+        if (fld.getTableName() == null || fld.getTableName().isEmpty())
+          fld.setTableName(map.getDefaultTable());
         map.addField(fld.getName(), fld);
       }
     }
@@ -144,8 +146,6 @@ public final class MappingReader impleme
     }
 
     field.setFuncs(getTranslateFuncs(fldElem));
-    field.setAppendTableName(Boolean.valueOf(fldElem
-          .getAttribute(FIELD_ATTR_APPEND_TABLE_NAME)));
 
     return field;
 

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/DBMSExecutor.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/DBMSExecutor.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/DBMSExecutor.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/DBMSExecutor.java Wed Sep 28 04:23:09 2011
@@ -19,15 +19,14 @@ package org.apache.oodt.xmlps.product;
 
 //OODT imports
 import org.apache.oodt.commons.database.DatabaseConnectionBuilder;
-import org.apache.oodt.xmlps.mapping.Mapping;
 import org.apache.oodt.xmlps.mapping.FieldType;
+import org.apache.oodt.xmlps.mapping.Mapping;
 import org.apache.oodt.xmlps.mapping.MappingField;
 import org.apache.oodt.xmlps.mapping.funcs.MappingFunc;
 import org.apache.oodt.xmlps.structs.CDEResult;
 import org.apache.oodt.xmlps.structs.CDERow;
 import org.apache.oodt.xmlps.structs.CDEValue;
 
-//JDK imports
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -36,10 +35,11 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
 import javax.sql.DataSource;
 
 /**
- * 
+ *
  * <p>
  * Executes CDE Queries against an underlying JDBC database, backed by Apache
  * commons-pool and commons-dbcp.
@@ -48,7 +48,7 @@ import javax.sql.DataSource;
  */
 public class DBMSExecutor {
 
-  private DataSource dataSource;
+  private final DataSource dataSource;
 
   private static final Logger LOG = Logger.getLogger(DBMSExecutor.class
       .getName());
@@ -113,7 +113,7 @@ public class DBMSExecutor {
     if (returnNames != null && returnNames.size() > 0) {
       for (Iterator<String> i = returnNames.iterator(); i.hasNext();) {
         String retName = i.next();
-        MappingField fld = map.getFieldByLocalName(retName);
+        MappingField fld = map.getFieldByName(retName);
         // only handle dynamic fields here
         // if it was a constant field, then it will be dealt with
         // later

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/product/XMLPSProductHandler.java Wed Sep 28 04:23:09 2011
@@ -18,22 +18,11 @@
 package org.apache.oodt.xmlps.product;
 
 //OODT imports
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Stack;
-import java.util.Vector;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-//OODT imports
+import org.apache.oodt.product.ProductException;
+import org.apache.oodt.product.QueryHandler;
 import org.apache.oodt.xmlps.mapping.DatabaseTable;
-import org.apache.oodt.xmlps.mapping.Mapping;
 import org.apache.oodt.xmlps.mapping.FieldScope;
+import org.apache.oodt.xmlps.mapping.Mapping;
 import org.apache.oodt.xmlps.mapping.MappingField;
 import org.apache.oodt.xmlps.mapping.MappingReader;
 import org.apache.oodt.xmlps.mapping.funcs.MappingFunc;
@@ -43,16 +32,24 @@ import org.apache.oodt.xmlps.structs.CDE
 import org.apache.oodt.xmlps.structs.CDERow;
 import org.apache.oodt.xmlps.structs.CDEValue;
 import org.apache.oodt.xmlps.util.XMLQueryHelper;
-
-//OODT imports
-import org.apache.oodt.product.ProductException;
-import org.apache.oodt.product.QueryHandler;
 import org.apache.oodt.xmlquery.QueryElement;
 import org.apache.oodt.xmlquery.Result;
 import org.apache.oodt.xmlquery.XMLQuery;
 
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Stack;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 /**
- * 
+ *
  * <p>
  * An XML configurable version of a Product Server that requires no code
  * to be written to plug into a local site's relational backend DBMS.
@@ -115,7 +112,7 @@ public class XMLPSProductHandler impleme
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.oodt.product.QueryHandler#query(org.apache.oodt.xmlquery.XMLQuery)
      */
     public XMLQuery query(XMLQuery query) throws ProductException {
@@ -125,10 +122,12 @@ public class XMLPSProductHandler impleme
             translateToDomain(selectSet, true);
             translateToDomain(whereSet, false);
         } catch (Exception e) {
-            e.printStackTrace();
+            LOG.severe(e.getMessage());
             throw new ProductException(e.getMessage());
         }
+
         queryAndPackageResults(query);
+
         return query;
     }
 
@@ -193,7 +192,7 @@ public class XMLPSProductHandler impleme
         List<QueryElement> names = getElemNamesFromQueryElemSet(query
                 .getSelectElementSet());
 
-        String querySelectNames = toNames(names);
+        String querySelectNames = toSQLSelectColumns(names);
 
         StringBuffer sqlBuf = new StringBuffer("SELECT ");
         sqlBuf.append(querySelectNames);
@@ -213,7 +212,7 @@ public class XMLPSProductHandler impleme
                 sqlBuf.append(".");
                 sqlBuf.append(tbl.getJoinFieldName());
                 sqlBuf.append(" = ");
-                sqlBuf.append((tbl.getDefaultTableJoin() != null && 
+                sqlBuf.append((tbl.getDefaultTableJoin() != null &&
                         !tbl.getDefaultTableJoin().equals("")) ? tbl
                         .getDefaultTableJoin() : mapping.getDefaultTable());
                 sqlBuf.append(".");
@@ -224,7 +223,7 @@ public class XMLPSProductHandler impleme
 
         if(parsedQuery != null){
             sqlBuf.append(" WHERE ");
-            sqlBuf.append(parsedQuery.evaluate());            
+            sqlBuf.append(parsedQuery.evaluate());
         }
 
         LOG.log(Level.INFO, sqlBuf.toString());
@@ -232,8 +231,7 @@ public class XMLPSProductHandler impleme
         if (executor != null) {
             try {
                 CDEResult res = executor.executeLocalQuery(this.mapping,
-                        sqlBuf.toString(), Arrays.asList(querySelectNames
-                                .split(",")));
+                        sqlBuf.toString(), toSQLResultSetColumns(names));
 
                 res = addConstFields(res,
                         getConstElemNamesFromQueryElemSet(query
@@ -286,15 +284,19 @@ public class XMLPSProductHandler impleme
 
     }
 
-    private String toNames(List<QueryElement> elems) {
+    private String toSQLSelectColumns(List<QueryElement> elems) {
         if (elems == null || (elems != null && elems.size() == 0))
             return null;
 
-        StringBuffer buf = new StringBuffer();
-        for (Iterator<QueryElement> i = elems.iterator(); i.hasNext();) {
-            QueryElement elem = i.next();
-            buf.append(elem.getValue());
-            buf.append(",");
+        StringBuilder buf = new StringBuilder();
+        for (QueryElement qe : elems) {
+            MappingField fld = this.mapping.getFieldByLocalName(qe.getValue());
+            if (fld != null) {
+                buf.append(fld.getLocalName());
+                buf.append(" as ");
+                buf.append(fld.getName());
+                buf.append(",");
+            }
         }
 
         buf.deleteCharAt(buf.length() - 1);
@@ -302,6 +304,21 @@ public class XMLPSProductHandler impleme
         return buf.toString();
     }
 
+    private List<String> toSQLResultSetColumns(List<QueryElement> elems) {
+        if (elems == null || (elems != null && elems.size() == 0))
+          return null;
+
+        List<String> resultSetNames = new ArrayList<String>();
+        for (QueryElement qe : elems) {
+            MappingField fld = this.mapping.getFieldByLocalName(qe.getValue());
+            if (fld != null) {
+                resultSetNames.add(fld.getName());
+            }
+        }
+
+        return resultSetNames;
+    }
+
     protected void translateToDomain(List<QueryElement> elemSet,
             boolean selectSet) throws Exception {
         // go through each query element: use the mapping fields
@@ -330,7 +347,7 @@ public class XMLPSProductHandler impleme
                 // check to see if it has a dbname attr, if not, then the name
                 // stays
                 // the same
-                String newFldName = this.mapping.getFieldLocalName(fld);
+                String newFldName = fld.getLocalName();
 
                 elem.setValue(newFldName);
 

Modified: oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/profile/DBMSExecutor.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/profile/DBMSExecutor.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/profile/DBMSExecutor.java (original)
+++ oodt/trunk/xmlps/src/main/java/org/apache/oodt/xmlps/profile/DBMSExecutor.java Wed Sep 28 04:23:09 2011
@@ -18,13 +18,20 @@
 package org.apache.oodt.xmlps.profile;
 
 //OODT imports
-import org.apache.oodt.xmlps.mapping.Mapping;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.metadata.util.PathUtils;
+import org.apache.oodt.commons.database.DatabaseConnectionBuilder;
+import org.apache.oodt.profile.EnumeratedProfileElement;
+import org.apache.oodt.profile.Profile;
+import org.apache.oodt.profile.ProfileAttributes;
+import org.apache.oodt.profile.ProfileElement;
+import org.apache.oodt.profile.ResourceAttributes;
 import org.apache.oodt.xmlps.mapping.FieldType;
+import org.apache.oodt.xmlps.mapping.Mapping;
 import org.apache.oodt.xmlps.mapping.MappingField;
 import org.apache.oodt.xmlps.mapping.funcs.MappingFunc;
 import org.apache.oodt.xmlps.structs.CDEValue;
 
-//JDK imports
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -34,20 +41,11 @@ import java.util.List;
 import java.util.Vector;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import javax.sql.DataSource;
 
-//OODT imports
-import org.apache.oodt.profile.EnumeratedProfileElement;
-import org.apache.oodt.profile.Profile;
-import org.apache.oodt.profile.ProfileAttributes;
-import org.apache.oodt.profile.ProfileElement;
-import org.apache.oodt.profile.ResourceAttributes;
-import org.apache.oodt.cas.metadata.Metadata;
-import org.apache.oodt.cas.metadata.util.PathUtils;
-import org.apache.oodt.commons.database.DatabaseConnectionBuilder;
+import javax.sql.DataSource;
 
 /**
- * 
+ *
  * <p>
  * Executes Profile Queries against an underlying JDBC database, backed by
  * Apache commons-pool and commons-dbcp.
@@ -56,7 +54,7 @@ import org.apache.oodt.commons.database.
  */
 public class DBMSExecutor {
 
-  private DataSource dataSource;
+  private final DataSource dataSource;
 
   private static final Logger LOG = Logger.getLogger(DBMSExecutor.class
       .getName());
@@ -155,7 +153,7 @@ public class DBMSExecutor {
       } catch (SQLException e) {
         e.printStackTrace();
         LOG.log(Level.WARNING, "Unable to obtain field: ["
-            + map.getFieldLocalName(fld) + "] from result set: message: "
+            + fld.getLocalName() + "] from result set: message: "
             + e.getMessage());
       }
 

Modified: oodt/trunk/xmlps/src/test/java/org/apache/oodt/xmlps/mapping/TestMappingReader.java
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/test/java/org/apache/oodt/xmlps/mapping/TestMappingReader.java?rev=1176716&r1=1176715&r2=1176716&view=diff
==============================================================================
--- oodt/trunk/xmlps/src/test/java/org/apache/oodt/xmlps/mapping/TestMappingReader.java (original)
+++ oodt/trunk/xmlps/src/test/java/org/apache/oodt/xmlps/mapping/TestMappingReader.java Wed Sep 28 04:23:09 2011
@@ -21,10 +21,8 @@ package org.apache.oodt.xmlps.mapping;
 import org.apache.oodt.xmlps.mapping.funcs.MappingFunc;
 import org.apache.oodt.xmlps.structs.CDEValue;
 
-//JDK imports
 import java.io.InputStream;
 
-//Junit imports
 import junit.framework.TestCase;
 
 /**
@@ -106,6 +104,19 @@ public class TestMappingReader extends T
         assertEquals(result.getVal(), "235");
     }
 
+    public void testMappingFieldGetLocalName() {
+        Mapping mapping = getMappingOrFail("test-same-col-name-ps.xml");
+
+        MappingField fieldOnly = mapping.getFieldByName("field_only");
+        assertEquals("defaultTable.field_only", fieldOnly.getLocalName());
+
+        MappingField fieldWithTable = mapping.getFieldByName("field_with_table");
+        assertEquals("anotherTable.field_db", fieldWithTable.getLocalName());
+
+        MappingField fieldUseDefault = mapping.getFieldByName("field_use_default");
+        assertEquals("defaultTable.field_db", fieldUseDefault.getLocalName());
+    }
+
     private void containsSpecimenCollectedCodeOrFail(Mapping mapping) {
 
         MappingField fld = mapping.getFieldByName(SPECIMEN_COLLECTED_CODE);
@@ -129,10 +140,14 @@ public class TestMappingReader extends T
     }
 
     private Mapping getMappingOrFail() {
+      return getMappingOrFail("test-ps.xml");
+    }
+
+    private Mapping getMappingOrFail(String mapfile) {
         Mapping mapping = null;
 
         InputStream configFileIs = TestMappingReader.class
-                .getResourceAsStream("test-ps.xml");
+                .getResourceAsStream(mapfile);
 
         try {
             mapping = MappingReader.getMapping(configFileIs);

Added: oodt/trunk/xmlps/src/test/resources/test-same-col-name-ps.xml
URL: http://svn.apache.org/viewvc/oodt/trunk/xmlps/src/test/resources/test-same-col-name-ps.xml?rev=1176716&view=auto
==============================================================================
--- oodt/trunk/xmlps/src/test/resources/test-same-col-name-ps.xml (added)
+++ oodt/trunk/xmlps/src/test/resources/test-same-col-name-ps.xml Wed Sep 28 04:23:09 2011
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file 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.
+-->
+<!-- Example XML mapping configuration file -->
+<oodt:xmlps xmlns:oodt="http://incubator.apache.org/oodt/0.1-incubating"
+  name="Example Query Handler" id="project:subproject:exampleps">
+  <tables default="defaultTable">
+    <table name="joinTable" join="id" tofld="id" />
+  </tables>
+  <!-- 
+    field:
+    
+    type (required):   dynamic or constant. If you choose dynamic, then the field
+    value is read from the row in the ResultSet returned
+    from the database. If constant, then each returned row
+    from the ResultSet is annotated with the value specified
+    in the 'value' attribute.
+    
+    name (required):   the name of the attribute that you want returned
+    in the product server.
+    
+    string (optional): whether or not the internal db representation at the local
+    site for this field is a STRING, or something else (e.g., a number, etc.). Possible 
+    values for this attribute are "true", to indicate that the field is a string, or
+    "false", to indicate that it is something else. If this attribute is omitted, a value
+    of "false" is assumed, and the attribute will not be quoted in the where clause of
+    the underlying SQL statement generated.
+    
+    dbname (optional): the name of the field within the underlying db. If not
+    specified, then assumed to be name
+    
+    table (optional):  if provided, then the attribute a is selected as
+    'table'.'a',and then returned. If omitted, the attribute
+    is assumed to come from the default table returned from the
+    PS query.
+    
+    value (optional):  is necessary to provide if type='constant' is selected.
+    
+    scope (optional):  limits the scope of a field's existence: acceptable values
+    are &quot;query&quot;, which signifies that the field is only applicable when
+    translating queries: and &quot;return&quot;, which signifies the field is only
+    applicable as a return field when converting database results into CDEResults.
+    
+  -->
+  <field type="dynamic" name="id_xmlps" dbname="id" table="defaultTable"/>
+  <field type="dynamic" name="field_only"/>
+  <field type="dynamic" name="field_with_table" dbname="field_db" table="anotherTable"/>
+  <field type="dynamic" name="field_use_default" dbname="field_db"/>
+</oodt:xmlps>