Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.dynamodbv2.document;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;

Used to specify one or multiple primary keys of a specific table, the attributes to be retrieved from that table, and the consistency of the read operation in a BatchGetItem request.
 
 public class TableKeysAndAttributes {
     private final String tableName;
     private List<PrimaryKeyprimaryKeys;
     private Set<StringattributeNames;
     private boolean consistentRead;
 
     private String projectionExpression;
     private Map<String,StringnameMap;
 
     public TableKeysAndAttributes(String tableName) {
         if (tableName == null || tableName.trim().length() == 0)
             throw new IllegalArgumentException("table name must not be null or empty");
         this. = tableName;
     }

    
Return the list of primary keys (of the current table) to be included in a batch get-item operation.
 
     public List<PrimaryKeygetPrimaryKeys() {
         return ;
     }

    
Used to specify multiple primary keys. A primary key could consist of either a hash-key or both a hash-key and a range-key depending on the schema of the table.
 
     public TableKeysAndAttributes withPrimaryKeys(PrimaryKey... primaryKeys) {
         if (primaryKeys == null)
             this. = null;
         else {
             Set<StringpkNameSet = null;
             for (PrimaryKey pk : primaryKeys) {
                 if (pkNameSet == null)
                     pkNameSet = pk.getComponentNameSet();
                 else {
                     if (!pkNameSet.equals(pk.getComponentNameSet())) {
                         throw new IllegalArgumentException(
                             "primary key attribute names must be consistent for the specified primary keys");
                     }
                 }
             }
             this. = new ArrayList<PrimaryKey>(Arrays.asList(primaryKeys));
         }
         return this;
     }

    
Used to specify multiple hash-only primary keys.

Parameters:
hashKeyName hash-only key name
hashKeyValues a list of hash key values
 
     public TableKeysAndAttributes withHashOnlyKeys(String hashKeyNameObject ... hashKeyValues) {
         if (hashKeyName == null)
             throw new IllegalArgumentException();
         PrimaryKey[] primaryKeys = new PrimaryKey[hashKeyValues.length];
         for (int i=0; i < hashKeyValues.lengthi++)
             primaryKeys[i] = new PrimaryKey(hashKeyNamehashKeyValues[i]);
         return withPrimaryKeys(primaryKeys);
     }

    
Used to specify multiple hash-and-range primary keys.

Parameters:
hashKeyName hash key name
rangeKeyName range key name
alternatingHashAndRangeKeyValues a list of alternating hash key value and range key value
            String hashKeyNameString rangeKeyName
            Object... alternatingHashAndRangeKeyValues) {
        if (hashKeyName == null)
            throw new IllegalArgumentException("hash key name must be specified");
        if (rangeKeyName == null)
            throw new IllegalArgumentException("range key name must be specified");
        if (alternatingHashAndRangeKeyValues.length % 2 != 0)
            throw new IllegalArgumentException("number of hash and range key values must be the same");
        final int len = alternatingHashAndRangeKeyValues.length / 2;
        PrimaryKey[] primaryKeys = new PrimaryKey[len];
        for (int i=0; i < alternatingHashAndRangeKeyValues.lengthi += 2) {
            primaryKeys[i >> 1] = new PrimaryKey(
                hashKeyNamealternatingHashAndRangeKeyValues[i],
                rangeKeyNamealternatingHashAndRangeKeyValues[i+1]);
        }
        return withPrimaryKeys(primaryKeys);
    }

    
Adds a primary key to be included in the batch get-item operation. A primary key could consist of either a hash-key or both a hash-key and a range-key depending on the schema of the table.
    public TableKeysAndAttributes addPrimaryKey(PrimaryKey primaryKey) {
        if (primaryKey != null) {
            if ( == null)
                 = new ArrayList<PrimaryKey>();
            checkConsistency(primaryKey);
            this..add(primaryKey);
        }
        return this;
    }
    private void checkConsistency(PrimaryKey primaryKey) {
        if (this..size() > 0) {
            // use the first one as the representative
            final Set<StringnameSet = .get(0).getComponentNameSet();
            if (!nameSet.equals(primaryKey.getComponentNameSet()))
                throw new IllegalArgumentException(
                    "primary key must be added with consistent key attribute name(s)");
        }
    }

    
Adds a hash-only primary key to be included in the batch get-item operation.

Parameters:
hashKeyName name of the hash key attribute name
hashKeyValue name of the hash key value
Returns:
the current instance for method chaining purposes
            String hashKeyNameObject hashKeyValue) {
        this.addPrimaryKey(new PrimaryKey(hashKeyNamehashKeyValue));
        return this;
    }

    
Adds multiple hash-only primary keys to be included in the batch get-item operation.

Parameters:
hashKeyName name of the hash key attribute name
hashKeyValues multiple hash key values
Returns:
the current instance for method chaining purposes
            Object ... hashKeyValues) {
        for (Object hashKeyValuehashKeyValues) {
            this.addPrimaryKey(new PrimaryKey(hashKeyNamehashKeyValue));
        }
        return this;
    }

    
Adds multiple hash-and-range primary keys to be included in the batch get-item operation.

Parameters:
hashKeyName name of the hash key attribute name
rangeKeyName name of the range key attribute name
alternatingHashRangeKeyValues used to specify multiple alternating hash key and range key values
Returns:
the current instance for method chaining purposes
            String hashKeyNameString rangeKeyName,
            Object ... alternatingHashRangeKeyValues) {
        if (alternatingHashRangeKeyValues.length % 2 != 0) {
            throw new IllegalArgumentException(
                "The multiple hash and range key values must alternate");
        }
        for (int i =0; i < alternatingHashRangeKeyValues.lengthi+=2) {
            Object hashKeyValue = alternatingHashRangeKeyValues[i];
            Object rangeKeyValue = alternatingHashRangeKeyValues[i+1];
            this.addPrimaryKey(
                new PrimaryKey()
                    .addComponent(hashKeyNamehashKeyValue)
                    .addComponent(rangeKeyNamerangeKeyValue)
                );
        }
        return this;
    }

    
Adds a primary key (that consists of a hash-key and a range-key) to be included in the batch get-item operation.

Parameters:
hashKeyName hash key attribute name
hashKeyValue hash key value
rangeKeyName range key attribute name
rangeKeyValue range key value
Returns:
the current instance for method chaining purposes
            String hashKeyNameObject hashKeyValue,
            String rangeKeyNameObject rangeKeyValue) {
        this.addPrimaryKey(
            new PrimaryKey()
                .addComponent(hashKeyNamehashKeyValue)
                .addComponent(rangeKeyNamerangeKeyValue));
        return this;
    }

    
    @Deprecated
    public TableKeysAndAttributes withAttrbuteNames(String ... attributeNames) {
        return withAttributeNames(attributeNames);
    }

    
    @Deprecated
    public TableKeysAndAttributes withAttrbuteNames(List<StringattributeNames) {
        return withAttributeNames(attributeNames);
    }

    
Used to specify the attributes to be retrieved in each item returned from the batch get-item operation.

Parameters:
attributeNames names of the attributes to be retrieved in each item returned from the batch get-item operation.
Returns:
the current instance for method chaining purposes
    public TableKeysAndAttributes withAttributeNames(String ... attributeNames) {
        if (attributeNames == null)
            this. = null;
        else
            this. = Collections.unmodifiableSet(
                new LinkedHashSet<String>(Arrays.asList(attributeNames)));
        return this;
    }
    public TableKeysAndAttributes withAttributeNames(List<StringattributeNames) {
        if (attributeNames == null)
            this. = null;
        else
            this. = Collections.unmodifiableSet(
                    new LinkedHashSet<String>(attributeNames));
        return this;
    }
    public Set<StringgetAttributeNames() {
        return ;
    }
    public String getTableName() {
        return ;
    }
    public boolean isConsistentRead() {
        return ;
    }
    public TableKeysAndAttributes withConsistentRead(boolean consistentRead) {
        this. = consistentRead;
        return this;
    }
    public String getProjectionExpression() {
        return ;
    }
    public TableKeysAndAttributes withProjectionExpression(String projectionExpression) {
        this. = projectionExpression;
        return this;
    }
    public Map<StringStringgetNameMap() {
        return ;
    }
    public TableKeysAndAttributes withNameMap(Map<StringStringnameMap) {
        this. = nameMap == null 
            ? null : Collections.unmodifiableMap(new LinkedHashMap<StringString>(nameMap));
        return this;
    }
New to GrepCode? Check out our FAQ X