List of usage examples for com.amazonaws.services.dynamodbv2.model AttributeValueUpdate AttributeValueUpdate
public AttributeValueUpdate()
From source file:com.rapid7.diskstorage.dynamodb.builder.SingleUpdateBuilder.java
License:Open Source License
public SingleUpdateBuilder put(StaticBuffer column, StaticBuffer value) { updates.put(encodeKeyBuffer(column), new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(encodeValue(value))); return this; }
From source file:com.rapid7.diskstorage.dynamodb.builder.SingleUpdateBuilder.java
License:Open Source License
public SingleUpdateBuilder delete(StaticBuffer column) { updates.put(encodeKeyBuffer(column), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); return this; }
From source file:com.vitembp.embedded.configuration.CloudConfigSync.java
License:Open Source License
/** * Checks if the configuration has changed. *///from w w w .j a v a 2 s . c o m private static void checkConfiguration() { // register the device if it is not in the table if (!CloudConfigSync.deviceRegistered) { try { CloudConfigSync.registerDevice(); } catch (IOException ex) { // log the error LOGGER.error("Could not register device.", ex); // do not continue we cannot update config if it is not registered return; } } // check if configuration has changed boolean hasChanged; String remoteConfig; // perform query Map<String, AttributeValue> reqkey = new HashMap<>(); reqkey.put("ID", new AttributeValue().withS(SystemConfig.getConfig().getSystemUUID().toString())); GetItemRequest request = new GetItemRequest().withTableName("DEVICES").withKey(reqkey) .withProjectionExpression("CONFIG,UPDATED"); // try to get the data GetItemResult result = client.getItem(request); if (result != null && result.getItem() != null) { // parse data from response if the table has the attributes Map<String, AttributeValue> attributes = result.getItem(); // can not continue if the UPDATED and CONFIG attributes are not // present in the table row if (!attributes.containsKey("UPDATED") || !attributes.containsKey("CONFIG")) { LOGGER.error("Configuration is not available in database."); return; } // attributes are present, get their values hasChanged = Boolean.parseBoolean(result.getItem().get("UPDATED").getS()); remoteConfig = result.getItem().get("CONFIG").getS(); } else { // query failed so do not continue LOGGER.error("Could not query configuration in databse."); return; } // update if tagged as changed, prefering the remote config over the local if (hasChanged) { try { loadConfigFromRemote(remoteConfig); } catch (XMLStreamException ex) { LOGGER.error("Could not update configuration.", ex); return; } // change updated to false Map<String, AttributeValue> keyAttribs = new HashMap<>(); keyAttribs.put("ID", new AttributeValue().withS(SystemConfig.getConfig().getSystemUUID().toString())); Map<String, AttributeValueUpdate> updateAttribs = new HashMap<>(); updateAttribs.put("UPDATED", new AttributeValueUpdate().withValue(new AttributeValue().withS(Boolean.toString(false))) .withAction(AttributeAction.PUT)); client.updateItem("DEVICES", keyAttribs, updateAttribs); LOGGER.info("Config updated flag set to false."); } else { // build local config to check if the local has changes not // in the remote config String localConfig; try { localConfig = SystemConfig.getConfig().writeToString(); } catch (XMLStreamException ex) { LOGGER.error("Could not create configuration string.", ex); return; } // update remote as needed if (!remoteConfig.equals(localConfig)) { // updated configuration with local Map<String, AttributeValue> keyAttribs = new HashMap<>(); keyAttribs.put("ID", new AttributeValue().withS(SystemConfig.getConfig().getSystemUUID().toString())); Map<String, AttributeValueUpdate> updateAttribs = new HashMap<>(); updateAttribs.put("CONFIG", new AttributeValueUpdate() .withValue(new AttributeValue().withS(localConfig)).withAction(AttributeAction.PUT)); client.updateItem("DEVICES", keyAttribs, updateAttribs); LOGGER.info("Remote config updated."); } } }
From source file:com.vitembp.embedded.interfaces.AmazonSQSControl.java
License:Open Source License
/** * Deletes a value from the DATA table./*from w w w.j av a 2s. c om*/ * @param location The location to delete in the table. * @param toWrite The data to write to the table row. * @throws IOException If an error occurs writing the data. */ private void writeData(UUID location, String toWrite) throws IOException { try { // build the request to put toWrite in VALUE at the ID location Map<String, AttributeValue> keyAttribs = new HashMap<>(); keyAttribs.put("ID", new AttributeValue().withS(location.toString())); Map<String, AttributeValueUpdate> updateAttribs = new HashMap<>(); updateAttribs.put("VALUE", new AttributeValueUpdate().withValue(new AttributeValue().withS(toWrite)) .withAction(AttributeAction.PUT)); // write the request to the DATA table client.updateItem("DATA", keyAttribs, updateAttribs); } catch (Exception ex) { throw new IOException( "Unexpected exception writing \"" + toWrite + "\" to location: " + location.toString(), ex); } }
From source file:com.vivastream.security.oauth2.common.util.DynamoDBUtils.java
License:Apache License
public static void nullSafeUpdateS(Map<String, AttributeValueUpdate> updates, String column, String value) { if (value == null || value.length() == 0) { updates.put(column, new AttributeValueUpdate().withAction(AttributeAction.DELETE)); } else {// w ww .ja v a2s. c o m updates.put(column, new AttributeValueUpdate(new AttributeValue(value), AttributeAction.PUT)); } }
From source file:doug.iotdemo.analyzer.Analyzer.java
License:Open Source License
void saveSensor(String sensor) throws IOException, MqttException { SensorData sensorData = data.get(sensor); if (sensorData != null) { UpdateItemRequest request = new UpdateItemRequest().withTableName(AmazonUtils.getSensorTableName()) .addKeyEntry("sensor", new AttributeValue().withS(sensor)) .addAttributeUpdatesEntry("time", new AttributeValueUpdate() .withValue(new AttributeValue().withN(Long.toString(sensorData.time))) .withAction(AttributeAction.PUT)) .addAttributeUpdatesEntry("count", new AttributeValueUpdate() .withValue(new AttributeValue().withN(Long.toString(sensorData.count))) .withAction(AttributeAction.PUT)); db.updateItem(request);// ww w. j av a 2s .com long thresh = sensorData.time / sensorData.count; mqtt.sendThreshold(sensor, thresh); } }
From source file:io.milton.s3.DynamoDBManagerImpl.java
License:Open Source License
/** * Move or rename entity to other folder * /*from w w w .java 2 s. com*/ * @param entity * - current entity want to move or rename * @param newParent * - parent of entity * @param newEntityName * - new name of entity * @param isRenamingAction * - TRUE is renaming file, otherwise FALSE * @return TRUE/FALSE */ @Override public boolean updateEntityByUniqueId(String tableName, Entity entity, Folder newParent, String newEntityName, boolean isRenamingAction) { HashMap<String, AttributeValue> primaryKey = new HashMap<String, AttributeValue>(); primaryKey.put(AttributeKey.UUID, new AttributeValue().withS(entity.getId().toString())); Map<String, AttributeValueUpdate> updateItems = new HashMap<String, AttributeValueUpdate>(); updateItems.put(AttributeKey.ENTITY_NAME, new AttributeValueUpdate().withAction(AttributeAction.PUT) .withValue(new AttributeValue().withS(newEntityName))); updateItems.put(AttributeKey.MODIFIED_DATE, new AttributeValueUpdate().withAction(AttributeAction.PUT) .withValue(new AttributeValue().withS(DateUtils.dateToString(new Date())))); if (!isRenamingAction) { updateItems.put(AttributeKey.PARENT_UUID, new AttributeValueUpdate().withAction(AttributeAction.PUT) .withValue(new AttributeValue().withS(newParent.getId().toString()))); } UpdateItemResult updateStatus = dynamoDBService.updateItem(tableName, primaryKey, updateItems); if (updateStatus != null) { return true; } return false; }
From source file:kinesisadaptersample.StreamsAdapterDemoHelper.java
License:Open Source License
public static void updateItem(AmazonDynamoDB dynamoDBClient, String tableName, String id, String val) { java.util.Map<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put("Id", new AttributeValue().withN(id)); Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>(); AttributeValueUpdate update = new AttributeValueUpdate().withAction(AttributeAction.PUT) .withValue(new AttributeValue().withS(val)); attributeUpdates.put("attribute-2", update); UpdateItemRequest updateItemRequest = new UpdateItemRequest().withTableName(tableName).withKey(key) .withAttributeUpdates(attributeUpdates); dynamoDBClient.updateItem(updateItemRequest); }
From source file:org.wildfly.camel.test.common.aws.DynamoDBUtils.java
License:Apache License
public static void updItem(CamelContext camelctx, String title) { HashMap<String, AttributeValue> key = new HashMap<>(); key.put("Id", new AttributeValue().withN("103")); HashMap<String, AttributeValueUpdate> updItem = new HashMap<>(); AttributeValueUpdate updValue = new AttributeValueUpdate(); updValue.setValue(new AttributeValue().withS(title)); updItem.put("Title", updValue); Exchange exchange = new ExchangeBuilder(camelctx) .withHeader(DdbConstants.OPERATION, DdbOperations.UpdateItem).withHeader(DdbConstants.KEY, key) .withHeader(DdbConstants.UPDATE_VALUES, updItem).build(); ProducerTemplate producer = camelctx.createProducerTemplate(); producer.send("direct:start", exchange); Assert.assertNull(exchange.getException()); }