We noticed the initialization method of entityprocessorwrapper.
@ Override
Public void Init (context ){
Delegate. INIT (context );
}
Here context is the context object, and the data source is obtained through context. context is an abstract class.
Public abstract class context
{
Public abstract datasource getdatasource ();
Public abstract datasource getdatasource (string name );
Public abstract entityprocessor getentityprocessor ();
Public Abstract Boolean isrootentity ();
}
The inheritance class is contextimpl. Pay attention to the method for obtaining the data source and call the dataimporter object to obtain the data source. (dataimporter described earlier. Refer to SOLR dataimport source code Import Analysis (2 ), instantiate a new jdbcdatasource () object using the getperformanceinstance method)
Contextimpl. Java
Private datasource Ds;
Private dataimporter;
@ Override
Public datasource getdatasource (){
If (Ds! = NULL) return Ds;
If (entity = NULL) return NULL;
If (entity. datasrc = NULL ){
Entity. datasrc = dataimporter. getdatasourceinstance (entity, entity. datasource, this );
}
If (entity. datasrc! = NULL & docbuilder! = NULL & docbuilder. verbosedebug &&
Context. full_dump.equals (currentprocess ())){
// Debug is not yet implemented properly for Deltas
Entity. datasrc = docbuilder. getdebuglogger (). wrapds (entity. datasrc );
}
Return entity. datasrc;
}
Let's look at how docbuidler initializes the entityprocessorwrapper class
Docbuidler. Java
Private entityprocessorwrapper getentityprocessor (dataconfig. entity ){
If (entity. processor! = NULL)
Return entity. processor;
Entityprocessor = NULL;
If (entity. Proc = NULL ){
Entityprocessor = new sqlentityprocessor ();
} Else {
Try {
Entityprocessor = (entityprocessor) loadclass (entity. Proc, dataimporter. getcore ())
. Newinstance ();
} Catch (exception e ){
Wrapandthrow (severe, e,
"Unable to load entityprocessor implementation for entity:" + entity. Name );
}
}
Return entity. processor = new entityprocessorwrapper (entityprocessor, this );
}
The returned proxy class is entityprocessorwrapper. The proxy object is the sqlentityprocessor class by default.
In the builddocument method of docbuidler, construct and pass in the context object, that is, the contextimpl object (obtain the data source through contextimpl)
Private void builddocument (variableresolverimpl VR, docwrapper Doc,
Map <string, Object> PK, dataconfig. entity, Boolean isroot,
Contextimpl parentctx, list <entityprocessorwrapper> entitiestodestroy ){
Entityprocessorwrapper entityprocessor = getentityprocessor (entity );
Contextimpl CTX = new contextimpl (entity, VR, null,
PK = NULL? Context. full_dump: context. delta_dump,
Session, parentctx, this );
Entityprocessor. INIT (CTX );
// Other Code omitted
}
In the initialization method of sqlentityprocessor, call the datasource getdatasource () method of contextimpl to initialize the data source.
Sqlentityprocessor. Java
Protected datasource <iterator <Map <string, Object> datasource;
@ Override
@ Suppresswarnings ("unchecked ")
Public void Init (context ){
Super. INIT (context );
Datasource = context. getdatasource ();
}
The data query method is as follows. The parameter SQL statement is passed in to initialize the data iterator.
Protected void initquery (string q ){
Try {
Dataimporter. query_count.get (). incrementandget ();
Rowiterator = datasource. getdata (Q );
This. query = Q;
} Catch (dataimporthandlerexception e ){
Throw E;
} Catch (exception e ){
Log. Error ("the query failed '" + q + "'", e );
Throw new dataimporthandlerexception (dataimporthandlerexception. Severe, e );
}
}
You can call initquery (string q) to obtain the data iterator.
Finally, the docbuilder class is indirectly called by the packaging class entityprocessorwrapper.
Sqlentityprocessor all these import and incremental import methods get data construct solrinputdocument object