Skip to content

Commit

Permalink
#22 Use generic type in BatchItemProcessor
Browse files Browse the repository at this point in the history
Now the method buildAddLuceneWorks(List, Class<T>) is generic. This implementation done thanks to Stack Overflow. I've asked a question this morning : How to use generic type in a map? [duplicate] <http://stackoverflow.com/questions/37654228/how-to-use-generic-type-in-a-map>
  • Loading branch information
mincong-h committed Jun 6, 2016
1 parent 2a67c66 commit e4c9f04
Showing 1 changed file with 11 additions and 5 deletions.
Expand Up @@ -103,7 +103,7 @@ public Object processItem(Object item) throws Exception {
// get data directly from the database.
.setHint("javax.persistence.cache.retrieveMode", "BYPASS")
.getResultList();
addWorks = buildAddLuceneWorks(addresses);
addWorks = buildAddLuceneWorks(addresses, Address.class);
updateWorksCount(addWorks.size());

return addWorks;
Expand All @@ -127,23 +127,28 @@ private void updateWorksCount(int currentCount) {
* current mass indexer implementation.
*
* @param entities entities obtained from JPA entity manager
* @param classOfEntity the class type of selected entities
* @return a list of addLuceneWorks
*/
private <T> List<AddLuceneWork> buildAddLuceneWorks(List<T> entities) {
private <T> List<AddLuceneWork> buildAddLuceneWorks(List<T> entities,
Class<T> classOfEntity) {

List<AddLuceneWork> addWorks = new LinkedList<>();
String tenantId = null;

session = em.unwrap(Session.class);
searchIntegrator = ContextHelper.getSearchintegrator(session);
entityIndexBinding = searchIntegrator
.getIndexBindings()
.get(Address.class);
.get(classOfEntity);
shardingStrategy = entityIndexBinding.getSelectionStrategy();
indexingContext.setIndexShardingStrategy(shardingStrategy);
docBuilder = entityIndexBinding.getDocumentBuilder();
conversionContext = new ContextualExceptionBridgeHelper();
sessionInitializer = new HibernateSessionLoadingInitializer(
(SessionImplementor) session
);
String tenantId = null;
List<AddLuceneWork> addWorks = new LinkedList<>();

for (T entity: entities) {
Serializable id = session.getIdentifier(entity);
TwoWayFieldBridge idBridge = docBuilder.getIdBridge();
Expand All @@ -168,6 +173,7 @@ private <T> List<AddLuceneWork> buildAddLuceneWorks(List<T> entities) {
);
addWorks.add(addWork);
}

return addWorks;
}

Expand Down

0 comments on commit e4c9f04

Please sign in to comment.