我們檢視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);
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;
public Map<String, Object> nextModifiedRowKey() {
Map<String, Object> row = delegate.nextModifiedRowKey();
row = applyTransformer(row);
rowcache = null;
return row;
public Map<String, Object> nextDeletedRowKey() {
Map<String, Object> row = delegate.nextDeletedRowKey();
public Map<String, Object> nextModifiedParentRowKey() {
return delegate.nextModifiedParentRowKey();
public void destroy() {
delegate.destroy();
public void close() {
delegate.close();
}