List of usage examples for com.amazonaws.services.dynamodbv2.model AttributeValueUpdate AttributeValueUpdate
public AttributeValueUpdate(AttributeValue value, AttributeAction action)
From source file:aws.example.dynamodb.UpdateItem.java
License:Open Source License
public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " UpdateItem <table> <name> <greeting>\n\n" + "Where:\n" + " table - the table to put the item in.\n" + " name - a name to update in the table. The name must exist,\n" + " or an error will result.\n" + "Additional fields can be specified by appending them to the end of the\n" + "input.\n\n" + "Examples:\n" + " UpdateItem SiteColors text default=000000 bold=b22222\n" + " UpdateItem SiteColors background default=eeeeee code=d3d3d3\n\n"; if (args.length < 3) { System.out.println(USAGE); System.exit(1);//from www . j a v a2 s.co m } String table_name = args[0]; String name = args[1]; ArrayList<String[]> extra_fields = new ArrayList<String[]>(); // any additional args (fields to add or update)? for (int x = 2; x < args.length; x++) { String[] fields = args[x].split("=", 2); if (fields.length == 2) { extra_fields.add(fields); } else { System.out.format("Invalid argument: %s\n", args[x]); System.out.println(USAGE); System.exit(1); } } System.out.format("Updating \"%s\" in %s\n", name, table_name); if (extra_fields.size() > 0) { System.out.println("Additional fields:"); for (String[] field : extra_fields) { System.out.format(" %s: %s\n", field[0], field[1]); } } HashMap<String, AttributeValue> item_key = new HashMap<String, AttributeValue>(); item_key.put("Name", new AttributeValue(name)); HashMap<String, AttributeValueUpdate> updated_values = new HashMap<String, AttributeValueUpdate>(); for (String[] field : extra_fields) { updated_values.put(field[0], new AttributeValueUpdate(new AttributeValue(field[1]), AttributeAction.PUT)); } final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(); try { ddb.updateItem(table_name, item_key, updated_values); } catch (ResourceNotFoundException e) { System.err.println(e.getMessage()); System.exit(1); } catch (AmazonServiceException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("Done!"); }
From source file:com.dell.doradus.db.dynamodb.DDBTransaction.java
License:Apache License
private void updateRowColumnUpdates(String storeName, Map<String, AttributeValue> key, List<DColumn> colList) { Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<>(); for (DColumn col : colList) { AttributeValue attrValue = mapColumnValue(storeName, col); attributeUpdates.put(col.getName(), new AttributeValueUpdate(attrValue, AttributeAction.PUT)); }//from w w w.ja va 2s. c o m m_service.updateRow(storeName, key, attributeUpdates); }
From source file:com.erudika.para.persistence.AWSDynamoDAO.java
License:Apache License
private void updateRow(String key, String appid, Map<String, AttributeValue> row) { if (StringUtils.isBlank(key) || StringUtils.isBlank(appid) || row == null || row.isEmpty()) { return;//from ww w .j av a 2 s .c o m } Map<String, AttributeValueUpdate> rou = new HashMap<String, AttributeValueUpdate>(); try { for (Entry<String, AttributeValue> attr : row.entrySet()) { rou.put(attr.getKey(), new AttributeValueUpdate(attr.getValue(), AttributeAction.PUT)); } UpdateItemRequest updateItemRequest = new UpdateItemRequest(getTableNameForAppid(appid), Collections.singletonMap(Config._KEY, new AttributeValue(getKeyForAppid(key, appid))), rou); client().updateItem(updateItemRequest); } catch (Exception e) { logger.error("Could not update row in DB - appid={}, key={}", appid, key, e); } }
From source file:com.nandanu.halomama.controller.DynamoDBRouter.java
License:Open Source License
public void incrementSeen(String userNameTwitter, String createdDate) { UpdateItemRequest upd = new UpdateItemRequest(); upd.setTableName(Constants.TABLE_NAME); AttributeValue unt = new AttributeValue(); unt.setS(userNameTwitter);/*from ww w.j a v a 2 s. c om*/ AttributeValue cd = new AttributeValue(); cd.setS(createdDate); upd.addKeyEntry(Constants.TAG_USERNAME, unt); upd.addKeyEntry(Constants.TAG_CREATED_DATE, cd); AttributeValue s = new AttributeValue(); s.setN("1"); AttributeValueUpdate seen = new AttributeValueUpdate(s, AttributeAction.ADD); upd.addAttributeUpdatesEntry(Constants.TAG_SEEN, seen); dDBClient.updateItem(upd); }
From source file:com.vivastream.security.oauth2.provider.token.store.DynamoDBTokenStore.java
License:Apache License
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { String refreshToken = null;// w w w. j a v a 2 s . co m if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } // the JdbcTokenStore removes the existing token for this token_id [if it exists] // We'll avoid doing so for now, unless a compelling reason to do otherwise presents itself // if (readAccessToken(token.getValue()) != null) { // removeAccessToken(token.getValue()); // } Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>(); updates.put(schema.getAccessColumnToken(), new AttributeValueUpdate( new AttributeValue().withB(serializeAccessToken(token)), AttributeAction.PUT)); DynamoDBUtils.nullSafeUpdateS(updates, schema.getAccessColumnAuthenticationId(), authenticationKeyGenerator.extractKey(authentication)); if (authentication.isClientOnly() || authentication.getName() == null || authentication.getName().length() == 0) { DynamoDBUtils.nullSafeUpdateS(updates, schema.getAccessColumnUserName(), schema.getAccessNullUserToken()); updates.put(schema.getAccessColumnIsNullUser(), new AttributeValueUpdate( new AttributeValue().withN(schema.getAccessIsNullUserTrueToken()), AttributeAction.PUT)); } else { DynamoDBUtils.nullSafeUpdateS(updates, schema.getAccessColumnUserName(), authentication.getName()); DynamoDBUtils.nullSafeUpdateS(updates, schema.getAccessColumnIsNullUser(), null); } DynamoDBUtils.nullSafeUpdateS(updates, schema.getAccessColumnClientId(), authentication.getOAuth2Request().getClientId()); updates.put(schema.getAccessColumnAuthentication(), new AttributeValueUpdate( new AttributeValue().withB(serializeAuthentication(authentication)), AttributeAction.PUT)); DynamoDBUtils.nullSafeUpdateS(updates, schema.getAccessColumnRefreshToken(), extractTokenKey(refreshToken)); dynamoDBTemplate.update(schema.getAccessTableName(), // Collections.singletonMap(schema.getAccessColumnTokenId(), new AttributeValue(extractTokenKey(token.getValue()))), // updates); }
From source file:com.vivastream.security.oauth2.provider.token.store.DynamoDBTokenStore.java
License:Apache License
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) { Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>(); updates.put(schema.getRefreshColumnToken(), new AttributeValueUpdate( new AttributeValue().withB(serializeRefreshToken(refreshToken)), AttributeAction.PUT)); updates.put(schema.getRefreshColumnAuthentication(), new AttributeValueUpdate( new AttributeValue().withB(serializeAuthentication(authentication)), AttributeAction.PUT)); dynamoDBTemplate.update(schema.getRefreshTableName(), // Collections.singletonMap(schema.getRefreshColumnTokenId(), new AttributeValue(extractTokenKey(refreshToken.getValue()))), // updates);//from w ww . ja va 2 s.c om }
From source file:doug.iotdemo.lambda.sensor.SensorLambda.java
License:Open Source License
private void handleStateChange(JsonObject request) throws IOException { UpdateItemRequest updateRequest = new UpdateItemRequest().withTableName(sensorTableName) .addKeyEntry("sensor", new AttributeValue().withS(request.get("sensor").getAsString())) .addAttributeUpdatesEntry("state", new AttributeValueUpdate( new AttributeValue().withN(Integer.toString(request.get("state").getAsInt())), AttributeAction.PUT)); db.updateItem(updateRequest);/*w w w. ja v a 2 s .com*/ System.out.println("Sensor table updated"); }
From source file:jp.xet.uncommons.spring.DynamoPersistentTokenRepository.java
License:Apache License
@Override public void updateToken(String series, String tokenValue, Date lastUsed) { if (logger.isTraceEnabled()) { logger.trace("Update token: series={}, tokenValue={}, lastUsed={}", new Object[] { series, tokenValue, lastUsed }); }/* ww w .j av a 2s. c om*/ try { String now = DateUtils.formatISO8601Date(new Date()); Map<String, AttributeValueUpdate> attributeUpdates = Maps.newHashMapWithExpectedSize(2); attributeUpdates.put(TOKEN, new AttributeValueUpdate(new AttributeValue(tokenValue), AttributeAction.PUT)); attributeUpdates.put(LAST_USED, new AttributeValueUpdate(new AttributeValue(now), AttributeAction.PUT)); UpdateItemRequest updateRequest = new UpdateItemRequest().withTableName(persistentLoginTable) .withKey(Collections.singletonMap(SERIES, new AttributeValue(series))) .withAttributeUpdates(attributeUpdates); UpdateItemResult result = dynamoDb.updateItem(updateRequest); if (logger.isDebugEnabled()) { logger.debug("Token updated: {}", result); } } catch (Exception e) { logger.error("unknown exception", e); } }