Databases Reference
In-Depth Information
Second, we have to implement the method that is used to fetch contact information
by using the key of the contact. We can implement the buildContact(String key)
method by following these steps:
1.
Create a new Contact object.
2.
Fetch the information of the contact from the hash.
We use bound hash operations because this way we
have to provide the key only once.
3.
Return the created object.
The source code of the implemented method is given as follows:
private Contact buildContact(String key) {
Contact contact = new Contact();
BoundHashops ops = redisTemplate.boundHashOps(key);
contact.setId((Long) ops.get("id"));
contact.setEmailAddress((String) ops.get("emailAddress"));
contact.setFirstName((String) ops.get("firstName"));
contact.setLastName((String) ops.get("lastName"));
contact.setPhoneNumber((String) ops.get("phoneNumber"));
Address address = new Address();
address.setStreetAddress((String) ops.get("streetAddress"));
address.setPostCode((String) ops.get("postCode"));
address.setPostOffice((String) ops.get("postOffice"));
address.setState((String) ops.get("state"));
address.setCountry((String) ops.get("country"));
contact.setAddress(address);
return contact;
}
Third, we have to implement the method that fetches contact information by using
the ID of the contact. Our implementation of the buildContact(Long id) method is
rather simple, and it includes the following steps:
1.
Build the key of the contact.
2.
Get the contact by using the created key.
3.
Return the found contact.
 
Search WWH ::




Custom Search