Database Reference
In-Depth Information
//Creates a HASH condition equivalent to BookTitle=SCJP
Condition hashKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new
AttributeValue().withS("SCJP"));
Map<String, Condition> keyConditions = new HashMap<String,
Condition>();
keyConditions.put("BookTitle", hashKeyCondition);
QueryRequest queryRequest = new QueryRequest()
.withTableName("Tbl_Book")
.withKeyConditions(keyConditions);
QueryResult result = client.query(queryRequest);
The first parameter needed for the query operation is the comparison condition. So we
will create an instance of the
com.amazonaws.services.dynamodbv2.model.Condition class. We must
configure this instance with two mandatory parameters ( ComparisonOperator and
AttributeValue list).
The first parameter will be an instance of an enumerator available in the DynamoDB SDK
package
com.amazonaws.services.dynamodbv2.model.ComparisonOperator .
Here, we have configured it with EQ (whose description is given in the previous code
block's comment as well as at the beginning of this section).
The second parameter is the list of
com.amazonaws.services.dynamodbv2.model.AttributeValue . In the
case of EQ , it takes only one AttributeValue , which is SCJP. But, if we use
BETWEEN , then it will take two parameters. Then we create a map called keyCondi-
tions of the type Map<String, Condition> . Then we put the hash attribute
named BookTitle as the key and the condition instance we have configured earlier.
The previous code is the minimum parameter required to perform a query operation on a
table. First, we need to create an instance of the
com.amazonaws.services.dynamodbv2.model.QueryRequest (or the
latest version ) class, and then, to that instance, we need to add a few mandatory configur-
ation details such as table name, and optional details such as index name, scan filter, and
so on (which we will discuss later).
Search WWH ::




Custom Search