@SuppressWarnings("unchecked")
private void index( Object entity, Session session, EntityInitializer sessionInitializer ) throws InterruptedException {
Serializable id = session.getIdentifier( entity );
Class<?> clazz = HibernateHelper.getClass( entity );
DocumentBuilderIndexedEntity docBuilder = documentBuilders.get( clazz );
if ( docBuilder == null ) {
// it might be possible to receive not-indexes subclasses of the currently indexed type;
// being not-indexed, we skip them.
// FIXME for improved performance: avoid loading them in an early phase.
return;
}
TwoWayFieldBridge idBridge = docBuilder.getIdBridge();
ContextualException2WayBridge contextualBridge = new ContextualException2WayBridge()
.setClass(clazz)
.setFieldName(docBuilder.getIdKeywordName())
.setFieldBridge(idBridge);
String idInString = contextualBridge.objectToString( id );
//depending on the complexity of the object graph going to be indexed it's possible
//that we hit the database several times during work construction.
AddLuceneWork addWork = docBuilder.createAddWork( clazz, entity, id, idInString, sessionInitializer, true );
backend.enqueueAsyncWork( addWork );
}