@SuppressWarnings("unchecked") private void index( Object entity, Session session, InstanceInitializer sessionInitializer, ConversionContext conversionContext) throws InterruptedException { // abort if the thread has been interrupted while not in wait(), I/O or similar which themselves // would have // raised the InterruptedException if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } Serializable id = session.getIdentifier(entity); Class<?> clazz = HibernateHelper.getClass(entity); EntityIndexBinding entityIndexBinding = entityIndexBindings.get(clazz); if (entityIndexBinding == 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; } EntityIndexingInterceptor interceptor = entityIndexBinding.getEntityIndexingInterceptor(); if (interceptor != null) { IndexingOverride onAdd = interceptor.onAdd(entity); switch (onAdd) { case REMOVE: case SKIP: return; } // default: continue indexing this instance } DocumentBuilderIndexedEntity docBuilder = entityIndexBinding.getDocumentBuilder(); TwoWayFieldBridge idBridge = docBuilder.getIdBridge(); conversionContext.pushProperty(docBuilder.getIdKeywordName()); String idInString = null; try { idInString = conversionContext.setClass(clazz).twoWayConversionContext(idBridge).objectToString(id); } finally { conversionContext.popProperty(); } // 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( tenantId, clazz, entity, id, idInString, sessionInitializer, conversionContext); backend.enqueueAsyncWork(addWork); }
protected static boolean isIdNumeric(DocumentBuilderIndexedEntity<?> documentBuilder) { TwoWayFieldBridge idBridge = documentBuilder.getIdBridge(); return idBridge instanceof NumericFieldBridge; }