Example usage for com.amazonaws.services.simpledb.model SelectRequest setSelectExpression

List of usage examples for com.amazonaws.services.simpledb.model SelectRequest setSelectExpression

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb.model SelectRequest setSelectExpression.

Prototype


public void setSelectExpression(String selectExpression) 

Source Link

Document

The expression used to query the domain.

Usage

From source file:squash.booking.lambdas.core.OptimisticPersister.java

License:Apache License

@Override
public List<ImmutablePair<String, List<Attribute>>> getAllItems() {

    if (!initialised) {
        throw new IllegalStateException("The optimistic persister has not been initialised");
    }/* w w  w . j a va2s.  c o m*/

    // Query database to get items
    List<ImmutablePair<String, List<Attribute>>> items = new ArrayList<>();
    AmazonSimpleDB client = getSimpleDBClient();

    SelectRequest selectRequest = new SelectRequest();
    // N.B. Think if results are paged, second and subsequent pages will always
    // be eventually-consistent only. This is currently used only to back up the
    // database - so being eventually-consistent is good enough - after all -
    // even if we were fully consistent, someone could still add a new booking
    // right after our call anyway.
    selectRequest.setConsistentRead(true);
    // Query all items in the domain
    selectRequest.setSelectExpression("select * from `" + simpleDbDomainName + "`");
    String nextToken = null;
    do {
        SelectResult selectResult = client.select(selectRequest);
        selectResult.getItems().forEach(item -> {
            List<Attribute> attributes = new ArrayList<>();
            item.getAttributes().stream()
                    // Do not return the version attribute or inactive attributes
                    .filter(attribute -> (!attribute.getName().equals(versionAttributeName)
                            && !attribute.getValue().startsWith("Inactive")))
                    .forEach(attribute -> {
                        attributes.add(attribute);
                    });
            items.add(new ImmutablePair<>(item.getName(), attributes));
        });
        nextToken = selectResult.getNextToken();
        selectRequest.setNextToken(nextToken);
    } while (nextToken != null);

    return items;
}