@Test public void testExecuteForPeopleAccountIdsWithNoInputs() { GetIdsFromPointersDbMapper<String> sut = new GetIdsFromPointersDbMapper<String>("accountId", Person.class); sut.setEntityManager(getEntityManager()); assertEquals(0, sut.execute(new ArrayList<String>()).size()); }
@Override public List<Long> execute(final List<PointerType> inPointerValues) { if (inPointerValues == null || inPointerValues.isEmpty()) { return new ArrayList<Long>(); } Criteria criteria = getHibernateSession().createCriteria(entityClass); ProjectionList fields = Projections.projectionList(); fields.add(Projections.property(pointerFieldName).as("key")); fields.add(Projections.property("id").as("itemId")); criteria.setProjection(fields); Criterion restriction = null; for (PointerType pointer : inPointerValues) { if (restriction == null) { restriction = Restrictions.eq(pointerFieldName, pointer); } else { restriction = Restrictions.or(Restrictions.eq(pointerFieldName, pointer), restriction); } } criteria.add(restriction); List<Object[]> dbResults = criteria.list(); Map<PointerType, Long> dbIndex = new HashMap<PointerType, Long>(); for (Object[] row : dbResults) { dbIndex.put((PointerType) row[0], (Long) row[1]); } List<Long> results = new ArrayList<Long>(inPointerValues.size()); for (PointerType key : inPointerValues) { results.add(dbIndex.get(key)); } return results; }
GetIdsFromPointersDbMapper extends BaseArgDomainMapper<List<PointerType>, List<Long>> { @Override public List<Long> execute(final List<PointerType> inPointerValues) { if (inPointerValues == null || inPointerValues.isEmpty()) { return new ArrayList<Long>(); } Criteria criteria = getHibernateSession().createCriteria(entityClass); ProjectionList fields = Projections.projectionList(); fields.add(Projections.property(pointerFieldName).as("key")); fields.add(Projections.property("id").as("itemId")); criteria.setProjection(fields); Criterion restriction = null; for (PointerType pointer : inPointerValues) { if (restriction == null) { restriction = Restrictions.eq(pointerFieldName, pointer); } else { restriction = Restrictions.or(Restrictions.eq(pointerFieldName, pointer), restriction); } } criteria.add(restriction); List<Object[]> dbResults = criteria.list(); Map<PointerType, Long> dbIndex = new HashMap<PointerType, Long>(); for (Object[] row : dbResults) { dbIndex.put((PointerType) row[0], (Long) row[1]); } List<Long> results = new ArrayList<Long>(inPointerValues.size()); for (PointerType key : inPointerValues) { results.add(dbIndex.get(key)); } return results; } }
GetIdsFromPointersDbMapper extends BaseArgDomainMapper<List<PointerType>, List<Long>> { @Override public List<Long> execute(final List<PointerType> inPointerValues) { if (inPointerValues == null || inPointerValues.isEmpty()) { return new ArrayList<Long>(); } Criteria criteria = getHibernateSession().createCriteria(entityClass); ProjectionList fields = Projections.projectionList(); fields.add(Projections.property(pointerFieldName).as("key")); fields.add(Projections.property("id").as("itemId")); criteria.setProjection(fields); Criterion restriction = null; for (PointerType pointer : inPointerValues) { if (restriction == null) { restriction = Restrictions.eq(pointerFieldName, pointer); } else { restriction = Restrictions.or(Restrictions.eq(pointerFieldName, pointer), restriction); } } criteria.add(restriction); List<Object[]> dbResults = criteria.list(); Map<PointerType, Long> dbIndex = new HashMap<PointerType, Long>(); for (Object[] row : dbResults) { dbIndex.put((PointerType) row[0], (Long) row[1]); } List<Long> results = new ArrayList<Long>(inPointerValues.size()); for (PointerType key : inPointerValues) { results.add(dbIndex.get(key)); } return results; } GetIdsFromPointersDbMapper(final String inPointerFieldName, final Class< ? > inEntityClass); }
GetIdsFromPointersDbMapper extends BaseArgDomainMapper<List<PointerType>, List<Long>> { @Override public List<Long> execute(final List<PointerType> inPointerValues) { if (inPointerValues == null || inPointerValues.isEmpty()) { return new ArrayList<Long>(); } Criteria criteria = getHibernateSession().createCriteria(entityClass); ProjectionList fields = Projections.projectionList(); fields.add(Projections.property(pointerFieldName).as("key")); fields.add(Projections.property("id").as("itemId")); criteria.setProjection(fields); Criterion restriction = null; for (PointerType pointer : inPointerValues) { if (restriction == null) { restriction = Restrictions.eq(pointerFieldName, pointer); } else { restriction = Restrictions.or(Restrictions.eq(pointerFieldName, pointer), restriction); } } criteria.add(restriction); List<Object[]> dbResults = criteria.list(); Map<PointerType, Long> dbIndex = new HashMap<PointerType, Long>(); for (Object[] row : dbResults) { dbIndex.put((PointerType) row[0], (Long) row[1]); } List<Long> results = new ArrayList<Long>(inPointerValues.size()); for (PointerType key : inPointerValues) { results.add(dbIndex.get(key)); } return results; } GetIdsFromPointersDbMapper(final String inPointerFieldName, final Class< ? > inEntityClass); @Override List<Long> execute(final List<PointerType> inPointerValues); }
GetIdsFromPointersDbMapper extends BaseArgDomainMapper<List<PointerType>, List<Long>> { @Override public List<Long> execute(final List<PointerType> inPointerValues) { if (inPointerValues == null || inPointerValues.isEmpty()) { return new ArrayList<Long>(); } Criteria criteria = getHibernateSession().createCriteria(entityClass); ProjectionList fields = Projections.projectionList(); fields.add(Projections.property(pointerFieldName).as("key")); fields.add(Projections.property("id").as("itemId")); criteria.setProjection(fields); Criterion restriction = null; for (PointerType pointer : inPointerValues) { if (restriction == null) { restriction = Restrictions.eq(pointerFieldName, pointer); } else { restriction = Restrictions.or(Restrictions.eq(pointerFieldName, pointer), restriction); } } criteria.add(restriction); List<Object[]> dbResults = criteria.list(); Map<PointerType, Long> dbIndex = new HashMap<PointerType, Long>(); for (Object[] row : dbResults) { dbIndex.put((PointerType) row[0], (Long) row[1]); } List<Long> results = new ArrayList<Long>(inPointerValues.size()); for (PointerType key : inPointerValues) { results.add(dbIndex.get(key)); } return results; } GetIdsFromPointersDbMapper(final String inPointerFieldName, final Class< ? > inEntityClass); @Override List<Long> execute(final List<PointerType> inPointerValues);  }