List of usage examples for com.amazonaws.services.dynamodbv2.model ScanRequest ScanRequest
public ScanRequest(String tableName)
From source file:AmazonDynamoDBSample_PutThrottled.java
License:Open Source License
public static void main(String[] args) throws Exception { init();/*from w w w . j av a2 s . c o m*/ try { String tableName = "my-favorite-movies-table"; // Create a table with a primary hash key named 'name', which holds // a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); // Create table if it does not exist yet TableUtils.createTableIfNotExists(dynamoDB, createTableRequest); // wait for the table to move into ACTIVE state TableUtils.waitUntilActive(dynamoDB, tableName); // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); // Add an item Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara"); PutItemRequest putItemRequest = new PutItemRequest(tableName, item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Add another item item = newItem("Airplane", 1980, "*****", "James", "Billy Bob"); putItemRequest = new PutItemRequest(tableName, item); putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); Thread[] thrds = new Thread[16]; for (int i = 0; i < thrds.length; i++) { thrds[i] = newItemCreationThread(tableName, i); thrds[i].start(); } for (Thread thrd : thrds) { thrd.join(); } // Scan items for movies with a year attribute greater than 1985 HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withN("1985")); scanFilter.put("year", condition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Result: " + scanResult); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:RandomQuery1OnDynamoDB.java
License:Open Source License
public static void main(String[] args) throws Exception { init();/*from ww w.j ava2 s .c o m*/ try { // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); System.out.println("Table count :" + tableDescription.getItemCount()); long lStartTime = new Date().getTime(); System.out.println("start time: " + lStartTime); Random rn = new Random(); // Scan items for movies with a year attribute greater than 1985 Long lItem = tableDescription.getItemCount(); int iNoOfItems = lItem.intValue(); System.out.println("no of item " + lItem); for (int i = 0; i <= 49999; i++) { String randomInt = Integer.toString(rn.nextInt(iNoOfItems)); HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue().withN(randomInt)); scanFilter.put("id", condition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Random No :" + randomInt + ":: Query no: " + (i + 1)); } // calculate time difference for update file time long lEndTime = new Date().getTime(); long difference = lEndTime - lStartTime; System.out.println("Elapsed milliseconds: " + difference); System.out.println("Elapsed seconds: " + difference * 0.001); System.out.println("Elapsed Minutes: " + (int) ((difference / (1000 * 60)) % 60)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:RandomQuery2OnDynamoDB.java
License:Open Source License
public static void main(String[] args) throws Exception { init();/*from w w w . jav a2 s .co m*/ try { // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); long lStartTime = new Date().getTime(); System.out.println("start time: " + lStartTime); Random rn = new Random(); Long lItem = tableDescription.getItemCount(); int iNoOfItems = lItem.intValue(); int iPointOnePercent = (int) ((int) iNoOfItems * 0.001); int iOnePercent = (int) ((int) iNoOfItems * 0.01); System.out.println("TotalItems:" + iNoOfItems + "::0.1% of data is :: " + iPointOnePercent + "::1% of data is :" + iOnePercent); // Generating 25000 random queries for 0.1 to 1 % of the data for (int i = 0; i <= 24999; i++) { String randomInt = Integer.toString(rn.nextInt(iOnePercent - iPointOnePercent) + iPointOnePercent); HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue().withN(randomInt)); scanFilter.put("id", condition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Random No :" + randomInt + ":: Query no: " + (i + 1)); } // calculate time difference for update file time long lEndTime = new Date().getTime(); long difference = lEndTime - lStartTime; System.out.println("Elapsed milliseconds: " + difference); System.out.println("Elapsed seconds: " + difference * 0.001); System.out.println("Elapsed Minutes: " + (int) ((difference / (1000 * 60)) % 60)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:awslabs.lab51.SolutionCode.java
License:Open Source License
@Override public List<Map<String, AttributeValue>> getImageItems(AmazonDynamoDBClient dynamoDbClient) { try {//from w w w. j a v a2s.c o m String tableName = System.getProperty("SESSIONTABLE"); String keyPrefix = System.getProperty("PARAM3"); ScanRequest scanRequest = new ScanRequest(tableName).withSelect("ALL_ATTRIBUTES"); if (!keyPrefix.isEmpty()) { Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("Key", new Condition().withAttributeValueList(new AttributeValue().withS(keyPrefix)) .withComparisonOperator("BEGINS_WITH")); scanRequest.withScanFilter(scanFilter); } return dynamoDbClient.scan(scanRequest).getItems(); } catch (Exception ex) { labController.logMessageToPage("getImageItems Error: " + ex.getMessage() + ":" + ex.getStackTrace()); return null; } }
From source file:br.com.faccilitacorretor.middleware.dynamo.AmazonDynamoDBSample.java
License:Open Source License
public static void main(String[] args) throws Exception { init();//from w ww .j av a 2s.co m try { String tableName = "my-favorite-movies-table"; // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else { // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.awaitTableToBecomeActive(dynamoDB, tableName); } // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); // Add an item Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara"); PutItemRequest putItemRequest = new PutItemRequest(tableName, item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Add another item item = newItem("Airplane", 1980, "*****", "James", "Billy Bob"); putItemRequest = new PutItemRequest(tableName, item); putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Scan items for movies with a year attribute greater than 1985 HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withN("1985")); scanFilter.put("year", condition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Result: " + scanResult); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.app.dynamoDb.DynamoFacebookUsers.java
License:Open Source License
public boolean isExist(String UserID) { ScanRequest scanRequest = new ScanRequest("FacebookUsers"); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("UserID", new Condition().withAttributeValueList(new AttributeValue(UserID)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { if (!(item.isEmpty())) return true; }/*from w w w . j a va 2s .c o m*/ return false; }
From source file:com.app.dynamoDb.DynamoFacebookUsers.java
License:Open Source License
public String getUserName(String UserID) { String result = ""; ScanRequest scanRequest = new ScanRequest("FacebookUsers"); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("UserID", new Condition().withAttributeValueList(new AttributeValue(UserID)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { System.out.println(item.get("UserName")); result = item.get("UserName").toString(); }/* w w w . j ava2s. c o m*/ return result; }
From source file:com.app.dynamoDb.DynamoFacebookUsers.java
License:Open Source License
public AttributeValue getUserID(String UserName) { ScanRequest scanRequest = new ScanRequest("FacebookUsers"); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("Email", new Condition().withAttributeValueList(new AttributeValue(UserName)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { return item.get("UserID"); }/*from w w w. j a v a2s . com*/ return null; }
From source file:com.app.dynamoDb.DynamoUser.java
License:Open Source License
@SuppressWarnings("null") public void insert(String UserName, String Password, String Email) { ScanRequest scanRequest = new ScanRequest("Users"); ScanResult scanResult = dynamoDB.scan(scanRequest); int s[] = new int[100]; int i = 0;/*w w w . ja v a 2s . co m*/ for (Map<String, AttributeValue> item : scanResult.getItems()) { s[i] = Integer.valueOf(item.get("UserID").getS()); i++; } Arrays.sort(s); int max = s[s.length - 1]; String userid = String.valueOf(max + 1); Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put("UserID", new AttributeValue(userid)); item.put("UserName", new AttributeValue(UserName)); item.put("Password", new AttributeValue(Password)); item.put("Email", new AttributeValue(Email)); this.setUserID(userid); this.setUserName(UserName); this.setPassword(Password); this.setEmail(Email); PutItemRequest putItemRequest = new PutItemRequest("Users", item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); }
From source file:com.app.dynamoDb.DynamoUser.java
License:Open Source License
public boolean validateEmail(String Email, String Password) { ScanRequest scanRequest = new ScanRequest("Users"); scanRequest.setConditionalOperator(ConditionalOperator.AND); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("Email", new Condition().withAttributeValueList(new AttributeValue(Email)) .withComparisonOperator(ComparisonOperator.EQ)); scanFilter.put("Password", new Condition().withAttributeValueList(new AttributeValue(Password)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { //System.out.println(item); if (!item.isEmpty()) return true; }// w w w . j a v a 2s . c o m return false; }