solr dataimport 数据导入源码分析(四)
2012-09-09 19:05
465 查看
我们查看DocBuilder类的源码发现,并不是直接持有对SqlEntityProcessor类的引用,而是另外一个包装类EntityProcessorWrapper,EntityProcessorWrapper直接继承自抽象类EntityProcessor,而不是继承自中间的EntityProcessorBase类,简要类图如下
包装类额外添加了缓存处理以及格式转换等功能,然后调用SqlEntityProcessor相应方法进行处理,相当于SqlEntityProcessor的代理类,共同继承自抽象类EntityProcessor(SqlEntityProcessor 是通过EntityProcessorBase 间接继承自EntityProcessor)
EntityProcessorWrapper类的简要代码如下
public class EntityProcessorWrapper extends EntityProcessor {
private static final Logger log = LoggerFactory.getLogger(EntityProcessorWrapper.class);
EntityProcessor delegate;
private DocBuilder docBuilder;
String onError;
Context context;
protected VariableResolverImpl resolver;
String entityName;
protected List<Transformer> transformers;
protected List<Map<String, Object>> rowcache;
public EntityProcessorWrapper(EntityProcessor delegate, DocBuilder docBuilder) {
this.delegate = delegate;
this.docBuilder = docBuilder;
}
@Override
public void init(Context context) {
delegate.init(context);
}
protected Map<String, Object> getFromRowCache() {
if (rowcache.isEmpty()){
return null;
}
return rowcache.remove(0);
}
@Override
public Map<String, Object> nextRow() {
pullRow();
}
protected Map<String,Object> pullRow() {
Map<String,Object> arow = null;
try {
arow = delegate.nextRow();
} catch (Exception e) {
if (ABORT.equals(onError)) {
wrapAndThrow(SEVERE, e);
} else {
// SKIP is not really possible. If this calls the nextRow() again the
// Entityprocessor would be in an inconistent state
log.error("Exception in entity : " + entityName, e);
return null;
}
}
log.debug("arow : {}", arow);
return arow;
}
@Override
public Map<String, Object> nextModifiedRowKey() {
Map<String, Object> row = delegate.nextModifiedRowKey();
row = applyTransformer(row);
rowcache = null;
return row;
}
@Override
public Map<String, Object> nextDeletedRowKey() {
Map<String, Object> row = delegate.nextDeletedRowKey();
row = applyTransformer(row);
rowcache = null;
return row;
}
@Override
public Map<String, Object> nextModifiedParentRowKey() {
return delegate.nextModifiedParentRowKey();
}
@Override
public void destroy() {
delegate.destroy();
}
@Override
public void close() {
delegate.close();
}
}
包装类额外添加了缓存处理以及格式转换等功能,然后调用SqlEntityProcessor相应方法进行处理,相当于SqlEntityProcessor的代理类,共同继承自抽象类EntityProcessor(SqlEntityProcessor 是通过EntityProcessorBase 间接继承自EntityProcessor)
EntityProcessorWrapper类的简要代码如下
public class EntityProcessorWrapper extends EntityProcessor {
private static final Logger log = LoggerFactory.getLogger(EntityProcessorWrapper.class);
EntityProcessor delegate;
private DocBuilder docBuilder;
String onError;
Context context;
protected VariableResolverImpl resolver;
String entityName;
protected List<Transformer> transformers;
protected List<Map<String, Object>> rowcache;
public EntityProcessorWrapper(EntityProcessor delegate, DocBuilder docBuilder) {
this.delegate = delegate;
this.docBuilder = docBuilder;
}
@Override
public void init(Context context) {
delegate.init(context);
}
protected Map<String, Object> getFromRowCache() {
if (rowcache.isEmpty()){
return null;
}
return rowcache.remove(0);
}
@Override
public Map<String, Object> nextRow() {
pullRow();
}
protected Map<String,Object> pullRow() {
Map<String,Object> arow = null;
try {
arow = delegate.nextRow();
} catch (Exception e) {
if (ABORT.equals(onError)) {
wrapAndThrow(SEVERE, e);
} else {
// SKIP is not really possible. If this calls the nextRow() again the
// Entityprocessor would be in an inconistent state
log.error("Exception in entity : " + entityName, e);
return null;
}
}
log.debug("arow : {}", arow);
return arow;
}
@Override
public Map<String, Object> nextModifiedRowKey() {
Map<String, Object> row = delegate.nextModifiedRowKey();
row = applyTransformer(row);
rowcache = null;
return row;
}
@Override
public Map<String, Object> nextDeletedRowKey() {
Map<String, Object> row = delegate.nextDeletedRowKey();
row = applyTransformer(row);
rowcache = null;
return row;
}
@Override
public Map<String, Object> nextModifiedParentRowKey() {
return delegate.nextModifiedParentRowKey();
}
@Override
public void destroy() {
delegate.destroy();
}
@Override
public void close() {
delegate.close();
}
}
相关文章推荐
- solr dataimport 数据导入源码分析 补充
- solr dataimport 数据导入源码分析(十二)
- solr dataimport 数据导入源码分析(五)
- solr dataimport 数据导入源码分析(六)
- solr dataimport 数据导入源码分析(一)
- solr dataimport 数据导入源码分析(十三)
- solr dataimport 数据导入源码分析(二)
- solr dataimport 数据导入源码分析(七)
- solr dataimport 数据导入源码分析(三)
- solr dataimport 数据导入源码分析(八)
- solr dataimport 数据导入源码分析(九)
- solr dataimport 数据导入源码分析(十四)
- solr dataimport 数据导入源码分析(十)总结
- Solr1.4.0源码分析(一) 解决DataImportHandler从数据库导入大量数据而内存溢出的问题
- 20161216-solr cloud 集群数据导入(dataimport)笔记
- Solr学习笔记之3、Solr dataimport - 从SQLServer导入数据建立索引
- Solr4:数据导入(dataimport)时,不符合Solr日期类型要求的字段的处理
- solr3.6数据导入DataImport实现
- Solr-5.3.1 dataimport 导入mysql数据
- dataserver 源码分析(三) 读写数据