1

只有当我添加它的项目不存在时,我才想添加一个属性。

据我所知,UpdateCondition 构造仅允许您根据是否存在具有指定值的项目的特定属性进行更新。

4

1 回答 1

-2

是执行有条件看跌期权的帮助链接。

使用条件放置的帮助链接仅在属性不存在时放置它。

编辑:

如果不运行 Amazon SimpleDB Query,您将无法检查项目是否存在。您可以查询一个项目,如果 amazon simpledb 没有在请求中返回该项目,则表示该项目不存在。检查示例代码 -

try {
            BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials("<accessKey>", "<secretkey>");
            AmazonSimpleDBClient amazonSimpleDBClient = new AmazonSimpleDBClient(basicAWSCredentials);
            amazonSimpleDBClient.setEndpoint("sdb.amazonaws.com");
            SelectRequest selectRequest = new SelectRequest("select * from `<domainName>` where itemName()='<itemName>'");
            SelectResult selectResult = amazonSimpleDBClient.select(selectRequest);
            List<Item> itemList = selectResult.getItems();
            if (itemList.size() == 0) {
                System.out.println("Specified item does not exist.");
                List<ReplaceableAttribute> list = new ArrayList<ReplaceableAttribute>();
                ReplaceableAttribute replaceableAttribute = new ReplaceableAttribute("<attribute>", "<value>", Boolean.TRUE);
                list.add(replaceableAttribute);
                PutAttributesRequest attributesRequest = new PutAttributesRequest("<domainName>", "<itemName>", list);
                amazonSimpleDBClient.putAttributes(attributesRequest);
            } else {
                System.out.println("Specified item exist. Do Nothing.");
            }
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
于 2013-08-23T04:50:03.927 回答