@Test @SuppressWarnings("unchecked") public void testTransformList() { List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>(); maps.add(buildMap(Person.class, 3L)); maps.add(buildMap(DomainGroup.class, 9L)); maps.add(buildMap(Person.class, 1L)); maps.add(buildMap(DomainGroup.class, 1L)); final ModelView person2 = buildModelView(new PersonModelView(), 3L); final ModelView group4 = buildModelView(new DomainGroupModelView(), 9L); final ModelView person5 = buildModelView(new PersonModelView(), 1L); final ModelView group7 = buildModelView(new DomainGroupModelView(), 1L); final List<Long> expectedGroupIdList = new ArrayList<Long>(); expectedGroupIdList.add(9L); expectedGroupIdList.add(1L); final List<ModelView> returnedGroupModelViews = new ArrayList<ModelView>(); returnedGroupModelViews.add(group7); returnedGroupModelViews.add(group4); final List<Long> expectedPersonIdList = new ArrayList<Long>(); expectedPersonIdList.add(3L); expectedPersonIdList.add(1L); final List<ModelView> returnedpersonModelViews = new ArrayList<ModelView>(); returnedpersonModelViews.add(person2); returnedpersonModelViews.add(person5); context.checking(new Expectations() { { oneOf(getDomainGroupsByIdsMapperMock).execute(expectedGroupIdList); will(returnValue(returnedGroupModelViews)); oneOf(getPeopleByIdsMapperMock).execute(expectedPersonIdList); will(returnValue(returnedpersonModelViews)); } }); CachedModelViewResultTransformer sut = new CachedModelViewResultTransformer(); sut.setGetDomainGroupsByIdsMapper(getDomainGroupsByIdsMapperMock); sut.setGetPeopleByIdsMapper(getPeopleByIdsMapperMock); List results = sut.transformList(maps); assertEquals(maps.size(), results.size()); assertSame(person2, results.get(0)); assertSame(group4, results.get(1)); assertSame(person5, results.get(2)); assertSame(group7, results.get(3)); context.assertIsSatisfied(); }
@Override @SuppressWarnings("unchecked") public List transformList(final List inCollection) { log.trace("transformList."); Map<String, Integer> positionList = new HashMap<String, Integer>(); List<Long> groupIds = new ArrayList<Long>(); List<Long> peopleIds = new ArrayList<Long>(); int listPos = 0; for (Object mapObj : inCollection) { Map<String, Object> map = (Map<String, Object>) mapObj; Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); if (clazz == DomainGroup.class) { groupIds.add(entityId); positionList.put("G" + entityId, listPos); listPos++; } else if (clazz == Person.class) { peopleIds.add(entityId); positionList.put("P" + entityId, listPos); listPos++; } } ModelView[] results = new ModelView[inCollection.size()]; if (groupIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for Groups:" + groupIds.toString()); } for (ModelView group : getDomainGroupsByIdsMapper.execute(groupIds)) { results[positionList.get("G" + group.getEntityId())] = group; } } if (peopleIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for People:" + peopleIds.toString()); } for (ModelView person : getPeopleByIdsMapper.execute(peopleIds)) { results[positionList.get("P" + person.getEntityId())] = person; } } ArrayList<ModelView> returnList = new ArrayList<ModelView>(); int arraySize = results.length; for (int i = 0; i < arraySize; i++) { if (results[i] != null) { returnList.add(results[i]); } else { Map<String, Object> map = (Map<String, Object>) inCollection.get(i); Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); log.warn("Null entry in transformed list discarded. Index " + i + " contained an entry of type " + clazz.getName() + " with id " + entityId + ". Possible duplicate or unhandled entity type "); } } return returnList; }
CachedModelViewResultTransformer implements ResultTransformer { @Override @SuppressWarnings("unchecked") public List transformList(final List inCollection) { log.trace("transformList."); Map<String, Integer> positionList = new HashMap<String, Integer>(); List<Long> groupIds = new ArrayList<Long>(); List<Long> peopleIds = new ArrayList<Long>(); int listPos = 0; for (Object mapObj : inCollection) { Map<String, Object> map = (Map<String, Object>) mapObj; Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); if (clazz == DomainGroup.class) { groupIds.add(entityId); positionList.put("G" + entityId, listPos); listPos++; } else if (clazz == Person.class) { peopleIds.add(entityId); positionList.put("P" + entityId, listPos); listPos++; } } ModelView[] results = new ModelView[inCollection.size()]; if (groupIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for Groups:" + groupIds.toString()); } for (ModelView group : getDomainGroupsByIdsMapper.execute(groupIds)) { results[positionList.get("G" + group.getEntityId())] = group; } } if (peopleIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for People:" + peopleIds.toString()); } for (ModelView person : getPeopleByIdsMapper.execute(peopleIds)) { results[positionList.get("P" + person.getEntityId())] = person; } } ArrayList<ModelView> returnList = new ArrayList<ModelView>(); int arraySize = results.length; for (int i = 0; i < arraySize; i++) { if (results[i] != null) { returnList.add(results[i]); } else { Map<String, Object> map = (Map<String, Object>) inCollection.get(i); Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); log.warn("Null entry in transformed list discarded. Index " + i + " contained an entry of type " + clazz.getName() + " with id " + entityId + ". Possible duplicate or unhandled entity type "); } } return returnList; } }
CachedModelViewResultTransformer implements ResultTransformer { @Override @SuppressWarnings("unchecked") public List transformList(final List inCollection) { log.trace("transformList."); Map<String, Integer> positionList = new HashMap<String, Integer>(); List<Long> groupIds = new ArrayList<Long>(); List<Long> peopleIds = new ArrayList<Long>(); int listPos = 0; for (Object mapObj : inCollection) { Map<String, Object> map = (Map<String, Object>) mapObj; Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); if (clazz == DomainGroup.class) { groupIds.add(entityId); positionList.put("G" + entityId, listPos); listPos++; } else if (clazz == Person.class) { peopleIds.add(entityId); positionList.put("P" + entityId, listPos); listPos++; } } ModelView[] results = new ModelView[inCollection.size()]; if (groupIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for Groups:" + groupIds.toString()); } for (ModelView group : getDomainGroupsByIdsMapper.execute(groupIds)) { results[positionList.get("G" + group.getEntityId())] = group; } } if (peopleIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for People:" + peopleIds.toString()); } for (ModelView person : getPeopleByIdsMapper.execute(peopleIds)) { results[positionList.get("P" + person.getEntityId())] = person; } } ArrayList<ModelView> returnList = new ArrayList<ModelView>(); int arraySize = results.length; for (int i = 0; i < arraySize; i++) { if (results[i] != null) { returnList.add(results[i]); } else { Map<String, Object> map = (Map<String, Object>) inCollection.get(i); Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); log.warn("Null entry in transformed list discarded. Index " + i + " contained an entry of type " + clazz.getName() + " with id " + entityId + ". Possible duplicate or unhandled entity type "); } } return returnList; }  }
CachedModelViewResultTransformer implements ResultTransformer { @Override @SuppressWarnings("unchecked") public List transformList(final List inCollection) { log.trace("transformList."); Map<String, Integer> positionList = new HashMap<String, Integer>(); List<Long> groupIds = new ArrayList<Long>(); List<Long> peopleIds = new ArrayList<Long>(); int listPos = 0; for (Object mapObj : inCollection) { Map<String, Object> map = (Map<String, Object>) mapObj; Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); if (clazz == DomainGroup.class) { groupIds.add(entityId); positionList.put("G" + entityId, listPos); listPos++; } else if (clazz == Person.class) { peopleIds.add(entityId); positionList.put("P" + entityId, listPos); listPos++; } } ModelView[] results = new ModelView[inCollection.size()]; if (groupIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for Groups:" + groupIds.toString()); } for (ModelView group : getDomainGroupsByIdsMapper.execute(groupIds)) { results[positionList.get("G" + group.getEntityId())] = group; } } if (peopleIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for People:" + peopleIds.toString()); } for (ModelView person : getPeopleByIdsMapper.execute(peopleIds)) { results[positionList.get("P" + person.getEntityId())] = person; } } ArrayList<ModelView> returnList = new ArrayList<ModelView>(); int arraySize = results.length; for (int i = 0; i < arraySize; i++) { if (results[i] != null) { returnList.add(results[i]); } else { Map<String, Object> map = (Map<String, Object>) inCollection.get(i); Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); log.warn("Null entry in transformed list discarded. Index " + i + " contained an entry of type " + clazz.getName() + " with id " + entityId + ". Possible duplicate or unhandled entity type "); } } return returnList; }  @Override @SuppressWarnings("unchecked") List transformList(final List inCollection); @Override Object transformTuple(final Object[] inTuple, final String[] inAliases); void setGetDomainGroupsByIdsMapper(
            final DomainMapper<List<Long>, List<DomainGroupModelView>> inGetDomainGroupsByIdsMapper); void setGetPeopleByIdsMapper(final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleByIdsMapper); }
CachedModelViewResultTransformer implements ResultTransformer { @Override @SuppressWarnings("unchecked") public List transformList(final List inCollection) { log.trace("transformList."); Map<String, Integer> positionList = new HashMap<String, Integer>(); List<Long> groupIds = new ArrayList<Long>(); List<Long> peopleIds = new ArrayList<Long>(); int listPos = 0; for (Object mapObj : inCollection) { Map<String, Object> map = (Map<String, Object>) mapObj; Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); if (clazz == DomainGroup.class) { groupIds.add(entityId); positionList.put("G" + entityId, listPos); listPos++; } else if (clazz == Person.class) { peopleIds.add(entityId); positionList.put("P" + entityId, listPos); listPos++; } } ModelView[] results = new ModelView[inCollection.size()]; if (groupIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for Groups:" + groupIds.toString()); } for (ModelView group : getDomainGroupsByIdsMapper.execute(groupIds)) { results[positionList.get("G" + group.getEntityId())] = group; } } if (peopleIds.size() > 0) { if (log.isDebugEnabled()) { log.debug("Checking cache/db for People:" + peopleIds.toString()); } for (ModelView person : getPeopleByIdsMapper.execute(peopleIds)) { results[positionList.get("P" + person.getEntityId())] = person; } } ArrayList<ModelView> returnList = new ArrayList<ModelView>(); int arraySize = results.length; for (int i = 0; i < arraySize; i++) { if (results[i] != null) { returnList.add(results[i]); } else { Map<String, Object> map = (Map<String, Object>) inCollection.get(i); Class< ? > clazz = (Class< ? >) map.get(HIBERNATE_CLASS_PROPERTY_NAME); Long entityId = (Long) map.get(HIBERNATE_ID_PROPERTY_NAME); log.warn("Null entry in transformed list discarded. Index " + i + " contained an entry of type " + clazz.getName() + " with id " + entityId + ". Possible duplicate or unhandled entity type "); } } return returnList; }  @Override @SuppressWarnings("unchecked") List transformList(final List inCollection); @Override Object transformTuple(final Object[] inTuple, final String[] inAliases); void setGetDomainGroupsByIdsMapper(
            final DomainMapper<List<Long>, List<DomainGroupModelView>> inGetDomainGroupsByIdsMapper); void setGetPeopleByIdsMapper(final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleByIdsMapper);  }