List of usage examples for com.amazonaws.services.dynamodbv2.model PutItemRequest PutItemRequest
public PutItemRequest()
From source file:com.makariev.dynamodb.data.populators.ProductCatalogPopulator.java
License:Apache License
@Override public List<PutItemRequest> getPutItemRequests() { final List<PutItemRequest> requests = new ArrayList<>(); final String tableName = getTableName(); // Add books. {//from w ww . j ava 2s . c o m final Map<String, AttributeValue> item = new HashMap<>(); item.put("Id", new AttributeValue().withN("101")); item.put("Title", new AttributeValue().withS("Book 101 Title")); item.put("ISBN", new AttributeValue().withS("111-1111111111")); item.put("Authors", new AttributeValue().withSS(Arrays.asList("Author1"))); item.put("Price", new AttributeValue().withN("2")); item.put("Dimensions", new AttributeValue().withS("8.5 x 11.0 x 0.5")); item.put("PageCount", new AttributeValue().withN("500")); item.put("InPublication", new AttributeValue().withN("1")); item.put("ProductCategory", new AttributeValue().withS("Book")); final PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); requests.add(itemRequest); } { final Map<String, AttributeValue> item = new HashMap<>(); item.put("Id", new AttributeValue().withN("102")); item.put("Title", new AttributeValue().withS("Book 102 Title")); item.put("ISBN", new AttributeValue().withS("222-2222222222")); item.put("Authors", new AttributeValue().withSS(Arrays.asList("Author1", "Author2"))); item.put("Price", new AttributeValue().withN("20")); item.put("Dimensions", new AttributeValue().withS("8.5 x 11.0 x 0.8")); item.put("PageCount", new AttributeValue().withN("600")); item.put("InPublication", new AttributeValue().withN("1")); item.put("ProductCategory", new AttributeValue().withS("Book")); final PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); requests.add(itemRequest); } { final Map<String, AttributeValue> item = new HashMap<>(); item.put("Id", new AttributeValue().withN("103")); item.put("Title", new AttributeValue().withS("Book 103 Title")); item.put("ISBN", new AttributeValue().withS("333-3333333333")); item.put("Authors", new AttributeValue().withSS(Arrays.asList("Author1", "Author2"))); // Intentional. Later we run scan to find price error. Find items > 1000 in price. item.put("Price", new AttributeValue().withN("2000")); item.put("Dimensions", new AttributeValue().withS("8.5 x 11.0 x 1.5")); item.put("PageCount", new AttributeValue().withN("600")); item.put("InPublication", new AttributeValue().withN("0")); item.put("ProductCategory", new AttributeValue().withS("Book")); final PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); requests.add(itemRequest); } { final Map<String, AttributeValue> item = new HashMap<>(); // Add bikes. item.put("Id", new AttributeValue().withN("201")); item.put("Title", new AttributeValue().withS("18-Bike-201")); // Size, followed by some title. item.put("Description", new AttributeValue().withS("201 Description")); item.put("BicycleType", new AttributeValue().withS("Road")); item.put("Brand", new AttributeValue().withS("Mountain A")); // Trek, Specialized. item.put("Price", new AttributeValue().withN("100")); item.put("Gender", new AttributeValue().withS("M")); // Men's item.put("Color", new AttributeValue().withSS(Arrays.asList("Red", "Black"))); item.put("ProductCategory", new AttributeValue().withS("Bicycle")); final PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); requests.add(itemRequest); } { final Map<String, AttributeValue> item = new HashMap<>(); item.put("Id", new AttributeValue().withN("202")); item.put("Title", new AttributeValue().withS("21-Bike-202")); item.put("Description", new AttributeValue().withS("202 Description")); item.put("BicycleType", new AttributeValue().withS("Road")); item.put("Brand", new AttributeValue().withS("Brand-Company A")); item.put("Price", new AttributeValue().withN("200")); item.put("Gender", new AttributeValue().withS("M")); item.put("Color", new AttributeValue().withSS(Arrays.asList("Green", "Black"))); item.put("ProductCategory", new AttributeValue().withS("Bicycle")); final PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); requests.add(itemRequest); } { final Map<String, AttributeValue> item = new HashMap<>(); item.put("Id", new AttributeValue().withN("203")); item.put("Title", new AttributeValue().withS("19-Bike-203")); item.put("Description", new AttributeValue().withS("203 Description")); item.put("BicycleType", new AttributeValue().withS("Road")); item.put("Brand", new AttributeValue().withS("Brand-Company B")); item.put("Price", new AttributeValue().withN("300")); item.put("Gender", new AttributeValue().withS("W")); // Women's item.put("Color", new AttributeValue().withSS(Arrays.asList("Red", "Green", "Black"))); item.put("ProductCategory", new AttributeValue().withS("Bicycle")); final PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); requests.add(itemRequest); } { final Map<String, AttributeValue> item = new HashMap<>(); item.put("Id", new AttributeValue().withN("204")); item.put("Title", new AttributeValue().withS("18-Bike-204")); item.put("Description", new AttributeValue().withS("204 Description")); item.put("BicycleType", new AttributeValue().withS("Mountain")); item.put("Brand", new AttributeValue().withS("Brand-Company B")); item.put("Price", new AttributeValue().withN("400")); item.put("Gender", new AttributeValue().withS("W")); item.put("Color", new AttributeValue().withSS(Arrays.asList("Red"))); item.put("ProductCategory", new AttributeValue().withS("Bicycle")); final PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); requests.add(itemRequest); } { final Map<String, AttributeValue> item = new HashMap<>(); item.put("Id", new AttributeValue().withN("205")); item.put("Title", new AttributeValue().withS("20-Bike-205")); item.put("Description", new AttributeValue().withS("205 Description")); item.put("BicycleType", new AttributeValue().withS("Hybrid")); item.put("Brand", new AttributeValue().withS("Brand-Company C")); item.put("Price", new AttributeValue().withN("500")); item.put("Gender", new AttributeValue().withS("B")); // Boy's item.put("Color", new AttributeValue().withSS(Arrays.asList("Red", "Black"))); item.put("ProductCategory", new AttributeValue().withS("Bicycle")); final PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); requests.add(itemRequest); } return requests; }
From source file:com.makariev.dynamodb.data.populators.ReplyPopulator.java
License:Apache License
@Override public List<PutItemRequest> getPutItemRequests() { final List<PutItemRequest> requests = new ArrayList<>(); final String tableName = getTableName(); final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); long time0 = (new Date()).getTime() - (1 * 24 * 60 * 60 * 1000); // 1 day ago long time1 = (new Date()).getTime() - (7 * 24 * 60 * 60 * 1000); // 7 days ago long time2 = (new Date()).getTime() - (14 * 24 * 60 * 60 * 1000); // 14 days ago long time3 = (new Date()).getTime() - (21 * 24 * 60 * 60 * 1000); // 21 days ago Date date0 = new Date(); date0.setTime(time0);// w w w . j ava 2s . com Date date1 = new Date(); date1.setTime(time1); Date date2 = new Date(); date2.setTime(time2); Date date3 = new Date(); date3.setTime(time3); // Add threads. { final Map<String, AttributeValue> reply = new HashMap<>(); reply.put("Id", new AttributeValue().withS("Amazon DynamoDB#DynamoDB Thread 1")); reply.put("ReplyDateTime", new AttributeValue().withS(dateFormatter.format(date3))); reply.put("Message", new AttributeValue().withS("DynamoDB Thread 1 Reply 1 text")); reply.put("PostedBy", new AttributeValue().withS("User A")); final PutItemRequest replyRequest = new PutItemRequest().withTableName(tableName).withItem(reply); requests.add(replyRequest); } { final Map<String, AttributeValue> reply = new HashMap<>(); reply.put("Id", new AttributeValue().withS("Amazon DynamoDB#DynamoDB Thread 1")); reply.put("ReplyDateTime", new AttributeValue().withS(dateFormatter.format(date2))); reply.put("Message", new AttributeValue().withS("DynamoDB Thread 1 Reply 2 text")); reply.put("PostedBy", new AttributeValue().withS("User B")); final PutItemRequest replyRequest = new PutItemRequest().withTableName(tableName).withItem(reply); requests.add(replyRequest); } { final Map<String, AttributeValue> reply = new HashMap<>(); reply.put("Id", new AttributeValue().withS("Amazon DynamoDB#DynamoDB Thread 2")); reply.put("ReplyDateTime", new AttributeValue().withS(dateFormatter.format(date1))); reply.put("Message", new AttributeValue().withS("DynamoDB Thread 2 Reply 1 text")); reply.put("PostedBy", new AttributeValue().withS("User A")); final PutItemRequest replyRequest = new PutItemRequest().withTableName(tableName).withItem(reply); requests.add(replyRequest); } { final Map<String, AttributeValue> reply = new HashMap<>(); reply.put("Id", new AttributeValue().withS("Amazon DynamoDB#DynamoDB Thread 2")); reply.put("ReplyDateTime", new AttributeValue().withS(dateFormatter.format(date0))); reply.put("Message", new AttributeValue().withS("DynamoDB Thread 2 Reply 2 text")); reply.put("PostedBy", new AttributeValue().withS("User A")); final PutItemRequest replyRequest = new PutItemRequest().withTableName(tableName).withItem(reply); requests.add(replyRequest); } return requests; }
From source file:com.makariev.dynamodb.data.populators.ThreadPopulator.java
License:Apache License
@Override public List<PutItemRequest> getPutItemRequests() { final List<PutItemRequest> requests = new ArrayList<>(); final String tableName = getTableName(); final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); long time1 = (new Date()).getTime() - (7 * 24 * 60 * 60 * 1000); // 7 days ago long time2 = (new Date()).getTime() - (14 * 24 * 60 * 60 * 1000); // 14 days ago long time3 = (new Date()).getTime() - (21 * 24 * 60 * 60 * 1000); // 21 days ago Date date1 = new Date(); date1.setTime(time1);//from w w w. jav a2 s.c om Date date2 = new Date(); date2.setTime(time2); Date date3 = new Date(); date3.setTime(time3); // Add threads. { final Map<String, AttributeValue> forum = new HashMap<>(); forum.put("ForumName", new AttributeValue().withS("Amazon DynamoDB")); forum.put("Subject", new AttributeValue().withS("DynamoDB Thread 1")); forum.put("Message", new AttributeValue().withS("DynamoDB thread 1 message")); forum.put("LastPostedBy", new AttributeValue().withS("User A")); forum.put("LastPostedDateTime", new AttributeValue().withS(dateFormatter.format(date2))); forum.put("Views", new AttributeValue().withN("0")); forum.put("Replies", new AttributeValue().withN("0")); forum.put("Answered", new AttributeValue().withN("0")); forum.put("Tags", new AttributeValue().withSS(Arrays.asList("index", "primarykey", "table"))); final PutItemRequest forumRequest = new PutItemRequest().withTableName(tableName).withItem(forum); requests.add(forumRequest); } { final Map<String, AttributeValue> forum = new HashMap<>(); forum.put("ForumName", new AttributeValue().withS("Amazon DynamoDB")); forum.put("Subject", new AttributeValue().withS("DynamoDB Thread 2")); forum.put("Message", new AttributeValue().withS("DynamoDB thread 2 message")); forum.put("LastPostedBy", new AttributeValue().withS("User A")); forum.put("LastPostedDateTime", new AttributeValue().withS(dateFormatter.format(date3))); forum.put("Views", new AttributeValue().withN("0")); forum.put("Replies", new AttributeValue().withN("0")); forum.put("Answered", new AttributeValue().withN("0")); forum.put("Tags", new AttributeValue().withSS(Arrays.asList("index", "primarykey", "rangekey"))); final PutItemRequest forumRequest = new PutItemRequest().withTableName(tableName).withItem(forum); requests.add(forumRequest); } { final Map<String, AttributeValue> forum = new HashMap<>(); forum.put("ForumName", new AttributeValue().withS("Amazon S3")); forum.put("Subject", new AttributeValue().withS("S3 Thread 1")); forum.put("Message", new AttributeValue().withS("S3 Thread 3 message")); forum.put("LastPostedBy", new AttributeValue().withS("User A")); forum.put("LastPostedDateTime", new AttributeValue().withS(dateFormatter.format(date1))); forum.put("Views", new AttributeValue().withN("0")); forum.put("Replies", new AttributeValue().withN("0")); forum.put("Answered", new AttributeValue().withN("0")); forum.put("Tags", new AttributeValue().withSS(Arrays.asList("largeobjects", "multipart upload"))); final PutItemRequest forumRequest = new PutItemRequest().withTableName(tableName).withItem(forum); requests.add(forumRequest); } return requests; }
From source file:com.makariev.dynamodb.preferences.UserPreferenceLowLevelAPIService.java
License:Open Source License
@Override public void save(UserPreference up) { final Map<String, AttributeValue> item = new HashMap<>(); AttributeValue userNo = new AttributeValue().withN(String.valueOf(up.getUserNo())); item.put("userNo", userNo); AttributeValue firstName = new AttributeValue().withS(up.getFirstName()); item.put("firstName", firstName); AttributeValue lastName = new AttributeValue().withS(up.getLastName()); item.put("lastName", lastName); PutItemRequest request = new PutItemRequest().withTableName(UserPreference.TABLE_NAME).withItem(item); dynamoDb.putItem(request);/* w w w . ja v a 2 s . c o m*/ }
From source file:com.tsatsatzu.subwar.game.logic.dynamo.DynamoIODriver.java
License:Apache License
/** * Do save user.//from www.j a v a2 s . c om * * @param user the user */ private void doSaveUser(SWUserBean user) { user.setNumberOfInteractions(user.getNumberOfInteractions() + 1); user.setLastInteraction(System.currentTimeMillis()); Map<String, AttributeValue> item = user.toMap(); PutItemRequest itemRequest = new PutItemRequest().withTableName(USER_TABLE_NAME).withItem(item); mClient.putItem(itemRequest); }
From source file:com.vitembp.embedded.configuration.CloudConfigSync.java
License:Open Source License
/** * Registers the device's ID to the database. * @throws IOException //from w w w . j a va 2 s. co m */ private static void registerDevice() throws IOException { // get configuration string String config; try { config = SystemConfig.getConfig().writeToString(); } catch (XMLStreamException ex) { throw new IOException("Could not generate configuration string.", ex); } // add holds data to store in table. Map<String, AttributeValue> itemToSet = new HashMap<>(); PutItemRequest pir = new PutItemRequest(); pir.setConditionExpression("attribute_not_exists(ID)"); // add the system ID itemToSet.put("ID", new AttributeValue(SystemConfig.getConfig().getSystemUUID().toString())); itemToSet.put("CONFIG", new AttributeValue(config)); itemToSet.put("UPDATED", new AttributeValue(Boolean.toString(false))); pir.setTableName("DEVICES"); pir.setItem(itemToSet); try { CloudConfigSync.client.putItem(pir); CloudConfigSync.deviceRegistered = true; LOGGER.info("Device successfully registered."); } catch (ConditionalCheckFailedException e) { CloudConfigSync.deviceRegistered = true; LOGGER.debug("Device already registered."); } catch (ResourceNotFoundException e) { LOGGER.error("The database does not contain the device index table.", e); } catch (AmazonServiceException e) { LOGGER.error("Exception occurred writing to database.", e); } }
From source file:Database.CustomerData.java
License:Open Source License
public static void uploadCustomer(String customerId, String customerName, String customerEmail, String product) throws Exception { init();//from w ww. java 2 s .c om try { Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put("Id", new AttributeValue(customerId)); item.put("Newstreams", new AttributeValue().withS(product)); item.put("CustomerEmail", new AttributeValue(customerEmail)); item.put("MemberName", new AttributeValue().withSS(customerName)); PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); item.clear(); } catch (AmazonServiceException ase) { System.err.println("Failed to create item in " + tableName + " " + ase); } }
From source file:Database.ProductData.java
License:Open Source License
private static void uploadSampleProducts(String tableName) { try {/*from www. ja va 2 s. c o m*/ // Add books. Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put("name", new AttributeValue("name1")); item.put("year", new AttributeValue().withN(Integer.toString(1984))); item.put("Title", new AttributeValue("title1")); item.put("Journalist", new AttributeValue().withSS("jName")); PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); item.clear(); item.put("name", new AttributeValue("name2")); item.put("year", new AttributeValue().withN(Integer.toString(1984))); item.put("Title", new AttributeValue("title2")); item.put("Journalist", new AttributeValue().withSS("jName")); itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); item.clear(); item.put("name", new AttributeValue("name3")); item.put("year", new AttributeValue().withN(Integer.toString(1984))); item.put("Title", new AttributeValue("title3")); item.put("Journalist", new AttributeValue().withSS("jName")); itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); item.clear(); // Add bikes. item.put("name", new AttributeValue("name1")); item.put("year", new AttributeValue().withN(Integer.toString(1984))); item.put("Title", new AttributeValue("title1")); item.put("Journalist", new AttributeValue().withSS("jName")); itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); item.clear(); item.put("name", new AttributeValue("name1")); item.put("year", new AttributeValue().withN(Integer.toString(1984))); item.put("Title", new AttributeValue("title1")); item.put("Journalist", new AttributeValue().withSS("jName")); itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); item.clear(); item.put("name", new AttributeValue("name1")); item.put("year", new AttributeValue().withN(Integer.toString(1984))); item.put("Title", new AttributeValue("title1")); item.put("Journalist", new AttributeValue().withSS("jName")); itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); item.clear(); item.put("name", new AttributeValue("name1")); item.put("year", new AttributeValue().withN(Integer.toString(1984))); item.put("Title", new AttributeValue("title1")); item.put("Journalist", new AttributeValue().withSS("jName")); itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); item.clear(); item.put("name", new AttributeValue("name1")); item.put("year", new AttributeValue().withN(Integer.toString(1984))); item.put("Title", new AttributeValue("title1")); item.put("Journalist", new AttributeValue().withSS("jName")); itemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDB.putItem(itemRequest); } catch (AmazonServiceException ase) { System.err.println("Failed to create item in " + tableName + " " + ase); } }
From source file:jp.xet.uncommons.spring.DynamoPersistentTokenRepository.java
License:Apache License
@Override public void createNewToken(PersistentRememberMeToken token) { Assert.notNull(token);//from w w w .j av a2s . c o m if (logger.isTraceEnabled()) { logger.trace("Create token: username={}, series={}, tokenValue={}, date={}", new Object[] { token.getUsername(), token.getSeries(), token.getTokenValue(), token.getDate() }); } try { Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put(USERNAME, new AttributeValue(token.getUsername())); item.put(SERIES, new AttributeValue(token.getSeries())); item.put(TOKEN, new AttributeValue(token.getTokenValue())); item.put(LAST_USED, new AttributeValue(DateUtils.formatISO8601Date(token.getDate()))); PutItemRequest putRequest = new PutItemRequest().withTableName(persistentLoginTable).withItem(item); PutItemResult result = dynamoDb.putItem(putRequest); if (logger.isDebugEnabled()) { logger.debug("Token created: {}", result); } } catch (Exception e) { logger.error("unknown exception", e); } }
From source file:kinesisadaptersample.StreamsAdapterDemoHelper.java
License:Open Source License
public static void putItem(AmazonDynamoDB dynamoDBClient, String tableName, String id, String val) { java.util.Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put("Id", new AttributeValue().withN(id)); item.put("attribute-1", new AttributeValue().withS(val)); PutItemRequest putItemRequest = new PutItemRequest().withTableName(tableName).withItem(item); dynamoDBClient.putItem(putItemRequest); }