All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazonaws.services.dynamodbv2.document.spec.AbstractSpecWithPrimaryKey Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon DynamoDB module holds the client classes that are used for communicating with Amazon DynamoDB Service

The newest version!
/*
 * Copyright 2014-2024 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.spec;

import java.util.Arrays;
import java.util.Collection;

import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.services.dynamodbv2.document.KeyAttribute;
import com.amazonaws.services.dynamodbv2.document.PrimaryKey;

/**
 * Common base class for parameter specification that involves a primary key.
 */
public class AbstractSpecWithPrimaryKey
        extends AbstractSpec {
    private Collection keyComponents;

    protected AbstractSpecWithPrimaryKey(T request) {
        super(request);
    }

    /**
     * Returns the primary key components that has been specified.
     */
    public final Collection getKeyComponents() {
        return keyComponents;
    }

    /**
     * Sets the primary key with the specified key components.
     */
    public AbstractSpecWithPrimaryKey withPrimaryKey(KeyAttribute ... components) {
        if (components == null)
            this.keyComponents = null;
        else
            this.keyComponents = Arrays.asList(components);
        return this;
    }

    /**
     * Sets the primary key.
     */
    public AbstractSpecWithPrimaryKey withPrimaryKey(PrimaryKey primaryKey) {
        if (primaryKey == null)
            this.keyComponents = null;
        else {
            this.keyComponents = primaryKey.getComponents();
        }
        return this;
    }

    /**
     * Sets the primary key with the specified hash-only key name and value.
     */
    public AbstractSpecWithPrimaryKey withPrimaryKey(String hashKeyName, Object hashKeyValue) {
        if (hashKeyName == null)
            throw new IllegalArgumentException();
        withPrimaryKey(new PrimaryKey(hashKeyName, hashKeyValue));
        return this;
    }

    /**
     * Sets the primary key with the specified hash key and range key.
     */
    public AbstractSpecWithPrimaryKey withPrimaryKey(String hashKeyName, Object hashKeyValue,
            String rangeKeyName, Object rangeKeyValue) {
        if (hashKeyName == null)
            throw new IllegalArgumentException("Invalid hash key name");
        if (rangeKeyName == null)
            throw new IllegalArgumentException("Invalid range key name");
        if (hashKeyName.equals(rangeKeyName))
            throw new IllegalArgumentException("Names of hash and range keys must not be the same");
        withPrimaryKey(new PrimaryKey(hashKeyName, hashKeyValue, 
            rangeKeyName, rangeKeyValue));
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy