1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
public List<Map<String,String>> scan(String tableName,String filterColumn,String filterValue,String columns,String reservedKeyWordColumn){ List<Map<String,String>> list = new ArrayList<>(); Map<String, AttributeValue> expressionAttributeValues = new HashMap<>(); expressionAttributeValues.put(":val", new AttributeValue().withS(filterValue)); Map<String, String> expressionAttributeNames = new HashMap<>(); StringBuffer rColumns = new StringBuffer(""); if(StringUtils.isNotBlank(reservedKeyWordColumn)){ String[] rKeys = reservedKeyWordColumn.split(","); for(String rKey:rKeys){ expressionAttributeNames.put("#"+rKey,rKey); rColumns.append(","); rColumns.append("#"+rKey); } } String projections = columns + rColumns.toString(); ScanRequest scanRequest = new ScanRequest() .withTableName(tableName) .withFilterExpression(filterColumn+" = :val") .withProjectionExpression(projections) .withExpressionAttributeValues(expressionAttributeValues) .withLimit(50); if(expressionAttributeNames.size() > 0){ scanRequest.withExpressionAttributeNames(expressionAttributeNames); } ScanResult result = client.scan(scanRequest); String[] columnNames = columns.split(","); String[] rColumnNames = reservedKeyWordColumn.split(","); List<Map<String,String>> list1 = parseToList(result,columnNames,rColumnNames); list.addAll(list1); while (result.getLastEvaluatedKey()!=null){ scanRequest.setExclusiveStartKey(result.getLastEvaluatedKey()); result = client.scan(scanRequest); List<Map<String,String>> list2 = parseToList(result,columnNames,rColumnNames); list.addAll(list2); } return list; }
|