Example usage for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBScanExpression DynamoDBScanExpression

List of usage examples for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBScanExpression DynamoDBScanExpression

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBScanExpression DynamoDBScanExpression.

Prototype

DynamoDBScanExpression

Source Link

Usage

From source file:cf.funge.aworldofplants.model.plant.DDBPlantDAO.java

License:Open Source License

/**
 * Returns a list of plants in the DynamoDB table.
 *
 * @param limit The maximum numbers of results for the scan
 * @return A List of Plant objects//w ww  .j a  v a  2s.  c o  m
 */
public List<Plant> getPlants(int limit) {
    if (limit <= 0 || limit > DynamoDBConfiguration.SCAN_LIMIT)
        limit = DynamoDBConfiguration.SCAN_LIMIT;

    DynamoDBScanExpression expression = new DynamoDBScanExpression();
    expression.setLimit(limit);
    return getMapper().scan(Plant.class, expression);
}

From source file:cf.funge.aworldofplants.model.plant.DDBPlantDAO.java

License:Open Source License

public List<Plant> getUserPlants(int limit, String username) {
    if (limit <= 0 || limit > DynamoDBConfiguration.SCAN_LIMIT)
        limit = DynamoDBConfiguration.SCAN_LIMIT;

    Map<String, AttributeValue> eav = new HashMap<>();
    eav.put(":val1", new AttributeValue().withS(username));

    DynamoDBScanExpression expression = new DynamoDBScanExpression().withFilterExpression("username = :val1")
            .withExpressionAttributeValues(eav);
    expression.setLimit(limit);/*from www  .  ja va2  s  .  co m*/

    List<Plant> scanResult = getMapper().scan(Plant.class, expression);

    return scanResult;
}

From source file:cf.funge.aworldofplants.model.plant.DDBPlantDAO.java

License:Open Source License

public GetPlantHistoryResponse getPlantHistory(String plantId, String startDate, String endDate,
        String chartType) {//ww  w.j ava  2 s  . c  o  m
    System.out.println("Find Plant history less than certain date: Scan history.");

    Map<String, AttributeValue> eav = new HashMap<String, AttributeValue>();
    eav.put(":val1", new AttributeValue().withS(plantId));
    eav.put(":val2", new AttributeValue().withN(startDate));
    eav.put(":val3", new AttributeValue().withN(endDate));
    eav.put(":val4", new AttributeValue().withS(chartType));

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression()
            .withFilterExpression(
                    "plantId = :val1 and startTime >= :val2 and endTime <= :val3 and chartType = :val4")
            .withExpressionAttributeValues(eav);

    List<PlantHistory> scanResult = getMapper().scan(PlantHistory.class, scanExpression);

    int scanResultSize = scanResult.size();

    GetPlantHistoryResponse newPlantHistory = new GetPlantHistoryResponse();
    String[] startTimes = new String[scanResultSize];
    String[] endTimes = new String[scanResultSize];
    String[] averages = new String[scanResultSize];
    String[] mins = new String[scanResultSize];
    String[] maxes = new String[scanResultSize];

    int i = 0;

    for (PlantHistory plantHistory : scanResult) {
        startTimes[i] = Objects.toString(plantHistory.getStartTime(), null);
        endTimes[i] = Objects.toString(plantHistory.getEndTime(), null);
        averages[i] = Objects.toString(plantHistory.getAvg(), null);
        mins[i] = Objects.toString(plantHistory.getMin(), null);
        maxes[i] = Objects.toString(plantHistory.getMax(), null);
        ++i;
    }

    newPlantHistory.setStartTimes(startTimes);
    newPlantHistory.setEndTimes(endTimes);
    newPlantHistory.setAverages(averages);
    newPlantHistory.setMins(mins);
    newPlantHistory.setMaxes(maxes);

    return newPlantHistory;
}

From source file:cf.funge.aworldofplants.model.user.DDBUserDAO.java

License:Open Source License

/**
 * Queries DynamoDB to find a user by its Email
 *
 * @param email The email to search for//from   w  w  w. j av a2  s  .c o m
 * @return A populated User object, null if the user was not found
 * @throws DAOException
 */
public boolean getUserByEmail(String email) throws DAOException {
    if (email == null || email.trim().equals("")) {
        throw new DAOException("Cannot lookup null or empty user");
    }

    //return getMapper().load(User.class, email);

    Map<String, AttributeValue> eav = new HashMap<String, AttributeValue>();
    eav.put(":val1", new AttributeValue().withS(email));

    System.out.println("Trying to query with email");

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withFilterExpression("email = :val1")
            .withExpressionAttributeValues(eav);

    List<User> scanResult = getMapper().scan(User.class, scanExpression);

    if (scanResult.isEmpty()) {
        return false;
    }

    return true;
}

From source file:chatbot.ServiceAlertHandler.java

License:Open Source License

private void FindCasesActive(DynamoDBMapper mapper, String sTeamID) throws Exception {
    System.out.println("Finding Active Cases ...");
    Map<String, AttributeValue> eav = new HashMap<String, AttributeValue>();
    eav.put(":val1", new AttributeValue().withS("ACTIVE"));
    eav.put(":val2", new AttributeValue().withS(sTeamID));
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression()
            .withFilterExpression("CASE_STATE = :val1 and TEAM_ID = :val2").withExpressionAttributeValues(eav);
    List<Case> scanResult = mapper.scan(Case.class, scanExpression);
    for (Case objCase : scanResult) {
        System.out.println(objCase);
        System.out.println("ID " + objCase.getId());
        objIDList.put(objCase.getId(), "");
        objCase.setStatus("INACTIVE");
        mapper.save(objCase);/*from  w  w  w.  ja va  2s . c  om*/
    }
}

From source file:com.github.sporcina.mule.modules.DynamoDBConnector.java

License:Open Source License

/**
 * Processor to delete a document/*from  w w w  .j a  va  2 s.co m*/
 * <p/>
 * {@sample.xml ../../../doc/DynamoDB-connector.xml.sample dynamodb:get-all-documents}
 *
 * @param tableName
 *         the name of the table to get the document from
 * @param template
 *         an object with the document data that DynamoDB will match against
 *
 * @return Object a list of all the documents
 */
@Processor
public Object getAllDocuments(String tableName, @Optional @Default(PAYLOAD) final Object template) {

    Class templateClass = template.getClass();

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    DynamoDBMapper mapper = getDbObjectMapper(tableName);
    return mapper.scan(templateClass, scanExpression);
}

From source file:com.makariev.dynamodb.forum.service.BaseDynamoDBRepository.java

License:Apache License

public List<T> findAll() {
    final DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    //not quite correct; this thing is limmitted by dynamoDb ( there is no count ) 
    final PaginatedScanList<T> result = mapper.scan(clazz, scanExpression);
    return result;
}

From source file:com.makariev.dynamodb.forum.service.BicycleQueryScanService.java

License:Apache License

public List<Bicycle> findBicyclesOfSpecificTypeWithMultipleThreads(
        @DsLabel("number of parallel threads") int numberOfThreads, @DsLabel("bicycleType") String bicycleType)
        throws Exception {

    final List<Bicycle> result = new ArrayList<>();

    final DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("ProductCategory",
            new Condition().withComparisonOperator(ComparisonOperator.EQ)
                    .withAttributeValueList(new AttributeValue().withS("Bicycle")));
    scanExpression.addFilterCondition("BicycleType",
            new Condition().withComparisonOperator(ComparisonOperator.EQ)
                    .withAttributeValueList(new AttributeValue().withS(bicycleType)));
    final List<Bicycle> scanResult = mapper.parallelScan(Bicycle.class, scanExpression, numberOfThreads);

    for (Bicycle bicycle : scanResult) {
        result.add(bicycle);/*  w  ww.ja va2 s .  co  m*/
    }
    return result;
}

From source file:com.makariev.dynamodb.preferences.UserPreferenceLowLevelAPIService.java

License:Open Source License

@Override
public List<UserPreference> scanByFirstName(String searchForName) {
    final DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("firstName",
            new Condition().withComparisonOperator(ComparisonOperator.CONTAINS)
                    .withAttributeValueList(new AttributeValue().withS(searchForName)));
    final Map<String, Condition> scanFilter = scanExpression.getScanFilter();

    final ScanResult scanResult = dynamoDb.scan(UserPreference.TABLE_NAME, scanFilter);

    final List<Map<String, AttributeValue>> items = scanResult.getItems();

    return toUserPreferenceList(items);
}

From source file:com.makariev.dynamodb.preferences.UserPreferenceLowLevelAPIService.java

License:Open Source License

@Override
public List<UserPreference> scanByLastName(String searchForName) {
    final DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("lastName",
            new Condition().withComparisonOperator(ComparisonOperator.CONTAINS)
                    .withAttributeValueList(new AttributeValue().withS(searchForName)));
    final Map<String, Condition> scanFilter = scanExpression.getScanFilter();

    final ScanResult scanResult = dynamoDb.scan(UserPreference.TABLE_NAME, scanFilter);

    final List<Map<String, AttributeValue>> items = scanResult.getItems();

    return toUserPreferenceList(items);
}