2016-07-07 4 views
5

मेरे पास एक जावा फ़ंक्शन है जो डायनेमोडीबी आइटम अपडेट करता है। मैं उस मामले को संभालना चाहता हूं जहां कुछ कारणों से अपडेट सफल नहीं है।जावा एसडीके का उपयोग करके डायनेमो डीबी में कोई अपडेट या डालने में सफल होने पर मुझे कैसे पता चलेगा?

Table table = dynamoDB.getTable(tableName); 
AttributeUpdate att = new attributeUpdate(fieldName).put(value); 
UpdateItemOutcome outcome = table.updateItem(keyFieldName, keyValue, att); 

updateItem कॉल का परिणाम एक UpdateItemOutcome वस्तु है: मेरे कोड कुछ इस तरह लग रहा है। यह सब एक getItem() विधि है जो अद्यतन ऑपरेशन से लौटाए गए गुण प्रदान करना चाहिए, और getUpdateItemResult() विधि जो UpdateItemResult ऑब्जेक्ट प्रदान करती है।

getItem() कॉल सफल होने पर भी मुझे शून्य देता है। UpdateItemResult ऑब्जेक्ट में ऐसा कोई प्रतीत नहीं होता है जो मुझे ऑपरेशन के संबंध में किसी भी प्रकार की स्थिति या त्रुटि प्रदान करता हो।

क्या किसी को पता है कि डायनेमो डीबी में इस तरह के संचालन के परिणाम की जांच करने के लिए सबसे अच्छा अभ्यास क्या है? यह प्रश्न इटिम() संचालन को भी संबंधित करता है।

धन्यवाद!

उत्तर

3

प्रलेखन में: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html

Use ReturnValues if you want to get the item attributes as they appeared either before or after they were updated. For UpdateItem, the valid values are: 

    NONE - If ReturnValues is not specified, or if its value is NONE, then nothing is returned. (This setting is the default for ReturnValues.) 

    ALL_OLD - If UpdateItem overwrote an attribute name-value pair, then the content of the old item is returned. 

    UPDATED_OLD - The old versions of only the updated attributes are returned. 

    ALL_NEW - All of the attributes of the new version of the item are returned. 

    UPDATED_NEW - The new versions of only the updated attributes are returned. 

There is no additional cost associated with requesting a return value aside from the small network and processing overhead of receiving a larger response. No Read Capacity Units are consumed. 

Values returned are strongly consistent 

Type: String 

Valid Values: NONE | ALL_OLD | UPDATED_OLD | ALL_NEW | UPDATED_NEW 

Required: No 

आप कर सकते हैं:

UpdateItemSpec updateItemSpec = new UpdateItemSpec(); 
... 
updateItemSpec.withReturnValues(ReturnValue.ALL_NEW); 

फिर UpdateItemOutcome आबादी वाले क्षेत्रों होगा।

हालांकि, अद्यतन या पुट ऑपरेशन विफल होने पर डायनेमो डीबी अपवाद फेंक देगा, इसलिए यदि आप केवल यह जांचना चाहते हैं कि ऑपरेशन सफल हुआ है, तो वापसी मान प्राप्त करना आवश्यक नहीं है।

+0

धन्यवाद, यह बहुत अच्छा काम करेगा। मैं पहले ही अपवादों को पकड़ने के लिए आगे बढ़ गया हूं, लेकिन यह एक पूरा जवाब है। –

संबंधित मुद्दे

 संबंधित मुद्दे