Example usage for com.amazonaws.services.dynamodbv2.model ComparisonOperator EQ

List of usage examples for com.amazonaws.services.dynamodbv2.model ComparisonOperator EQ

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model ComparisonOperator EQ.

Prototype

ComparisonOperator EQ

To view the source code for com.amazonaws.services.dynamodbv2.model ComparisonOperator EQ.

Click Source Link

Usage

From source file:RandomQuery1OnDynamoDB.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();//from  www  .j  a  va 2 s .  co m

    try {

        // Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);

        System.out.println("Table count :" + tableDescription.getItemCount());

        long lStartTime = new Date().getTime();
        System.out.println("start time: " + lStartTime);
        Random rn = new Random();
        // Scan items for movies with a year attribute greater than 1985
        Long lItem = tableDescription.getItemCount();
        int iNoOfItems = lItem.intValue();
        System.out.println("no of item " + lItem);
        for (int i = 0; i <= 49999; i++) {
            String randomInt = Integer.toString(rn.nextInt(iNoOfItems));
            HashMap<String, Condition> scanFilter = new HashMap<String, Condition>();
            Condition condition = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString())
                    .withAttributeValueList(new AttributeValue().withN(randomInt));
            scanFilter.put("id", condition);
            ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
            ScanResult scanResult = dynamoDB.scan(scanRequest);
            System.out.println("Random No :" + randomInt + ":: Query no: " + (i + 1));

        }
        // calculate time difference for update file time
        long lEndTime = new Date().getTime();
        long difference = lEndTime - lStartTime;
        System.out.println("Elapsed milliseconds: " + difference);
        System.out.println("Elapsed seconds: " + difference * 0.001);
        System.out.println("Elapsed Minutes: " + (int) ((difference / (1000 * 60)) % 60));

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:RandomQuery2OnDynamoDB.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();//from ww  w.j  a va 2  s. co  m

    try {

        // Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);
        long lStartTime = new Date().getTime();
        System.out.println("start time: " + lStartTime);
        Random rn = new Random();
        Long lItem = tableDescription.getItemCount();
        int iNoOfItems = lItem.intValue();
        int iPointOnePercent = (int) ((int) iNoOfItems * 0.001);
        int iOnePercent = (int) ((int) iNoOfItems * 0.01);
        System.out.println("TotalItems:" + iNoOfItems + "::0.1% of data is :: " + iPointOnePercent
                + "::1% of data is :" + iOnePercent);

        // Generating 25000 random queries for 0.1 to 1 % of the data
        for (int i = 0; i <= 24999; i++) {
            String randomInt = Integer.toString(rn.nextInt(iOnePercent - iPointOnePercent) + iPointOnePercent);
            HashMap<String, Condition> scanFilter = new HashMap<String, Condition>();
            Condition condition = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString())
                    .withAttributeValueList(new AttributeValue().withN(randomInt));
            scanFilter.put("id", condition);
            ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
            ScanResult scanResult = dynamoDB.scan(scanRequest);
            System.out.println("Random No :" + randomInt + ":: Query no: " + (i + 1));

        }
        // calculate time difference for update file time
        long lEndTime = new Date().getTime();
        long difference = lEndTime - lStartTime;
        System.out.println("Elapsed milliseconds: " + difference);
        System.out.println("Elapsed seconds: " + difference * 0.001);
        System.out.println("Elapsed Minutes: " + (int) ((difference / (1000 * 60)) % 60));

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:amazon.dynamodb.config.DynamoDBManager.java

License:Open Source License

/**
 * Query Amazon DynamoDB/*from ww  w.jav  a2s.  c om*/
 *
 * @param hashKey Hash key for the query request.
 *
 * @param range The range of geohashs to query.
 *
 * @return The query result.
 */
public List<QueryResult> queryGeohash(QueryRequest queryRequest, long hashKey, GeoHashRango range) {
    List<QueryResult> queryResults = new ArrayList<QueryResult>();
    Map<String, AttributeValue> lastEvaluatedKey = null;

    do {
        Map<String, Condition> keyConditions = new HashMap<String, Condition>();

        Condition hashKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withN(String.valueOf(hashKey)));
        keyConditions.put(config.getHashKeyAttributeName(), hashKeyCondition);

        AttributeValue minRange = new AttributeValue().withN(Long.toString(range.getRangeMin()));
        AttributeValue maxRange = new AttributeValue().withN(Long.toString(range.getRangeMax()));

        Condition geohashCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN)
                .withAttributeValueList(minRange, maxRange);
        keyConditions.put(config.getGeohashAttributeName(), geohashCondition);

        queryRequest.withTableName(config.getTableName()).withKeyConditions(keyConditions)
                .withIndexName(config.getGeohashIndexName()).withConsistentRead(true)
                .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
                .withExclusiveStartKey(lastEvaluatedKey);

        QueryResult queryResult = config.getDynamoDBClient().query(queryRequest);
        queryResults.add(queryResult);

        lastEvaluatedKey = queryResult.getLastEvaluatedKey();

    } while (lastEvaluatedKey != null);

    return queryResults;
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.builder.SingleExpectedAttributeValueBuilder.java

License:Open Source License

private void addExpectedValueIfPresent(final StaticBuffer column,
        final Map<String, ExpectedAttributeValue> expectedValueMap) {
    final String dynamoDbColumn = encodeKeyBuffer(column);

    if (expectedValueMap.containsKey(dynamoDbColumn)) {
        return;/*  w ww . j  ava  2  s. co m*/
    }

    if (transaction.contains(store, key, column)) {
        final StaticBuffer expectedValue = transaction.get(store, key, column);
        final ExpectedAttributeValue expectedAttributeValue;
        if (expectedValue == null) {
            expectedAttributeValue = new ExpectedAttributeValue().withExists(false);
        } else {
            final AttributeValue attributeValue = encodeValue(expectedValue);
            expectedAttributeValue = new ExpectedAttributeValue().withValue(attributeValue)
                    .withComparisonOperator(ComparisonOperator.EQ);
        }
        expectedValueMap.put(dynamoDbColumn, expectedAttributeValue);
    }
}

From source file:com.app.dynamoDb.DynamoFacebookUsers.java

License:Open Source License

public boolean isExist(String UserID) {
    ScanRequest scanRequest = new ScanRequest("FacebookUsers");

    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    scanFilter.put("UserID", new Condition().withAttributeValueList(new AttributeValue(UserID))
            .withComparisonOperator(ComparisonOperator.EQ));

    scanRequest.setScanFilter(scanFilter);
    ScanResult scanResult = dynamoDB.scan(scanRequest);

    for (Map<String, AttributeValue> item : scanResult.getItems()) {
        if (!(item.isEmpty()))
            return true;
    }/*w  w w  . j  a  v  a 2s .  c  o  m*/
    return false;
}

From source file:com.app.dynamoDb.DynamoFacebookUsers.java

License:Open Source License

public String getUserName(String UserID) {
    String result = "";
    ScanRequest scanRequest = new ScanRequest("FacebookUsers");

    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    scanFilter.put("UserID", new Condition().withAttributeValueList(new AttributeValue(UserID))
            .withComparisonOperator(ComparisonOperator.EQ));

    scanRequest.setScanFilter(scanFilter);
    ScanResult scanResult = dynamoDB.scan(scanRequest);

    for (Map<String, AttributeValue> item : scanResult.getItems()) {
        System.out.println(item.get("UserName"));

        result = item.get("UserName").toString();
    }//  ww w . j  a v a2 s . co  m
    return result;
}

From source file:com.app.dynamoDb.DynamoFacebookUsers.java

License:Open Source License

public AttributeValue getUserID(String UserName) {

    ScanRequest scanRequest = new ScanRequest("FacebookUsers");

    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    scanFilter.put("Email", new Condition().withAttributeValueList(new AttributeValue(UserName))
            .withComparisonOperator(ComparisonOperator.EQ));
    scanRequest.setScanFilter(scanFilter);
    ScanResult scanResult = dynamoDB.scan(scanRequest);

    for (Map<String, AttributeValue> item : scanResult.getItems()) {
        return item.get("UserID");

    }//from   ww  w .  j  a  v a 2 s . c  om
    return null;
}

From source file:com.app.dynamoDb.DynamoUser.java

License:Open Source License

public boolean validateEmail(String Email, String Password) {

    ScanRequest scanRequest = new ScanRequest("Users");
    scanRequest.setConditionalOperator(ConditionalOperator.AND);

    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    scanFilter.put("Email", new Condition().withAttributeValueList(new AttributeValue(Email))
            .withComparisonOperator(ComparisonOperator.EQ));
    scanFilter.put("Password", new Condition().withAttributeValueList(new AttributeValue(Password))
            .withComparisonOperator(ComparisonOperator.EQ));

    scanRequest.setScanFilter(scanFilter);
    ScanResult scanResult = dynamoDB.scan(scanRequest);

    for (Map<String, AttributeValue> item : scanResult.getItems()) {
        //System.out.println(item);

        if (!item.isEmpty())
            return true;
    }//from  ww  w. ja v a 2s. co m
    return false;

}

From source file:com.app.dynamoDb.DynamoUser.java

License:Open Source License

public boolean validateName(String UserName, String Password) {

    ScanRequest scanRequest = new ScanRequest("Users");
    scanRequest.setConditionalOperator(ConditionalOperator.AND);

    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    scanFilter.put("UserName", new Condition().withAttributeValueList(new AttributeValue(UserName))
            .withComparisonOperator(ComparisonOperator.EQ));
    scanFilter.put("Password", new Condition().withAttributeValueList(new AttributeValue(Password))
            .withComparisonOperator(ComparisonOperator.EQ));

    scanRequest.setScanFilter(scanFilter);
    ScanResult scanResult = dynamoDB.scan(scanRequest);

    for (Map<String, AttributeValue> item : scanResult.getItems()) {
        //System.out.println(item);

        if (!item.isEmpty())
            return true;
    }/*from w  w w.  ja v  a 2  s.  com*/
    return false;

}

From source file:com.app.dynamoDb.DynamoUser.java

License:Open Source License

public String getUserIDfromUserName(String UserName) {
    String result = "";
    ScanRequest scanRequest = new ScanRequest("Users");
    //scanRequest.setConditionalOperator(ConditionalOperator.OR);

    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    scanFilter.put("UserName", new Condition().withAttributeValueList(new AttributeValue(UserName))
            .withComparisonOperator(ComparisonOperator.EQ));
    //scanFilter.put("Password", new Condition().withAttributeValueList(new AttributeValue(UserName)).withComparisonOperator(ComparisonOperator.EQ));

    scanRequest.setScanFilter(scanFilter);
    ScanResult scanResult = dynamoDB.scan(scanRequest);

    for (Map<String, AttributeValue> item : scanResult.getItems()) {
        //         System.out.println(item.get("UserID"));

        result = item.get("UserID").toString().replaceAll("\\W", "").trim().toLowerCase();
        result = result.replaceAll("\\D", "");
    }/*from  w ww .  j av a2 s . co  m*/
    return result;
}