/** * We need to make a difference on which value is used as identifier * according to use case and mapping options * * @param work The work instance from which to extract the id * * @return the appropriate id to use for this work */ private Serializable extractProperId(Work work) { // see HSEARCH-662 if ( containedInOnly ) { return work.getId(); } Object entity = work.getEntity(); // 1) entity is null for purge operation, which requires to trust the work id // 2) types mapped as provided id require to use the work id // 3) when Hibernate identifier rollback is used && this identifier is our same id source, we need to get the value from work id if ( entity == null || documentBuilder.requiresProvidedId() || ( work.isIdentifierWasRolledBack() && documentBuilder.isIdMatchingJpaId() ) ) { return work.getId(); } else { return documentBuilder.getId( entity ); } }
/** * We need to make a difference on which value is used as identifier * according to use case and mapping options * * @param work The work instance from which to extract the id * * @return the appropriate id to use for this work */ private Serializable extractProperId(Work work) { // see HSEARCH-662 if ( containedInOnly ) { return work.getId(); } Object entity = work.getEntity(); // 1) entity is null for purge operation, which requires to trust the work id // 2) types mapped as provided id require to use the work id // 3) when Hibernate identifier rollback is used && this identifier is our same id source, we need to get the value from work id if ( entity == null || documentBuilder.requiresProvidedId() || ( work.isIdentifierWasRolledBack() && documentBuilder.isIdMatchingJpaId() ) ) { return work.getId(); } else { return documentBuilder.getId( entity ); } }
/** * Calculates the expect number of documents in the index by replaying * the work log, taking into account deletes, add and updates * * @return index size */ public int calculateIndexSize() { Set<Serializable> added = new HashSet<>(); for ( Work work : workLog ) { if ( work.getType().equals( DELETE ) ) { added.remove( work.getId() ); } else { added.add( work.getId() ); } } return added.size(); } }
public void workApplied(Work work) { workLog.add( work ); if ( work.getType().equals( ADD ) ) { lastAddedDocumentId = (Integer) work.getId(); } }
break; case UPDATE: result = new Work( work.getTenantIdentifier(), work.getEntity(), work.getId(), WorkType.UPDATE ); log.forceUpdateOnIndexOperationViaInterception( entityType, work.getType() ); break; result = new Work( work.getTenantIdentifier(), work.getEntity(), work.getId(), WorkType.DELETE, work.isIdentifierWasRolledBack() ); log.forceRemoveOnIndexOperationViaInterception( entityType, work.getType() ); break;
break; case UPDATE: result = new Work( work.getTenantIdentifier(), work.getEntity(), work.getId(), WorkType.UPDATE ); log.forceUpdateOnIndexOperationViaInterception( entityType, work.getType() ); break; result = new Work( work.getTenantIdentifier(), work.getEntity(), work.getId(), WorkType.DELETE, work.isIdentifierWasRolledBack() ); log.forceRemoveOnIndexOperationViaInterception( entityType, work.getType() ); break;