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
This commit is contained in:
James Dyer 2012-02-16 18:09:01 +00:00
parent 59b7673a18
commit fd6c1e657a
3 changed files with 15 additions and 15 deletions

View File

@ -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<String,DIHCache> queryVsCache = new HashMap<String,DIHCache>();
private Map<String,Iterator<Map<String,Object>>> 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<String,Object> getIdCacheData(Context context, String query,
Iterator<Map<String,Object>> 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"));

View File

@ -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;

View File

@ -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<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
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"));