SOLR-1627

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@887875 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2009-12-07 10:27:47 +00:00
parent 5b13258bfa
commit 146b73565d
13 changed files with 45 additions and 51 deletions

View File

@ -568,7 +568,7 @@ public class MailEntityProcessor extends EntityProcessorBase {
try {
String val = context.getEntityAttribute(prop);
if (val != null) {
val = context.getVariableResolver().replaceTokens(val);
val = context.replaceTokens(val);
v = Integer.valueOf(val);
}
} catch (NumberFormatException e) {
@ -581,7 +581,7 @@ public class MailEntityProcessor extends EntityProcessorBase {
boolean v = ifNull;
String val = context.getEntityAttribute(prop);
if (val != null) {
val = context.getVariableResolver().replaceTokens(val);
val = context.replaceTokens(val);
v = Boolean.valueOf(val);
}
return v;
@ -591,7 +591,7 @@ public class MailEntityProcessor extends EntityProcessorBase {
String v = ifNull;
String val = context.getEntityAttribute(prop);
if (val != null) {
val = context.getVariableResolver().replaceTokens(val);
val = context.replaceTokens(val);
v = val;
}
return v;

View File

@ -50,7 +50,7 @@ public class CachedSqlEntityProcessor extends SqlEntityProcessor {
return getFromRowCacheTransformed();
if (!isFirst)
return null;
String query = resolver.replaceTokens(context.getEntityAttribute("query"));
String query = context.replaceTokens(context.getEntityAttribute("query"));
isFirst = false;
if (simpleCache != null) {
return getSimpleCacheData(query);
@ -63,7 +63,7 @@ public class CachedSqlEntityProcessor extends SqlEntityProcessor {
protected List<Map<String, Object>> getAllNonCachedRows() {
List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
String q = getQuery();
initQuery(resolver.replaceTokens(q));
initQuery(context.replaceTokens(q));
if (rowIterator == null)
return rows;
while (rowIterator.hasNext()) {

View File

@ -40,8 +40,6 @@ public class EntityProcessorBase extends EntityProcessor {
protected Context context;
protected VariableResolverImpl resolver;
protected Iterator<Map<String, Object>> rowIterator;
protected List<Transformer> transformers;
@ -54,7 +52,6 @@ public class EntityProcessorBase extends EntityProcessor {
public void init(Context context) {
rowIterator = null;
this.context = context;
resolver = (VariableResolverImpl) context.getVariableResolver();
if (isFirstInit) {
firstInit(context);
}
@ -180,7 +177,7 @@ public class EntityProcessorBase extends EntityProcessor {
Map<Object, List<Map<String, Object>>> rowIdVsRows = cacheWithWhereClause
.get(query);
List<Map<String, Object>> rows = null;
Object key = resolver.resolve(cacheVariableName);
Object key = context.resolve(cacheVariableName);
if (key == null) {
throw new DataImportHandlerException(DataImportHandlerException.WARN,
"The cache lookup value : " + cacheVariableName + " is resolved to be null in the entity :" +

View File

@ -166,6 +166,7 @@ public class EntityProcessorWrapper extends EntityProcessor {
Map<String, Object> transformedRow = row;
List<Map<String, Object>> rows = null;
boolean stopTransform = checkStopTransform(row);
VariableResolverImpl resolver = (VariableResolverImpl) context.getVariableResolver();
for (Transformer t : transformers) {
if (stopTransform) break;
try {
@ -269,7 +270,7 @@ public class EntityProcessorWrapper extends EntityProcessor {
}
public VariableResolverImpl getVariableResolver() {
return resolver;
return (VariableResolverImpl) context.getVariableResolver();
}
public Context getContext() {

View File

@ -109,14 +109,14 @@ public class FileListEntityProcessor extends EntityProcessorBase {
super.init(context);
fileName = context.getEntityAttribute(FILE_NAME);
if (fileName != null) {
fileName = resolver.replaceTokens(fileName);
fileName = context.replaceTokens(fileName);
fileNamePattern = Pattern.compile(fileName);
}
baseDir = context.getEntityAttribute(BASE_DIR);
if (baseDir == null)
throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
"'baseDir' is a required attribute");
baseDir = resolver.replaceTokens(baseDir);
baseDir = context.replaceTokens(baseDir);
File dir = new File(baseDir);
if (!dir.isDirectory())
throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
@ -127,7 +127,7 @@ public class FileListEntityProcessor extends EntityProcessorBase {
recursive = Boolean.parseBoolean(r);
excludes = context.getEntityAttribute(EXCLUDES);
if (excludes != null) {
excludes = resolver.replaceTokens(excludes);
excludes = context.replaceTokens(excludes);
excludesPattern = Pattern.compile(excludes);
}
}
@ -144,11 +144,11 @@ public class FileListEntityProcessor extends EntityProcessorBase {
Matcher m = PLACE_HOLDER_PATTERN.matcher(dateStr);
if (m.find()) {
Object o = resolver.resolve(m.group(1));
Object o = context.resolve(m.group(1));
if (o instanceof Date) return (Date)o;
dateStr = (String) o;
} else {
dateStr = resolver.replaceTokens(dateStr);
dateStr = context.replaceTokens(dateStr);
}
m = EvaluatorBag.IN_SINGLE_QUOTES.matcher(dateStr);
if (m.find()) {
@ -181,14 +181,14 @@ public class FileListEntityProcessor extends EntityProcessorBase {
Matcher m = PLACE_HOLDER_PATTERN.matcher(sizeStr);
if (m.find()) {
Object o = resolver.resolve(m.group(1));
Object o = context.resolve(m.group(1));
if (o instanceof Number) {
Number number = (Number) o;
return number.longValue();
}
sizeStr = (String) o;
} else {
sizeStr = resolver.replaceTokens(sizeStr);
sizeStr = context.replaceTokens(sizeStr);
}
return Long.parseLong(sizeStr);

View File

@ -39,11 +39,10 @@ public class HTMLStripTransformer extends Transformer {
@Override
@SuppressWarnings("unchecked")
public Object transformRow(Map<String, Object> row, Context context) {
VariableResolver resolver = context.getVariableResolver();
List<Map<String, String>> fields = context.getAllEntityFields();
for (Map<String, String> field : fields) {
String col = field.get(DataImporter.COLUMN);
String splitHTML = resolver.replaceTokens(field.get(STRIP_HTML));
String splitHTML = context.replaceTokens(field.get(STRIP_HTML));
if (!TRUE.equals(splitHTML))
continue;
Object tmpVal = row.get(col);

View File

@ -63,7 +63,7 @@ public class JdbcDataSource extends
String bsz = initProps.getProperty("batchSize");
if (bsz != null) {
bsz = context.getVariableResolver().replaceTokens(bsz);
bsz = context.replaceTokens(bsz);
try {
batchSize = Integer.parseInt(bsz);
if (batchSize == -1)
@ -97,8 +97,8 @@ public class JdbcDataSource extends
protected Callable<Connection> createConnectionFactory(final Context context,
final Properties initProps) {
final VariableResolver resolver = context.getVariableResolver();
resolveVariables(resolver, initProps);
// final VariableResolver resolver = context.getVariableResolver();
resolveVariables(context, initProps);
final String jndiName = initProps.getProperty(JNDI_NAME);
final String url = initProps.getProperty(URL);
final String driver = initProps.getProperty(DRIVER);
@ -127,7 +127,7 @@ public class JdbcDataSource extends
return factory = new Callable<Connection>() {
public Connection call() throws Exception {
// Resolve variables again because the variables may have changed
resolveVariables(resolver, initProps);
resolveVariables(context, initProps);
LOG.info("Creating a connection for entity "
+ context.getEntityAttribute(DataImporter.NAME) + " with URL: "
+ url);
@ -198,10 +198,10 @@ public class JdbcDataSource extends
};
}
private void resolveVariables(VariableResolver resolver, Properties initProps) {
private void resolveVariables(Context ctx, Properties initProps) {
for (Map.Entry<Object, Object> entry : initProps.entrySet()) {
if (entry.getValue() != null) {
entry.setValue(resolver.replaceTokens((String) entry.getValue()));
entry.setValue(ctx.replaceTokens((String) entry.getValue()));
}
}
}

View File

@ -35,28 +35,27 @@ import java.util.Map;
public class LogTransformer extends Transformer {
Logger LOG = LoggerFactory.getLogger(LogTransformer.class);
public Object transformRow(Map<String, Object> row, Context context) {
VariableResolver vr = context.getVariableResolver();
String expr = context.getEntityAttribute(LOG_TEMPLATE);
String level = vr.replaceTokens(context.getEntityAttribute(LOG_LEVEL));
public Object transformRow(Map<String, Object> row, Context ctx) {
String expr = ctx.getEntityAttribute(LOG_TEMPLATE);
String level = ctx.replaceTokens(ctx.getEntityAttribute(LOG_LEVEL));
if (expr == null || level == null) return row;
if ("info".equals(level)) {
if (LOG.isInfoEnabled())
LOG.info(vr.replaceTokens(expr));
LOG.info(ctx.replaceTokens(expr));
} else if ("trace".equals(level)) {
if (LOG.isTraceEnabled())
LOG.trace(vr.replaceTokens(expr));
LOG.trace(ctx.replaceTokens(expr));
} else if ("warn".equals(level)) {
if (LOG.isWarnEnabled())
LOG.warn(vr.replaceTokens(expr));
LOG.warn(ctx.replaceTokens(expr));
} else if ("error".equals(level)) {
if (LOG.isErrorEnabled())
LOG.error(vr.replaceTokens(expr));
LOG.error(ctx.replaceTokens(expr));
} else if ("debug".equals(level)) {
if (LOG.isDebugEnabled())
LOG.debug(vr.replaceTokens(expr));
LOG.debug(ctx.replaceTokens(expr));
}
return row;

View File

@ -51,14 +51,13 @@ public class NumberFormatTransformer extends Transformer {
@SuppressWarnings("unchecked")
public Object transformRow(Map<String, Object> row, Context context) {
VariableResolver resolver = context.getVariableResolver();
for (Map<String, String> fld : context.getAllEntityFields()) {
String style = resolver.replaceTokens(fld.get(FORMAT_STYLE));
String style = context.replaceTokens(fld.get(FORMAT_STYLE));
if (style != null) {
String column = fld.get(DataImporter.COLUMN);
String srcCol = fld.get(RegexTransformer.SRC_COL_NAME);
Locale locale = null;
String localeStr = resolver.replaceTokens(fld.get(LOCALE));
String localeStr = context.replaceTokens(fld.get(LOCALE));
if (srcCol == null)
srcCol = column;
if (localeStr != null) {

View File

@ -47,7 +47,7 @@ public class PlainTextEntityProcessor extends EntityProcessorBase {
public Map<String, Object> nextRow() {
if (ended) return null;
DataSource<Reader> ds = context.getDataSource();
String url = context.getVariableResolver().replaceTokens(context.getEntityAttribute(URL));
String url = context.replaceTokens(context.getEntityAttribute(URL));
Reader r = null;
try {
r = ds.getData(url);

View File

@ -68,7 +68,7 @@ public class SqlEntityProcessor extends EntityProcessorBase {
public Map<String, Object> nextRow() {
if (rowIterator == null) {
String q = getQuery();
initQuery(resolver.replaceTokens(q));
initQuery(context.replaceTokens(q));
}
return getNext();
}
@ -78,7 +78,7 @@ public class SqlEntityProcessor extends EntityProcessorBase {
String deltaQuery = context.getEntityAttribute(DELTA_QUERY);
if (deltaQuery == null)
return null;
initQuery(resolver.replaceTokens(deltaQuery));
initQuery(context.replaceTokens(deltaQuery));
}
return getNext();
}
@ -88,7 +88,7 @@ public class SqlEntityProcessor extends EntityProcessorBase {
String deletedPkQuery = context.getEntityAttribute(DEL_PK_QUERY);
if (deletedPkQuery == null)
return null;
initQuery(resolver.replaceTokens(deletedPkQuery));
initQuery(context.replaceTokens(deletedPkQuery));
}
return getNext();
}
@ -100,7 +100,7 @@ public class SqlEntityProcessor extends EntityProcessorBase {
return null;
LOG.info("Running parentDeltaQuery for Entity: "
+ context.getEntityAttribute("name"));
initQuery(resolver.replaceTokens(parentDeltaQuery));
initQuery(context.replaceTokens(parentDeltaQuery));
}
return getNext();
}
@ -132,11 +132,11 @@ public class SqlEntityProcessor extends EntityProcessorBase {
sb.append(" and ");
}
first = false;
Object val = resolver.resolve("dataimporter.delta." + primaryKey);
Object val = context.resolve("dataimporter.delta." + primaryKey);
if (val == null) {
Matcher m = DOT_PATTERN.matcher(primaryKey);
if (m.find()) {
val = resolver.resolve("dataimporter.delta." + m.group(1));
val = context.resolve("dataimporter.delta." + m.group(1));
}
}
sb.append(primaryKey).append(" = ");

View File

@ -126,7 +126,7 @@ public class URLDataSource extends DataSource<Reader> {
if (expr == null) {
return null;
}
return context.getVariableResolver().replaceTokens(expr);
return context.replaceTokens(expr);
}
private static final Pattern URIMETHOD = Pattern.compile("\\w{3,}:/");

View File

@ -104,7 +104,7 @@ public class XPathEntityProcessor extends EntityProcessorBase {
}
String xslt = context.getEntityAttribute(XSL);
if (xslt != null) {
xslt = resolver.replaceTokens(xslt);
xslt = context.replaceTokens(xslt);
try {
Source xsltSource = new StreamSource(xslt);
// create an instance of TransformerFactory
@ -141,7 +141,7 @@ public class XPathEntityProcessor extends EntityProcessorBase {
flags = XPathRecordReader.FLATTEN;
}
String xpath = field.get(XPATH);
xpath = resolver.replaceTokens(xpath);
xpath = context.replaceTokens(xpath);
xpathReader.addField(field.get(DataImporter.COLUMN),
xpath,
Boolean.parseBoolean(field.get(DataImporter.MULTI_VALUED)),
@ -198,7 +198,7 @@ public class XPathEntityProcessor extends EntityProcessorBase {
Map<String, Object> r = null;
while (true) {
if (rowIterator == null)
initQuery(resolver.replaceTokens(context.getEntityAttribute(URL)));
initQuery(context.replaceTokens(context.getEntityAttribute(URL)));
r = getNext();
if (r == null) {
Object hasMore = context.getSessionAttribute(HAS_MORE, Context.SCOPE_ENTITY);
@ -208,7 +208,7 @@ public class XPathEntityProcessor extends EntityProcessorBase {
if (url == null)
url = context.getEntityAttribute(URL);
addNamespace();
initQuery(resolver.replaceTokens(url));
initQuery(context.replaceTokens(url));
r = getNext();
if (r == null)
return null;
@ -236,8 +236,7 @@ public class XPathEntityProcessor extends EntityProcessorBase {
Object val = context.getSessionAttribute(name, Context.SCOPE_ENTITY);
if (val != null) namespace.put(name, val);
}
resolver.addNamespace(entityName, namespace);
((VariableResolverImpl)context.getVariableResolver()).addNamespace(entityName, namespace);
}
private void addCommonFields(Map<String, Object> r) {