Ejemplo n.º 1
0
  /**
   * Print the user profiles and actions for all users with the provided last name
   *
   * <p>This method demonstrates how to open a scanner with a start key. It's using the composite
   * dao, so the records it returns will be a composite of both the profile model and actions model.
   *
   * @param lastName The last name of users to scan.
   */
  public void printUserProfileActionsForLastName(String lastName) {
    // Create a partial key that will allow us to start the scanner from the
    // first user record that has last name equal to the one provided.
    PartitionKey startKey = userProfileActionsDao.getPartitionStrategy().partitionKey("lastName");

    // Get the scanner with the start key. Null for stopKey in the getScanner
    // method indicates that the scanner will scan to the end of the table. Our
    // loop will break out when it encounters a record without the last name.

    EntityScanner<UserProfileActionsModel> scanner =
        userProfileActionsDao.getScanner(startKey, null);
    scanner.open();
    try {
      // scan until we find a last name not equal to the one provided
      for (UserProfileActionsModel entity : scanner) {
        if (!entity.getUserProfileModel().getLastName().equals(lastName)) {
          // last name of row different, break out of the scan.
          break;
        }
        System.out.println(entity.toString());
      }
    } finally {
      // scanners need to be closed.
      scanner.close();
    }
  }
Ejemplo n.º 2
0
 /**
  * Print all user profiles.
  *
  * <p>This method demonstrates how to open a scanner that will scan the entire table. It has no
  * start or stop keys specified.
  */
 public void printUserProfies() {
   EntityScanner<UserProfileModel> scanner = userProfileDao.getScanner();
   scanner.open();
   try {
     for (UserProfileModel entity : scanner) {
       System.out.println(entity.toString());
     }
   } finally {
     // scanners need to be closed.
     scanner.close();
   }
 }