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

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

Introduction

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

Prototype

ComparisonOperator BEGINS_WITH

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

Click Source Link

Usage

From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCreator.java

License:Apache License

protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID> criteria, Part part,
        Iterator<Object> iterator) {
    if (part.shouldIgnoreCase().equals(IgnoreCaseType.ALWAYS))
        throw new UnsupportedOperationException("Case insensitivity not supported");

    Class<?> leafNodePropertyType = part.getProperty().getLeafProperty().getType();

    PropertyPath leafNodePropertyPath = part.getProperty().getLeafProperty();
    String leafNodePropertyName = leafNodePropertyPath.toDotPath();
    if (leafNodePropertyName.indexOf(".") != -1) {
        int index = leafNodePropertyName.lastIndexOf(".");
        leafNodePropertyName = leafNodePropertyName.substring(index);
    }/*from  w w w.j  a  v a  2  s  . co m*/

    switch (part.getType()) {

    case IN:
        Object in = iterator.next();
        Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '"
                + leafNodePropertyName + "'");
        boolean isIterable = ClassUtils.isAssignable(Iterable.class, in.getClass());
        boolean isArray = ObjectUtils.isArray(in);
        Assert.isTrue(isIterable || isArray, "In criteria can only operate with Iterable or Array parameters");
        Iterable<?> iterable = isIterable ? ((Iterable<?>) in) : Arrays.asList(ObjectUtils.toObjectArray(in));
        return criteria.withPropertyIn(leafNodePropertyName, iterable, leafNodePropertyType);
    case CONTAINING:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.CONTAINS,
                iterator.next(), leafNodePropertyType);
    case STARTING_WITH:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.BEGINS_WITH,
                iterator.next(), leafNodePropertyType);
    case BETWEEN:
        Object first = iterator.next();
        Object second = iterator.next();
        return criteria.withPropertyBetween(leafNodePropertyName, first, second, leafNodePropertyType);
    case AFTER:
    case GREATER_THAN:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GT, iterator.next(),
                leafNodePropertyType);
    case BEFORE:
    case LESS_THAN:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LT, iterator.next(),
                leafNodePropertyType);
    case GREATER_THAN_EQUAL:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GE, iterator.next(),
                leafNodePropertyType);
    case LESS_THAN_EQUAL:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LE, iterator.next(),
                leafNodePropertyType);
    case IS_NULL:
        return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NULL);
    case IS_NOT_NULL:
        return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NOT_NULL);
    case TRUE:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.TRUE,
                leafNodePropertyType);
    case FALSE:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.FALSE,
                leafNodePropertyType);
    case SIMPLE_PROPERTY:
        return criteria.withPropertyEquals(leafNodePropertyName, iterator.next(), leafNodePropertyType);
    case NEGATING_SIMPLE_PROPERTY:
        return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.NE, iterator.next(),
                leafNodePropertyType);
    default:
        throw new IllegalArgumentException("Unsupported keyword " + part.getType());
    }

}

From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.java

License:Apache License

public boolean comparisonOperatorsPermittedForQuery() {
    List<ComparisonOperator> comparisonOperatorsPermittedForQuery = Arrays.asList(new ComparisonOperator[] {
            ComparisonOperator.EQ, ComparisonOperator.LE, ComparisonOperator.LT, ComparisonOperator.GE,
            ComparisonOperator.GT, ComparisonOperator.BEGINS_WITH, ComparisonOperator.BETWEEN });

    // Can only query on subset of Conditions
    for (Collection<Condition> conditions : attributeConditions.values()) {
        for (Condition condition : conditions) {
            if (!comparisonOperatorsPermittedForQuery
                    .contains(ComparisonOperator.fromValue(condition.getComparisonOperator()))) {
                return false;
            }/*from   ww w .  j  av a 2s.c o  m*/
        }
    }
    return true;
}

From source file:org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBEntityWithHashAndRangeKeyCriteria.java

License:Apache License

private void checkComparisonOperatorPermittedForCompositeHashAndRangeKey(
        ComparisonOperator comparisonOperator) {

    if (!ComparisonOperator.EQ.equals(comparisonOperator)
            && !ComparisonOperator.CONTAINS.equals(comparisonOperator)
            && !ComparisonOperator.BEGINS_WITH.equals(comparisonOperator)) {
        throw new UnsupportedOperationException(
                "Only EQ,CONTAINS,BEGINS_WITH supported for composite id comparison");
    }/*  ww w.  j  a  v a  2 s  .  co  m*/

}

From source file:org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBQueryCreator.java

License:Apache License

protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID> criteria, Part part,
        Iterator<Object> iterator) {
    if (part.shouldIgnoreCase().equals(IgnoreCaseType.ALWAYS))
        throw new UnsupportedOperationException("Case insensitivity not supported");

    Class<?> propertyType = part.getProperty().getType();

    switch (part.getType()) {
    case IN:/*from w ww. j a  v a2  s.  c  o  m*/
        Object in = iterator.next();
        Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '"
                + part.getProperty().getSegment() + "'");
        boolean isIterable = ClassUtils.isAssignable(in.getClass(), Iterable.class);
        boolean isArray = ObjectUtils.isArray(in);
        Assert.isTrue(isIterable || isArray, "In criteria can only operate with Iterable or Array parameters");
        Iterable<?> iterable = isIterable ? ((Iterable<?>) in) : Arrays.asList(ObjectUtils.toObjectArray(in));
        return criteria.withPropertyIn(part.getProperty().getSegment(), iterable, propertyType);
    case CONTAINING:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.CONTAINS,
                iterator.next(), propertyType);
    case STARTING_WITH:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.BEGINS_WITH,
                iterator.next(), propertyType);
    case BETWEEN:
        Object first = iterator.next();
        Object second = iterator.next();
        return criteria.withPropertyBetween(part.getProperty().getSegment(), first, second, propertyType);
    case AFTER:
    case GREATER_THAN:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.GT,
                iterator.next(), propertyType);
    case BEFORE:
    case LESS_THAN:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.LT,
                iterator.next(), propertyType);
    case GREATER_THAN_EQUAL:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.GE,
                iterator.next(), propertyType);
    case LESS_THAN_EQUAL:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.LE,
                iterator.next(), propertyType);
    case IS_NULL:
        return criteria.withNoValuedCriteria(part.getProperty().getSegment(), ComparisonOperator.NULL);
    case IS_NOT_NULL:
        return criteria.withNoValuedCriteria(part.getProperty().getSegment(), ComparisonOperator.NOT_NULL);
    case TRUE:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.EQ,
                Boolean.TRUE, propertyType);
    case FALSE:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.EQ,
                Boolean.FALSE, propertyType);
    case SIMPLE_PROPERTY:
        return criteria.withPropertyEquals(part.getProperty().getSegment(), iterator.next(), propertyType);
    case NEGATING_SIMPLE_PROPERTY:
        return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.NE,
                iterator.next(), propertyType);
    default:
        throw new IllegalArgumentException("Unsupported keyword " + part.getType());
    }

}

From source file:searchengine.WordToDoc.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/* ww w.jav a2  s.c o  m*/

    try {
        String tableName = "my-favorite-movies-table";

        // Create table if it does not exist yet
        if (Tables.doesTableExist(dynamoDB, tableName)) {
            System.out.println("Table " + tableName + " is already ACTIVE");
        } else {
            // Create a table with a primary hash key named 'name', which holds a string
            CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
                    .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH))
                    .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name")
                            .withAttributeType(ScalarAttributeType.S))
                    .withProvisionedThroughput(
                            new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
            TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest)
                    .getTableDescription();
            System.out.println("Created Table: " + createdTableDescription);

            // Wait for it to become active
            System.out.println("Waiting for " + tableName + " to become ACTIVE...");
            Tables.awaitTableToBecomeActive(dynamoDB, tableName);
        }

        /*// Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);
                
        // Add an item
        Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara");
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);*/

        /*// Add another item
        item = newItem("Airplane", 1980, "*****", "James", "Billy Bob");
        putItemRequest = new PutItemRequest(tableName, item);
        putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);
                
        item = newItem("Billrplane", 1980, "*****", "James", "Billy Bob");
        putItemRequest = new PutItemRequest(tableName, item);
        putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);*/

        // Scan items for movies with a year attribute greater than 1985
        HashMap<String, Condition> scanFilter = new HashMap<String, Condition>();
        Condition condition = new Condition().withComparisonOperator(ComparisonOperator.BEGINS_WITH)
                .withAttributeValueList(new AttributeValue().withS("Bill"));
        scanFilter.put("name", condition);
        ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        for (int i = 0; i < 2; i++) {

            System.out.println("Result: " + scanResult.getItems().get(i).get("year"));
        }

    } 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());
    }
}