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.Set;

Used to specify items to be put and/or primary keys to be deleted from a specific table in a BatchWriteItem request.
 
 public class TableWriteItems {
     private final String tableName;
     private List<PrimaryKeyprimaryKeysToDelete;
     private Collection<ItemitemsToPut;
 
     public TableWriteItems(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 deleted in a batch write operation.
 
     public List<PrimaryKeygetPrimaryKeysToDelete() {
         return ;
     }

    
Used to specify multiple primary keys to be deleted from the current table. 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.
 
             PrimaryKey... primaryKeysToDelete) {
         if (primaryKeysToDelete == null)
             this. = null;
         else {
             Set<StringpkNameSet = null;
             for (PrimaryKey pk : primaryKeysToDelete) {
                 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(primaryKeysToDelete));
         }
         return this;
     }

    
Used to specify multiple hash-only primary keys to be deleted from the current table.

Parameters:
hashKeyName hash-only key name
hashKeyValues a list of hash key values
 
     public TableWriteItems withHashOnlyKeysToDelete(String hashKeyName,
             Object... 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 withPrimaryKeysToDelete(primaryKeys);
     }

    
Used to specify multiple hash-and-range primary keys to be deleted from the current table.

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

    
Adds a primary key to be deleted in a batch write-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 TableWriteItems addPrimaryKeyToDelete(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 deleted in a batch write 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.addPrimaryKeyToDelete(new PrimaryKey(hashKeyNamehashKeyValue));
        return this;
    }

    
Adds multiple hash-only primary keys to be deleted in a batch write 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.addPrimaryKeyToDelete(new PrimaryKey(hashKeyNamehashKeyValue));
        }
        return this;
    }

    
Adds multiple hash-and-range primary keys to be deleted in a batch write 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.addPrimaryKeyToDelete(
                new PrimaryKey()
                    .addComponent(hashKeyNamehashKeyValue)
                    .addComponent(rangeKeyNamerangeKeyValue)
                );
        }
        return this;
    }

    
Adds a primary key (that consists of a hash-key and a range-key) to be deleted in a batch write 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.addPrimaryKeyToDelete(
            new PrimaryKey()
                .addComponent(hashKeyNamehashKeyValue)
                .addComponent(rangeKeyNamerangeKeyValue));
        return this;
    }

    
Used to specify the items to be put in the current table in a batch write operation.

Returns:
the current instance for method chaining purposes
    public TableWriteItems withItemsToPut(Item ... itemsToPut) {
        if (itemsToPut == null)
            this. = null;
        else
            this. = new ArrayList<Item>(Arrays.asList(itemsToPut));
        return this;
    }

    
Used to specify the collection of items to be put in the current table in a batch write operation.

Returns:
the current instance for method chaining purposes
    public TableWriteItems withItemsToPut(Collection<ItemitemsToPut) {
        if (itemsToPut == null)
            this. = null;
        else
            this. = new ArrayList<Item>(itemsToPut);
        return this;
    }

    
Returns the collection of items to be put in the current table in a batch write operation.
    public Collection<ItemgetItemsToPut() {
        return  == null
             ? null
             : Collections.unmodifiableCollection();
    }
    public String getTableName() {
        return ;
    }

    
Adds an item to be put to the current table in a batch write operation.
    public TableWriteItems addItemToPut(Item item) {
        if (item != null) {
            if ( == null)
                 = new ArrayList<Item>();
            this..add(item);
        }
        return this;
    }
New to GrepCode? Check out our FAQ X