Skip to content

Commit

Permalink
0.9.82
Browse files Browse the repository at this point in the history
  • Loading branch information
landawn committed Sep 9, 2017
1 parent b426256 commit d835b35
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 103 deletions.
Binary file modified lib/abacus-util-0.9.82.jar
Binary file not shown.
Binary file modified lib/abacus-util-all-0.9.82.jar
Binary file not shown.
Binary file modified lib/abacus-util-all-jdk7-0.9.82.jar
Binary file not shown.
Binary file modified lib/abacus-util-jdk7-0.9.82.jar
Binary file not shown.
220 changes: 124 additions & 96 deletions src/com/landawn/abacus/util/DynamoDBExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ static <T> T toValue(AttributeValue x) {
return (T) tmp;
} else if (N.notNullOrEmpty(x.getM())) {
final Map<String, AttributeValue> attrMap = x.getM();
final Map<String, Object> tmp = attrMap instanceof HashMap ? new HashMap<>(N.initHashCapacity(attrMap.size()))
: new LinkedHashMap<>(N.initHashCapacity(attrMap.size()));
final Map<String, Object> tmp = attrMap instanceof HashMap ? new HashMap<String, Object>(N.initHashCapacity(attrMap.size()))
: new LinkedHashMap<String, Object>(N.initHashCapacity(attrMap.size()));

for (Map.Entry<String, AttributeValue> entry : attrMap.entrySet()) {
tmp.put(entry.getKey(), toValue(entry.getValue()));
Expand Down Expand Up @@ -981,56 +981,70 @@ public List<Map<String, Object>> find(final QueryRequest queryRequest) {
* @return
*/
public <T> List<T> find(final Class<T> targetClass, final QueryRequest queryRequest) {
return find(targetClass, queryRequest, 0, Integer.MAX_VALUE);
}

/**
*
* @param targetClass <code>Map</code> or entity class with getter/setter method.
* @param queryRequest
* @param pageOffset
* @param pageCount
* @return
* @see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.Pagination">Query.Pagination</a>
*/
public <T> List<T> find(final Class<T> targetClass, final QueryRequest queryRequest, int pageOffset, int pageCount) {
N.checkArgument(pageOffset >= 0 && pageCount >= 0, "'pageOffset' and 'pageCount' can't be negative");

final List<T> res = new ArrayList<>();
QueryRequest newQueryRequest = queryRequest;
QueryResult queryResult = null;

do {
if (queryResult != null && N.notNullOrEmpty(queryResult.getLastEvaluatedKey())) {
if (newQueryRequest == queryRequest) {
newQueryRequest = queryRequest.clone();
}

newQueryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey());
}
final QueryResult queryResult = dynamoDB.query(queryRequest);
final List<T> res = toList(targetClass, queryResult);

queryResult = dynamoDB.query(newQueryRequest);
} while (pageOffset-- > 0 && N.notNullOrEmpty(queryResult.getItems()) && N.notNullOrEmpty(queryResult.getLastEvaluatedKey()));

if (pageOffset >= 0 || pageCount-- <= 0) {
return res;
} else {
res.addAll(toList(targetClass, queryResult));
}
if (N.notNullOrEmpty(queryResult.getLastEvaluatedKey()) && N.isNullOrEmpty(queryRequest.getExclusiveStartKey())) {
final QueryRequest newQueryRequest = queryRequest.clone();
QueryResult newQueryResult = queryResult;

while (pageCount-- > 0 && N.notNullOrEmpty(queryResult.getLastEvaluatedKey())) {
if (newQueryRequest == queryRequest) {
newQueryRequest = queryRequest.clone();
while (N.notNullOrEmpty(newQueryResult.getLastEvaluatedKey())) {
newQueryRequest.setExclusiveStartKey(newQueryResult.getLastEvaluatedKey());
newQueryResult = dynamoDB.query(newQueryRequest);
res.addAll(toList(targetClass, newQueryResult));
}

newQueryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey());
queryResult = dynamoDB.query(newQueryRequest);
res.addAll(toList(targetClass, queryResult));
}

return res;
}

// /**
// *
// * @param targetClass <code>Map</code> or entity class with getter/setter method.
// * @param queryRequest
// * @param pageOffset
// * @param pageCount
// * @return
// * @see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.Pagination">Query.Pagination</a>
// */
// public <T> List<T> find(final Class<T> targetClass, final QueryRequest queryRequest, int pageOffset, int pageCount) {
// N.checkArgument(pageOffset >= 0 && pageCount >= 0, "'pageOffset' and 'pageCount' can't be negative");
//
// final List<T> res = new ArrayList<>();
// QueryRequest newQueryRequest = queryRequest;
// QueryResult queryResult = null;
//
// do {
// if (queryResult != null && N.notNullOrEmpty(queryResult.getLastEvaluatedKey())) {
// if (newQueryRequest == queryRequest) {
// newQueryRequest = queryRequest.clone();
// }
//
// newQueryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey());
// }
//
// queryResult = dynamoDB.query(newQueryRequest);
// } while (pageOffset-- > 0 && N.notNullOrEmpty(queryResult.getItems()) && N.notNullOrEmpty(queryResult.getLastEvaluatedKey()));
//
// if (pageOffset >= 0 || pageCount-- <= 0) {
// return res;
// } else {
// res.addAll(toList(targetClass, queryResult));
// }
//
// while (pageCount-- > 0 && N.notNullOrEmpty(queryResult.getLastEvaluatedKey())) {
// if (newQueryRequest == queryRequest) {
// newQueryRequest = queryRequest.clone();
// }
//
// newQueryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey());
// queryResult = dynamoDB.query(newQueryRequest);
// res.addAll(toList(targetClass, queryResult));
// }
//
// return res;
// }

/**
*
* @param queryRequest
Expand All @@ -1049,21 +1063,21 @@ public DataSet query(final QueryRequest queryRequest) {
* @see #find(Class, QueryRequest)
*/
public DataSet query(final Class<?> targetClass, final QueryRequest queryRequest) {
return query(targetClass, queryRequest, 0, Integer.MAX_VALUE);
}

/**
*
* @param targetClass
* @param queryRequest
* @param pageOffset
* @param pageCount
* @return
* @see #find(Class, QueryRequest, int, int)
*/
public DataSet query(final Class<?> targetClass, final QueryRequest queryRequest, int pageOffset, int pageCount) {
return N.newDataSet(find(targetClass, queryRequest, pageOffset, pageCount));
}
return N.newDataSet(find(targetClass, queryRequest));
}

// /**
// *
// * @param targetClass
// * @param queryRequest
// * @param pageOffset
// * @param pageCount
// * @return
// * @see #find(Class, QueryRequest, int, int)
// */
// public DataSet query(final Class<?> targetClass, final QueryRequest queryRequest, int pageOffset, int pageCount) {
// return N.newDataSet(find(targetClass, queryRequest, pageOffset, pageCount));
// }

public DataSet scan(final String tableName, final List<String> attributesToGet) {
return scan(new ScanRequest().withTableName(tableName).withAttributesToGet(attributesToGet));
Expand All @@ -1078,12 +1092,12 @@ public DataSet scan(final String tableName, final List<String> attributesToGet,
}

public DataSet scan(final ScanRequest scanRequest) {
return scan(scanRequest, 0, Integer.MAX_VALUE);
return N.newDataSet(scan(Map.class, scanRequest));
}

public DataSet scan(final ScanRequest scanRequest, int pageOffset, int pageCount) {
return N.newDataSet(scan(Map.class, scanRequest, pageOffset, pageCount));
}
// public DataSet scan(final ScanRequest scanRequest, int pageOffset, int pageCount) {
// return N.newDataSet(scan(Map.class, scanRequest, pageOffset, pageCount));
// }

public <T> List<T> scan(final Class<T> targetClass, final String tableName, final List<String> attributesToGet) {
return scan(targetClass, new ScanRequest().withTableName(tableName).withAttributesToGet(attributesToGet));
Expand All @@ -1098,47 +1112,61 @@ public <T> List<T> scan(final Class<T> targetClass, final String tableName, fina
}

public <T> List<T> scan(final Class<T> targetClass, final ScanRequest scanRequest) {
return scan(targetClass, scanRequest, 0, Integer.MAX_VALUE);
}

public <T> List<T> scan(final Class<T> targetClass, final ScanRequest scanRequest, int pageOffset, int pageCount) {
N.checkArgument(pageOffset >= 0 && pageCount >= 0, "'pageOffset' and 'pageCount' can't be negative");
final ScanResult scanResult = dynamoDB.scan(scanRequest);
final List<T> res = toList(targetClass, scanResult);

final List<T> res = new ArrayList<>();
ScanRequest newQueryRequest = scanRequest;
ScanResult queryResult = null;
if (N.notNullOrEmpty(scanResult.getLastEvaluatedKey()) && N.isNullOrEmpty(scanRequest.getExclusiveStartKey())) {
final ScanRequest newScanRequest = scanRequest.clone();
ScanResult newScanResult = scanResult;

do {
if (queryResult != null && N.notNullOrEmpty(queryResult.getLastEvaluatedKey())) {
if (newQueryRequest == scanRequest) {
newQueryRequest = scanRequest.clone();
}

newQueryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey());
}

queryResult = dynamoDB.scan(newQueryRequest);
} while (pageOffset-- > 0 && N.notNullOrEmpty(queryResult.getItems()) && N.notNullOrEmpty(queryResult.getLastEvaluatedKey()));

if (pageOffset >= 0 || pageCount-- <= 0) {
return res;
} else {
res.addAll(toList(targetClass, queryResult));
}

while (pageCount-- > 0 && N.notNullOrEmpty(queryResult.getLastEvaluatedKey())) {
if (newQueryRequest == scanRequest) {
newQueryRequest = scanRequest.clone();
while (N.notNullOrEmpty(newScanResult.getLastEvaluatedKey())) {
newScanRequest.setExclusiveStartKey(newScanResult.getLastEvaluatedKey());
newScanResult = dynamoDB.scan(newScanRequest);
res.addAll(toList(targetClass, newScanResult));
}

newQueryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey());
queryResult = dynamoDB.scan(newQueryRequest);
res.addAll(toList(targetClass, queryResult));
}

return res;
}

// public <T> List<T> scan(final Class<T> targetClass, final ScanRequest scanRequest, int pageOffset, int pageCount) {
// N.checkArgument(pageOffset >= 0 && pageCount >= 0, "'pageOffset' and 'pageCount' can't be negative");
//
// final List<T> res = new ArrayList<>();
// ScanRequest newQueryRequest = scanRequest;
// ScanResult queryResult = null;
//
// do {
// if (queryResult != null && N.notNullOrEmpty(queryResult.getLastEvaluatedKey())) {
// if (newQueryRequest == scanRequest) {
// newQueryRequest = scanRequest.clone();
// }
//
// newQueryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey());
// }
//
// queryResult = dynamoDB.scan(newQueryRequest);
// } while (pageOffset-- > 0 && N.notNullOrEmpty(queryResult.getItems()) && N.notNullOrEmpty(queryResult.getLastEvaluatedKey()));
//
// if (pageOffset >= 0 || pageCount-- <= 0) {
// return res;
// } else {
// res.addAll(toList(targetClass, queryResult));
// }
//
// while (pageCount-- > 0 && N.notNullOrEmpty(queryResult.getLastEvaluatedKey())) {
// if (newQueryRequest == scanRequest) {
// newQueryRequest = scanRequest.clone();
// }
//
// newQueryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey());
// queryResult = dynamoDB.scan(newQueryRequest);
// res.addAll(toList(targetClass, queryResult));
// }
//
// return res;
// }

@Override
public void close() throws IOException {
dynamoDB.shutdown();
Expand Down
6 changes: 3 additions & 3 deletions src/com/landawn/abacus/util/Fn.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ private Fn() {
// Singleton.
}

// public static <T> T get(final Supplier<T> supplier) {
// return supplier.get();
// }
public static <T> T get(final Supplier<T> supplier) {
return supplier.get();
}

public static <T> Comparator<T> naturalOrder() {
return Comparators.naturalOrder();
Expand Down
22 changes: 18 additions & 4 deletions src/com/landawn/abacus/util/stream/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -8230,12 +8230,26 @@ public static enum SOO {
*
*/
public static enum PSO {
MAP, BI_MAP, TRI_MAP, SLIDING_MAP, MAP_TO_, FLAT_MAP, FLAT_MAP_TO_, REDUCE, COLLECT, //
MIN, MAX, SUM_INT, SUM_LONG, SUM_DOUBLE, AVERAGE_INT, AVERAGE_LONG, AVERAGE_DOUBLE, SUMMARIZE_, //
GROUP_BY, GROUP_BY_2, GROUP_BY_TO_ENTRY, PARTITION_BY, PARTITION_BY_TO_ENTRY, TO_MAP, TO_MAP_2, TO_MULTIMAP, //
MAP, BI_MAP, TRI_MAP, SLIDING_MAP, MAP_TO_ENTRY, MAP_TO_, MAP_FIRST, MAP_FIRST_, MAP_LAST, MAP_LAST_, RANGE_MAP, //
FLAT_MAP, FLAT_MAP_TO_, FLAT_ARRAY, FLAT_COLLECION, //
FILTER, TAKE_WHILE, DROP_WHILE, REMOVE, REMOVE_IF, REMOVE_WHILE, SKIP_NULL, //
SPLIT_BY, SORTED, REVERSE_SORTED, DISTINCT_BY, JOIN, PEEK, //
GROUP_BY, GROUP_BY_TO_ENTRY, PARTITION_BY, PARTITION_BY_TO_ENTRY, GROUP_TO, TO_MAP, TO_MULTIMAP, //
MIN, MAX, SUM_INT, SUM_LONG, SUM_DOUBLE, AVERAGE_INT, AVERAGE_LONG, AVERAGE_DOUBLE, SUMMARIZE_, //
FOR_EACH, FOR_EACH_PAIR, FOR_EACH_TRIPLE, ANY_MATCH, ALL_MATCH, NONE_MATCH, FIND_FIRST, FIND_LAST, //
PERSIST_DB;
REDUCE, COLLECT, PERSIST_DB;
}

/**
* LAIO = Loading All Intermediate Operations.
*
* Intermediate operations which will load or go through all the elements in the stream.
*
* @author haiyangl
*
*/
public static enum LAIO {
SORTED, SORTED_BY, REVERSE_SORTED, CACHED, REVERSED, SHUFFLED, ROTATED, //
GROUP_BY, GROUP_BY_TO_ENTRY, PARTITION_BY, PARTITION_BY_TO_ENTRY;
}
}

0 comments on commit d835b35

Please sign in to comment.