[teiid-commits] teiid SVN: r1810 - in trunk/engine/src: test/java/org/teiid/dqp/internal/process and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Feb 9 17:10:40 EST 2010


Author: shawkins
Date: 2010-02-09 17:10:39 -0500 (Tue, 09 Feb 2010)
New Revision: 1810

Modified:
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/CodeTableCache.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java
Log:
TEIID-829 adding fix for case sensitivity

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/CodeTableCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/CodeTableCache.java	2010-02-09 20:03:49 UTC (rev 1809)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/CodeTableCache.java	2010-02-09 22:10:39 UTC (rev 1810)
@@ -37,6 +37,7 @@
 import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
 import com.metamatrix.dqp.util.LogConstants;
 import com.metamatrix.query.util.CommandContext;
+import com.metamatrix.vdb.runtime.VDBKey;
 
 /**
  * Code table cache.  Heavily synchronized in-memory cache of code tables.  There is no purging policy for this cache.  Once the limits have been reached exceptions will occur.
@@ -189,32 +190,13 @@
         }
 		return table.codeMap.get(keyValue);
     }
-
-   /**
-    * Places the lookup results in the cache and marks the cache loaded
-    * @param requestID
-    * @param nodeID
-    * @return the set of waiting requests
-    * @since 4.2
-    */
-    public Set<Object> markCacheLoaded(CacheKey requestKey) {
-        return markCacheDone(requestKey, false);
-    }
-       
-   /**
-    * Notifies the CodeTableCache that this code table had an error. Removes any existing cached results and clears any state
-    * for this CacheKey.
-    * @param requestID
-    * @param nodeID
-    * @return the set of waiting requests
-    * @since 4.2
-    */
-    public Set<Object> errorLoadingCache(CacheKey requestKey) {
-        return markCacheDone(requestKey, true);
-    }
    
-    private synchronized Set<Object> markCacheDone(CacheKey cacheKey, boolean errorOccurred) {
-        if (errorOccurred) {
+    /**
+     * Notifies the CodeTableCache that this code is done.  If the table had an error, it removes any temporary results.
+     * @return the set of waiting requests
+     */
+    public synchronized Set<Object> markCacheDone(CacheKey cacheKey, boolean success) {
+        if (!success) {
             // Remove any results already cached
             CodeTable table = codeTableCache.remove(cacheKey);
             if (table != null) {
@@ -224,7 +206,7 @@
         }
     	CodeTable table = codeTableCache.get(cacheKey);
     	if (table == null || table.codeMap == null) {
-    		return null;
+    		return null; //can only happen if cache was cleared between load and now
     	}
         rowCount += table.codeMap.size();
         Set<Object> waiting = table.waitingRequests;
@@ -264,8 +246,7 @@
         private String codeTable;
         private String returnElement;
         private String keyElement;
-        private String vdbName;
-        private String vdbVersion;
+        private VDBKey vdbKey;
         
         private int hashCode;
         
@@ -273,15 +254,11 @@
             this.codeTable = codeTable;
             this.returnElement = returnElement;
             this.keyElement = keyElement;
-            this.vdbName = vdbName;
-            this.vdbVersion = vdbVersion;
+            this.vdbKey = new VDBKey(vdbName, vdbVersion);
             
             // Compute hash code and cache it
-            hashCode = HashCodeUtil.hashCode(0, codeTable);
-            hashCode = HashCodeUtil.hashCode(hashCode, returnElement);
-            hashCode = HashCodeUtil.hashCode(hashCode, keyElement);   
-            hashCode = HashCodeUtil.hashCode(hashCode, vdbName);
-            hashCode = HashCodeUtil.hashCode(hashCode, vdbVersion);
+            hashCode = HashCodeUtil.hashCode(codeTable.toUpperCase().hashCode(), returnElement.toUpperCase(), 
+            		keyElement.toUpperCase(), vdbKey);
         }
         
         public String getCodeTable() {
@@ -304,11 +281,10 @@
                 CacheKey other = (CacheKey) obj;
                 
                 return (other.hashCode() == hashCode() &&
-                    this.codeTable.equals(other.codeTable) &&
-                    this.returnElement.equals(other.returnElement) && 
-                    this.keyElement.equals(other.keyElement) &&
-                    this.vdbName.equals(other.vdbName) &&
-                    this.vdbVersion.equals(other.vdbVersion));
+                    this.codeTable.equalsIgnoreCase(other.codeTable) &&
+                    this.returnElement.equalsIgnoreCase(other.returnElement) && 
+                    this.keyElement.equalsIgnoreCase(other.keyElement) &&
+                    this.vdbKey.equals(other.vdbKey));
             }
             return false;
         }

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java	2010-02-09 20:03:49 UTC (rev 1809)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java	2010-02-09 22:10:39 UTC (rev 1810)
@@ -446,12 +446,7 @@
             }
         	success = true;
         } finally {
-        	Collection requests = null;
-        	if (success) {
-                requests = codeTableCache.markCacheLoaded(codeRequestId);
-        	} else {
-        		requests = codeTableCache.errorLoadingCache(codeRequestId);        		
-        	}
+        	Collection requests = codeTableCache.markCacheDone(codeRequestId, success);
         	notifyWaitingCodeTableRequests(requests);
         }
     }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java	2010-02-09 20:03:49 UTC (rev 1809)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java	2010-02-09 22:10:39 UTC (rev 1810)
@@ -73,11 +73,7 @@
 		} catch (MetaMatrixProcessingException e) {
 			throw new RuntimeException(e);
 		}
-		if(setDone) {
-			ctc.markCacheLoaded(nodeId);
-		} else {
-			ctc.errorLoadingCache(nodeId);
-		}
+		ctc.markCacheDone(nodeId, setDone);
 		return ctc;	
 	}
 
@@ -98,7 +94,7 @@
 		} catch (MetaMatrixProcessingException e) {
 			throw new RuntimeException(e);
 		}
-		ctc.markCacheLoaded(nodeId);
+		ctc.markCacheDone(nodeId, true);
 		return ctc;	
 	}
 
@@ -115,6 +111,10 @@
 
 		CacheState actualState = ctc.cacheExists("countrycode", "code", "country", TEST_CONTEXT); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		assertEquals("Actual cache state doesn't match with expected: ", CacheState.CACHE_EXISTS, actualState);	 //$NON-NLS-1$
+		
+		//test case insensitive
+		actualState = ctc.cacheExists("countryCODE", "code", "Country", TEST_CONTEXT); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		assertEquals("Actual cache state doesn't match with expected: ", CacheState.CACHE_EXISTS, actualState);	 //$NON-NLS-1$
 	}
 
 	/** state = 1; loading state */



More information about the teiid-commits mailing list