SimpleDB では SQL のようにテーブル属性としてユニーク制約を定義することができないため、ユニーク制約を行いたい場合は、以下のように UpdateCondition を指定してデータを登録します。
この例の場合は、メールアドレスをキーに、存在するであろう属性を検索して、見つかった場合は既に登録済みとみなして排他処理を行って、別のスレッドからの並列書き込みによる上書きを回避しています。
AmazonSimpleDBClient client =
new AmazonSimpleDBClient(new AWSCredentials() {
@Override
public String getAWSSecretKey() {
return awsSecretKey;
}
@Override
public String getAWSAccessKeyId() {
return awsAccessKey;
}
});
List<ReplaceableAttribute> list = new ArrayList<ReplaceableAttribute>();
list.add(new ReplaceableAttribute("id", "001", true));
client.putAttributes(new PutAttributesRequest()
.withDomainName("user")
.withItemName("user1@sample.com")
.withAttributes(list)
.withExpected(new UpdateCondition().withExists(false).withName("id")));

