001package com.nimbusds.infinispan.persistence.dynamodb; 002 003 004import com.amazonaws.services.dynamodbv2.model.AttributeDefinition; 005import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; 006import com.amazonaws.services.dynamodbv2.model.KeyType; 007import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType; 008 009 010/** 011 * DynamoDB hash key schema. 012 */ 013public final class DynamoDBHashKeySchema { 014 015 016 /** 017 * The key name. 018 */ 019 private final String keyName; 020 021 022 /** 023 * The attribute type. 024 */ 025 private final ScalarAttributeType attrType; 026 027 028 /** 029 * Creates a new DynamoDB hash key schema. 030 * 031 * @param keyName The key (attribute) name. 032 * @param attrType The key attribute type. 033 */ 034 public DynamoDBHashKeySchema(final String keyName, 035 final ScalarAttributeType attrType) { 036 if (keyName == null) { 037 throw new IllegalArgumentException("The key (attribute) name must not be null"); 038 } 039 this.keyName = keyName; 040 041 if (attrType == null) { 042 throw new IllegalArgumentException("The key attribute type must not be null"); 043 } 044 this.attrType = attrType; 045 } 046 047 048 /** 049 * Returns the key (attribute) name. 050 * 051 * @return The key (attribute) name. 052 */ 053 public String getKeyName() { 054 055 return keyName; 056 } 057 058 059 /** 060 * Returns the key attribute type. 061 * 062 * @return The key attribute type. 063 */ 064 public ScalarAttributeType getAttributeType() { 065 066 return attrType; 067 } 068 069 070 /** 071 * Returns the key schema element. 072 * 073 * @return The key schema element. 074 */ 075 public KeySchemaElement toKeySchemaElement() { 076 077 return new KeySchemaElement(keyName, KeyType.HASH); 078 } 079 080 081 /** 082 * Returns the attribute definition. 083 * 084 * @return The attribute definition. 085 */ 086 public AttributeDefinition toAttributeDefinition() { 087 088 return new AttributeDefinition(keyName, attrType); 089 } 090}