Posts

Showing posts from December 3, 2017

Accessing database in AWS - Part 2 ( Refactoring your code )

I have refactored the code to as below. As you can see, I have refactored getRegistration into two methods. The first method is generic so that tomorrow if you want to use GetLoans, we could use the generic method. And also the method "getRegistration" now uses the generic method " getValueFromDatabase". I am using the scan method of AWS ( which is more intensive) than query because I have to search on a column which is NOT a partition key. If it was a partition key, I could have used "query" instead of "scan". I am using  if (scanResult.getCount() != 0) break;    to return from the scan immediately as soon as I get one result. Else it would scan the entire database and I would get a "Throughput exceeded violation/error" from AWS. import com.amazonaws.regions.Regions; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; import com.amazonaws.services....