From fd6c1e657a677faaa2253d7210fad5ac992ba64a Mon Sep 17 00:00:00 2001 From: James Dyer Date: Thu, 16 Feb 2012 18:09:01 +0000 Subject: [PATCH] SOLR-2947: fix 'where' clause bug on CachedSqlEntityProcessor (introduced w/SOLR-2382) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1245109 13f79535-47bb-0310-9956-ffa450edef68 --- .../handler/dataimport/DIHCacheSupport.java | 21 +++++++++---------- .../AbstractDataImportHandlerTestCase.java | 3 ++- .../TestCachedSqlEntityProcessor.java | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCacheSupport.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCacheSupport.java index c042bfa86ac..dc99c1e8d10 100644 --- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCacheSupport.java +++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCacheSupport.java @@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory; public class DIHCacheSupport { private static final Logger log = LoggerFactory .getLogger(DIHCacheSupport.class); - private String cacheVariableName; + private String cacheForeignKey; private String cacheImplName; private Map queryVsCache = new HashMap(); private Map>> queryVsCacheIterator; @@ -27,10 +27,8 @@ public class DIHCacheSupport { this.cacheImplName = cacheImplName; String where = context.getEntityAttribute("where"); - String cacheKey = context - .getEntityAttribute(DIHCacheSupport.CACHE_PRIMARY_KEY); - String lookupKey = context - .getEntityAttribute(DIHCacheSupport.CACHE_FOREIGN_KEY); + String cacheKey = context.getEntityAttribute(DIHCacheSupport.CACHE_PRIMARY_KEY); + String lookupKey = context.getEntityAttribute(DIHCacheSupport.CACHE_FOREIGN_KEY); if (cacheKey != null && lookupKey == null) { throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "'cacheKey' is specified for the entity " @@ -43,15 +41,16 @@ public class DIHCacheSupport { } else { if (where != null) { String[] splits = where.split("="); - cacheVariableName = splits[1].trim(); + cacheKey = splits[0]; + cacheForeignKey = splits[1].trim(); } else { - cacheVariableName = lookupKey; + cacheForeignKey = lookupKey; } cacheDoKeyLookup = true; } context.setSessionAttribute(DIHCacheSupport.CACHE_PRIMARY_KEY, cacheKey, Context.SCOPE_ENTITY); - context.setSessionAttribute(DIHCacheSupport.CACHE_FOREIGN_KEY, lookupKey, + context.setSessionAttribute(DIHCacheSupport.CACHE_FOREIGN_KEY, cacheForeignKey, Context.SCOPE_ENTITY); context.setSessionAttribute(DIHCacheSupport.CACHE_DELETE_PRIOR_DATA, "true", Context.SCOPE_ENTITY); @@ -90,7 +89,7 @@ public class DIHCacheSupport { } queryVsCache = null; dataSourceRowCache = null; - cacheVariableName = null; + cacheForeignKey = null; } /** @@ -142,10 +141,10 @@ public class DIHCacheSupport { */ protected Map getIdCacheData(Context context, String query, Iterator> rowIterator) { - Object key = context.resolve(cacheVariableName); + Object key = context.resolve(cacheForeignKey); if (key == null) { throw new DataImportHandlerException(DataImportHandlerException.WARN, - "The cache lookup value : " + cacheVariableName + "The cache lookup value : " + cacheForeignKey + " is resolved to be null in the entity :" + context.getEntityAttribute("name")); diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java index af1a3b2538a..e6dead10157 100644 --- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java +++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java @@ -36,6 +36,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.File; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -148,7 +149,7 @@ public abstract class AbstractDataImportHandlerTestCase extends */ @SuppressWarnings("unchecked") public static Map createMap(Object... args) { - Map result = new HashMap(); + Map result = new LinkedHashMap(); if (args == null || args.length == 0) return result; diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java index e945a15eb32..e2cf59f324a 100644 --- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java +++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java @@ -184,7 +184,7 @@ public class TestCachedSqlEntityProcessor extends AbstractDataImportHandlerTestC } @Test - public void withWhereClause() { + public void withKeyAndLookup() { List fields = new ArrayList(); fields.add(createMap("column", "id")); fields.add(createMap("column", "desc")); @@ -200,7 +200,7 @@ public class TestCachedSqlEntityProcessor extends AbstractDataImportHandlerTestC } @Test - public void withKeyAndLookup() { + public void withWhereClause() { List fields = new ArrayList(); fields.add(createMap("column", "id")); fields.add(createMap("column", "desc")); @@ -216,7 +216,7 @@ public class TestCachedSqlEntityProcessor extends AbstractDataImportHandlerTestC private void doWhereTest(String q, Context context, MockDataSource ds, Map xNamespace) { List> rows = new ArrayList>(); - rows.add(createMap("id", 1, "desc", "one")); + rows.add(createMap("desc", "one", "id", 1)); rows.add(createMap("id", 2, "desc", "two")); rows.add(createMap("id", 2, "desc", "another two")); rows.add(createMap("id", 3, "desc", "three"));