/** * Save the item using a PutItem request. The handler will call this * method if * <ul> * <li> CLOBBER configuration is being used; * <li> OR the item contains auto-generated key value; * <li> OR an UpdateItem request has silently failed (200 response with * no affected attribute), which indicates the key-only-put scenario * that we used to handle by the keyOnlyPut(...) hack. * </ul> */ protected PutItemResult doPutItem() { Map<String, AttributeValue> attributeValues = convertToItem(getAttributeValueUpdates()); attributeValues = transformAttributes( toParameters(attributeValues, this.clazz, getTableName(), saveConfig)); PutItemRequest req = new PutItemRequest() .withTableName(getTableName()) .withItem(attributeValues) .withExpected(mergeExpectedAttributeValueConditions()) .withConditionalOperator(userProvidedConditionOperator) .withRequestMetricCollector(saveConfig.getRequestMetricCollector()); return db.putItem(applyUserAgent(req)); }
private PutItemOutcome doPutItem(PutItemSpec spec) { // set the table name String tableName = getTable().getTableName(); PutItemRequest req = spec.getRequest().withTableName(tableName); // set up the item Item item = spec.getItem(); final Map<String,AttributeValue> attributes = InternalUtils.toAttributeValues(item); // set up the expected attribute map, if any final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(spec.getExpected()); // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up the request req.withItem(attributes) .withExpected(expectedMap) .withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; PutItemResult result = getClient().putItem(req); return new PutItemOutcome(result); } }
@Override public <T> T setConfigOnce(String project, String configName, @NotNull T value) { try { dynamoDBClient.putItem(new PutItemRequest() .withTableName(tableConfig.getTableName()) .withExpected(of("id", new ExpectedAttributeValue(false), "project", new ExpectedAttributeValue(false))) .withItem(of( "project", new AttributeValue(project), "id", new AttributeValue(configName), "value", new AttributeValue(JsonHelper.encode(value))))); return value; } catch (Exception e) { return getConfig(project, configName, (Class<T>) value.getClass()); } }
/** * Save the item using a PutItem request. The handler will call this * method if * <ul> * <li>CLOBBER configuration is being used; * <li>OR the item contains auto-generated key value; * <li>OR an UpdateItem request has silently failed (200 response with * no affected attribute), which indicates the key-only-put scenario * that we used to handle by the keyOnlyPut(...) hack. * </ul> */ protected PutItemResult doPutItem() { Map<String, AttributeValue> attributeValues = convertToItem(getAttributeValueUpdates()); attributeValues = transformAttributes( toParameters(attributeValues, this.clazz, getTableName(), saveConfig)); final PutItemRequest req = new PutItemRequest() .withTableName(getTableName()) .withItem(attributeValues) .withExpected(mergeExpectedAttributeValueConditions()) .withConditionalOperator(userProvidedConditionOperator) .withRequestMetricCollector(saveConfig.getRequestMetricCollector()); return db.putItem(applyUserAgent(req)); }
private Map<String, AttributeValue> conditionalPut(final Map<String, AttributeValue> item) { try { final PutItemRequest put = new PutItemRequest().withTableName(tableName).withItem(item) .withExpected(doesNotExist); ddb.putItem(put); return item; } catch (final ConditionalCheckFailedException ex) { final Map<String, AttributeValue> ddbKey = new HashMap<String, AttributeValue>(); ddbKey.put(DEFAULT_HASH_KEY, item.get(DEFAULT_HASH_KEY)); ddbKey.put(DEFAULT_RANGE_KEY, item.get(DEFAULT_RANGE_KEY)); return ddbGet(ddbKey); } }
private Map<String, AttributeValue> conditionalPut(final Map<String, AttributeValue> item) { try { final PutItemRequest put = new PutItemRequest().withTableName(tableName).withItem(item) .withExpected(doesNotExist); ddb.putItem(put); return item; } catch (final ConditionalCheckFailedException ex) { final Map<String, AttributeValue> ddbKey = new HashMap<>(); ddbKey.put(DEFAULT_HASH_KEY, item.get(DEFAULT_HASH_KEY)); ddbKey.put(DEFAULT_RANGE_KEY, item.get(DEFAULT_RANGE_KEY)); return ddbGet(ddbKey); } }
/** * This API retrieves the intermediate keys from the source region and replicates it in the target region. * @param materialName * @param version * @param targetMetaStore */ public void replicate(final String materialName, final long version, final MetaStore targetMetaStore) { try { final Map<String, AttributeValue> ddbKey = new HashMap<String, AttributeValue>(); ddbKey.put(DEFAULT_HASH_KEY, new AttributeValue().withS(materialName)); ddbKey.put(DEFAULT_RANGE_KEY, new AttributeValue().withN(Long.toString(version))); final Map<String, AttributeValue> item = ddbGet(ddbKey); if (item == null || item.isEmpty()) { throw new IndexOutOfBoundsException("No material found: " + materialName + "#" + version); } final Map<String, AttributeValue> plainText = getPlainText(item); final Map<String, AttributeValue> encryptedText = targetMetaStore.getEncryptedText(plainText); final PutItemRequest put = new PutItemRequest().withTableName(targetMetaStore.tableName).withItem(encryptedText) .withExpected(doesNotExist); targetMetaStore.ddb.putItem(put); } catch (ConditionalCheckFailedException e) { //Item already present. } } /**
/** * Inserts a new transaction item into the table. Assumes txKey is already initialized. * @return the txItem * @throws TransactionException if the transaction already exists */ private Map<String, AttributeValue> insert() { Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put(AttributeName.STATE.toString(), new AttributeValue(STATE_PENDING)); item.put(AttributeName.VERSION.toString(), new AttributeValue().withN(Integer.toString(1))); item.put(AttributeName.DATE.toString(), txManager.getCurrentTimeAttribute()); item.putAll(txKey); Map<String, ExpectedAttributeValue> expectNotExists = new HashMap<String, ExpectedAttributeValue>(2); expectNotExists.put(AttributeName.TXID.toString(), new ExpectedAttributeValue(false)); expectNotExists.put(AttributeName.STATE.toString(), new ExpectedAttributeValue(false)); PutItemRequest request = new PutItemRequest() .withTableName(txManager.getTransactionTableName()) .withItem(item) .withExpected(expectNotExists); try { txManager.getClient().putItem(request); return item; } catch (ConditionalCheckFailedException e) { throw new TransactionException("Failed to create new transaction with id " + txId, e); } }
txManager.getClient().putItem(new PutItemRequest() .withTableName(txManager.getItemImageTableName()) .withExpected(expected) .withItem(item)); } catch (ConditionalCheckFailedException e) {
/** * This API retrieves the intermediate keys from the source region and replicates it in the target region. * * @param materialName material name of the encryption material. * @param version version of the encryption material. * @param targetMetaStore target MetaStore where the encryption material to be stored. */ public void replicate(final String materialName, final long version, final MetaStore targetMetaStore) { try { Map<String, AttributeValue> item = getMaterialItem(materialName, version); final Map<String, AttributeValue> plainText = getPlainText(item); final Map<String, AttributeValue> encryptedText = targetMetaStore.getEncryptedText(plainText); final PutItemRequest put = new PutItemRequest().withTableName(targetMetaStore.tableName).withItem(encryptedText) .withExpected(doesNotExist); targetMetaStore.ddb.putItem(put); } catch (ConditionalCheckFailedException e) { //Item already present. } }
.withTableName(tableName) .withItem(itemImage) .withExpected(expected); txManager.getClient().putItem(put); } catch (ConditionalCheckFailedException e) {
/** * Save the item using a PutItem request. The handler will call this * method if * <ul> * <li> CLOBBER configuration is being used; * <li> OR the item contains auto-generated key value; * <li> OR an UpdateItem request has silently failed (200 response with * no affected attribute), which indicates the key-only-put scenario * that we used to handle by the keyOnlyPut(...) hack. * </ul> */ protected PutItemResult doPutItem() { Map<String, AttributeValue> attributeValues = convertToItem(getAttributeValueUpdates()); attributeValues = transformAttributes( toParameters(attributeValues, this.clazz, getTableName(), saveConfig)); PutItemRequest req = new PutItemRequest() .withTableName(getTableName()) .withItem(attributeValues) .withExpected(mergeExpectedAttributeValueConditions()) .withConditionalOperator(userProvidedConditionOperator) .withRequestMetricCollector(saveConfig.getRequestMetricCollector()); return db.putItem(applyUserAgent(req)); }
private PutItemOutcome doPutItem(PutItemSpec spec) { // set the table name String tableName = getTable().getTableName(); PutItemRequest req = spec.getRequest().withTableName(tableName); // set up the item Item item = spec.getItem(); final Map<String,AttributeValue> attributes = InternalUtils.toAttributeValues(item); // set up the expected attribute map, if any final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(spec.getExpected()); // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up the request req.withItem(attributes) .withExpected(expectedMap) .withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; PutItemResult result = getClient().putItem(req); return new PutItemOutcome(result); } }