Package com.amazonaws.services.dynamodb.model

Examples of com.amazonaws.services.dynamodb.model.KeysAndAttributes


        Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
        Map<String, Class<?>> classesByTableName = new HashMap<String, Class<?>>();
        Map<String, List<Object>> resultSet = new HashMap<String, List<Object>>();
        int count = 0;

        KeysAndAttributes keysAndAttributes = new KeysAndAttributes();
        List<Key> keys = new LinkedList<Key>();
        for (Class<?> clazz : itemsToGet.keySet()) {
            String tableName = getTableName(clazz, config);
            List<KeyPair> keyPairs = itemsToGet.get(clazz);
            if (keyPairs == null) {
                continue;
            }
            classesByTableName.put(tableName, clazz);

            Method hashKeyGetter = reflector.getHashKeyGetter(clazz);
            for (KeyPair keyPair : keyPairs) {
                AttributeValue hashKeyElement = getHashKeyElement(keyPair.getHashKey(), hashKeyGetter);

                // Determine the range key, if provided
                AttributeValue rangeKeyElement = null;
                if (keyPair.getRangeKey() != null) {
                    Method rangeKeyMethod = reflector.getRangeKeyGetter(clazz);
                    if (rangeKeyMethod == null) {
                        throw new DynamoDBMappingException("Zero-parameter range key property must be annotated with "
                                + DynamoDBRangeKey.class);
                    }
                    rangeKeyElement = getRangeKeyElement(keyPair.getRangeKey(), rangeKeyMethod);
                }

                keys.add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
                count++;
                // Reach the maximum number which can be handled in a single
                // batchGet
                if (count == 100) {
                    requestItems.put(tableName, new KeysAndAttributes().withKeys(keys).withConsistentRead(consistentReads));
                    processBatchGetRequest(classesByTableName, requestItems, resultSet);
                    keys.clear();
                    requestItems.clear();
                    count = 0;
                }

            }

            keysAndAttributes.setKeys(keys);
            requestItems.put(tableName, new KeysAndAttributes().withKeys(new ArrayList<Key>(keys)));
            keys.clear();
        }

        if (count > 0) {
        processBatchGetRequest(classesByTableName, requestItems, resultSet);
View Full Code Here


    @Test
    public void execute() {
        Key key = new Key(new AttributeValue("Key_1"));
        Key unprocessedKey = new Key(new AttributeValue("UNPROCESSED_KEY"));
        Map<String, KeysAndAttributes> keysAndAttributesMap = new HashMap<String, KeysAndAttributes>();
        KeysAndAttributes keysAndAttributes = new KeysAndAttributes().withKeys(key);
        keysAndAttributesMap.put("DOMAIN1", keysAndAttributes);
        exchange.getIn().setHeader(DdbConstants.BATCH_ITEMS, keysAndAttributesMap);

        command.execute();

        assertEquals(keysAndAttributesMap, ddbClient.batchGetItemRequest.getRequestItems());


        BatchResponse batchResponse = (BatchResponse)exchange.getIn()
                .getHeader(DdbConstants.BATCH_RESPONSE, Map.class).get("DOMAIN1");
        AttributeValue value = batchResponse.getItems().get(0).get("attrName");

        KeysAndAttributes unProcessedAttributes = (KeysAndAttributes)exchange.getIn().getHeader(
                DdbConstants.UNPROCESSED_KEYS, Map.class).get("DOMAIN1");
        Key next = unProcessedAttributes.getKeys().iterator().next();

        assertEquals(new AttributeValue("attrValue"), value);
        assertEquals(unprocessedKey, next);
    }
View Full Code Here

        this.batchGetItemRequest = batchGetItemRequest;
        Map<String, BatchResponse> responseMap = new HashMap<String, BatchResponse>();
        responseMap.put("DOMAIN1", new BatchResponse().withItems(getAttributes()));

        Map<String, KeysAndAttributes> unprocessedKeys = new HashMap<String, KeysAndAttributes>();
        unprocessedKeys.put("DOMAIN1", new KeysAndAttributes().withKeys(
                new Key(new AttributeValue("UNPROCESSED_KEY"))));

        return new BatchGetItemResult()
                .withResponses(responseMap)
                .withUnprocessedKeys(unprocessedKeys);
View Full Code Here

    Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
    Map<String, Class<?>> classesByTableName = new HashMap<String, Class<?>>();
    Map<String, List<Object>> resultSet = new HashMap<String, List<Object>>();
    int count = 0;

    KeysAndAttributes keysAndAttributes = new KeysAndAttributes();
    ;
    List<Key> keys = new LinkedList<Key>();
    for (Class<?> clazz : itemsToGet.keySet()) {
      String tableName = getTableName(clazz, config);
      List<KeyPair> keyPairs = itemsToGet.get(clazz);
      classesByTableName.put(tableName, clazz);

      Method hashKeyGetter = reflector.getHashKeyGetter(clazz);
      if (keyPairs == null) {
        continue;
      }
      for (KeyPair keyPair : keyPairs) {
        AttributeValue hashKeyElement = getHashKeyElement(keyPair.getHashKey(), hashKeyGetter);

        // Determine the range key, if provided
        AttributeValue rangeKeyElement = null;
        if (keyPair.getRangeKey() != null) {
          Method rangeKeyMethod = reflector.getRangeKeyGetter(clazz);
          if (rangeKeyMethod == null) {
            throw new DynamoDBMappingException("Zero-parameter range key property must be annotated with "
                + DynamoDBRangeKey.class);
          }
          rangeKeyElement = getRangeKeyElement(keyPair.getRangeKey(), rangeKeyMethod);
        }

        keys.add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
        count++;
        // Reach the maximum number which can be handled in a single
        // batchGet
        if (count == 100) {
          requestItems.put(tableName, new KeysAndAttributes().withKeys(keys));
          processBatchGetRequest(classesByTableName, requestItems, resultSet);
          keys.clear();
          requestItems.clear();
          count = 0;
        }

      }

      keysAndAttributes.setKeys(keys);
      requestItems.put(tableName, new KeysAndAttributes().withKeys(new ArrayList<Key>(keys)));
      keys.clear();
    }

    processBatchGetRequest(classesByTableName, requestItems, resultSet);
    return resultSet;
View Full Code Here

                }

                if ( !requestItems.containsKey(tableName) ) {
                    requestItems
                            .put(tableName,
                                    new KeysAndAttributes().withConsistentRead(consistentReads).withKeys(
                                            new LinkedList<Key>()));
                }

                requestItems.get(tableName).getKeys()
                        .add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
View Full Code Here

                }

                if ( !requestItems.containsKey(tableName) ) {
                    requestItems
                            .put(tableName,
                                    new KeysAndAttributes().withConsistentRead(consistentReads).withKeys(
                                            new LinkedList<Key>()));
                }

                requestItems.get(tableName).getKeys()
                        .add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
View Full Code Here

        Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
        Map<String, Class<?>> classesByTableName = new HashMap<String, Class<?>>();
        Map<String, List<Object>> resultSet = new HashMap<String, List<Object>>();
        int count = 0;

        KeysAndAttributes keysAndAttributes = new KeysAndAttributes();
        List<Key> keys = new LinkedList<Key>();
        for (Class<?> clazz : itemsToGet.keySet()) {
            String tableName = getTableName(clazz, config);
            List<KeyPair> keyPairs = itemsToGet.get(clazz);
            if (keyPairs == null) {
                continue;
            }
            classesByTableName.put(tableName, clazz);

            Method hashKeyGetter = reflector.getHashKeyGetter(clazz);
            for (KeyPair keyPair : keyPairs) {
                AttributeValue hashKeyElement = getHashKeyElement(keyPair.getHashKey(), hashKeyGetter);

                // Determine the range key, if provided
                AttributeValue rangeKeyElement = null;
                if (keyPair.getRangeKey() != null) {
                    Method rangeKeyMethod = reflector.getRangeKeyGetter(clazz);
                    if (rangeKeyMethod == null) {
                        throw new DynamoDBMappingException("Zero-parameter range key property must be annotated with "
                                + DynamoDBRangeKey.class);
                    }
                    rangeKeyElement = getRangeKeyElement(keyPair.getRangeKey(), rangeKeyMethod);
                }

                keys.add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
                count++;
                // Reach the maximum number which can be handled in a single
                // batchGet
                if (count == 100) {
                    requestItems.put(tableName, new KeysAndAttributes().withKeys(keys).withConsistentRead(consistentReads));
                    processBatchGetRequest(classesByTableName, requestItems, resultSet);
                    keys.clear();
                    requestItems.clear();
                    count = 0;
                }

            }

            keysAndAttributes.setKeys(keys);
            requestItems.put(tableName, new KeysAndAttributes().withKeys(new ArrayList<Key>(keys)));
            keys.clear();
        }

        if (count > 0) {
        processBatchGetRequest(classesByTableName, requestItems, resultSet);
View Full Code Here

                }

                if ( !requestItems.containsKey(tableName) ) {
                    requestItems
                            .put(tableName,
                                    new KeysAndAttributes().withConsistentRead(consistentReads).withKeys(
                                            new LinkedList<Key>()));
                }

                requestItems.get(tableName).getKeys()
                        .add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
View Full Code Here

        Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
        Map<String, Class<?>> classesByTableName = new HashMap<String, Class<?>>();
        Map<String, List<Object>> resultSet = new HashMap<String, List<Object>>();
        int count = 0;

        KeysAndAttributes keysAndAttributes = new KeysAndAttributes();
        List<Key> keys = new LinkedList<Key>();
        for (Class<?> clazz : itemsToGet.keySet()) {
            String tableName = getTableName(clazz, config);
            List<KeyPair> keyPairs = itemsToGet.get(clazz);
            if (keyPairs == null) {
                continue;
            }
            classesByTableName.put(tableName, clazz);

            Method hashKeyGetter = reflector.getHashKeyGetter(clazz);
            for (KeyPair keyPair : keyPairs) {
                AttributeValue hashKeyElement = getHashKeyElement(keyPair.getHashKey(), hashKeyGetter);

                // Determine the range key, if provided
                AttributeValue rangeKeyElement = null;
                if (keyPair.getRangeKey() != null) {
                    Method rangeKeyMethod = reflector.getRangeKeyGetter(clazz);
                    if (rangeKeyMethod == null) {
                        throw new DynamoDBMappingException("Zero-parameter range key property must be annotated with "
                                + DynamoDBRangeKey.class);
                    }
                    rangeKeyElement = getRangeKeyElement(keyPair.getRangeKey(), rangeKeyMethod);
                }

                keys.add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
                count++;
                // Reach the maximum number which can be handled in a single
                // batchGet
                if (count == 100) {
                    requestItems.put(tableName, new KeysAndAttributes().withKeys(keys).withConsistentRead(consistentReads));
                    processBatchGetRequest(classesByTableName, requestItems, resultSet);
                    keys.clear();
                    requestItems.clear();
                    count = 0;
                }

            }

            keysAndAttributes.setKeys(keys);
            requestItems.put(tableName, new KeysAndAttributes().withKeys(new ArrayList<Key>(keys)));
            keys.clear();
        }

        if (count > 0) {
        processBatchGetRequest(classesByTableName, requestItems, resultSet);
View Full Code Here

                }

                if ( !requestItems.containsKey(tableName) ) {
                    requestItems
                            .put(tableName,
                                    new KeysAndAttributes().withConsistentRead(consistentReads).withKeys(
                                            new LinkedList<Key>()));
                }

                requestItems.get(tableName).getKeys()
                        .add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
View Full Code Here

TOP

Related Classes of com.amazonaws.services.dynamodb.model.KeysAndAttributes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.