Source:
private <T extends Item> Collection<T> executeQuery(final AttributeQuery query, final Class<T> itemClass) { final ItemConfiguration itemConfiguration = getItemConfiguration(itemClass); final String tableName = databaseSchemaHolder.schemaName() + "." + itemConfiguration.tableName(); final Table table = dynamoDBClient.getTable(tableName); final List<T> totalItems = new ArrayList<>(); if (itemConfiguration.hasIndexOn(query.getAttributeName()) && query.getCondition().getComparisonOperator().equals(Operators.EQUALS)) { final Index index = table.getIndex(query.getAttributeName() + "_idx"); final QuerySpec querySpec = generateQuerySpec(query); final ItemCollection<QueryOutcome> queryOutcome = index.query(querySpec); final Iterator<com.amazonaws.services.dynamodbv2.document.Item> iterator = queryOutcome.iterator(); while (iterator.hasNext()) { final com.amazonaws.services.dynamodbv2.document.Item item = iterator.next(); totalItems.add(stringToItem(item.toJSON(), itemClass)); } } else { logger.debug("Performing table scan"); ScanSpec scanSpec = null; try { scanSpec = generateScanSpec(query, itemClass); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new PersistenceResourceFailureException("Could not create ScanSpec for query: " + query, e); } final ItemCollection<ScanOutcome> scanOutcome = table.scan(scanSpec); final Iterator<com.amazonaws.services.dynamodbv2.document.Item> iterator = scanOutcome.iterator(); while (iterator.hasNext()) { final com.amazonaws.services.dynamodbv2.document.Item item = iterator.next(); totalItems.add(stringToItem(item.toJSON(), itemClass)); } } return totalItems; }

Target:
private <T extends Item> Collection<T> executeQuery(final AttributeQuery query, final Class<T> itemClass) { final ItemConfiguration itemConfiguration = getItemConfiguration(itemClass); final String tableName = databaseSchemaHolder.schemaName() + "." + itemConfiguration.tableName(); final Table table = dynamoDBClient.getTable(tableName); final List<T> totalItems = new ArrayList<>(); if (itemConfiguration.hasIndexOn(query.getAttributeName()) && query.getCondition().getComparisonOperator().equals(Operators.EQUALS)) { final Index index = table.getIndex(query.getAttributeName() + "_idx"); final QuerySpec querySpec = generateQuerySpec(query); final ItemCollection<QueryOutcome> queryOutcome = index.query(querySpec); final Iterator<com.amazonaws.services.dynamodbv2.document.Item> iterator = queryOutcome.iterator(); while (iterator.hasNext()) { final com.amazonaws.services.dynamodbv2.document.Item item = iterator.next(); totalItems.add(stringToItem(item.toJSON(), itemClass)); } } else { logger.debug("Performing table scan with query: " + query); ScanSpec scanSpec = null; try { scanSpec = generateScanSpec(query, itemClass); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new PersistenceResourceFailureException("Could not create ScanSpec for query: " + query, e); } final ItemCollection<ScanOutcome> scanOutcome = table.scan(scanSpec); final Iterator<com.amazonaws.services.dynamodbv2.document.Item> iterator = scanOutcome.iterator(); while (iterator.hasNext()) { final com.amazonaws.services.dynamodbv2.document.Item item = iterator.next(); totalItems.add(stringToItem(item.toJSON(), itemClass)); } } return totalItems; }