Java Code Examples for com.googlecode.objectify.Key#getId()

The following examples show how to use com.googlecode.objectify.Key#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BillingEvent.java    From nomulus with Apache License 2.0 6 votes vote down vote up
public static VKey<OneTime> createVKey(Key<OneTime> key) {
  // TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary
  // key type for the table, which is a single long integer.
  if (key == null) {
    return null;
  }
  Key parent = key.getParent();
  Key grandparent = (parent != null) ? parent.getParent() : null;
  String path =
      (grandparent != null ? grandparent.getName() : "")
          + "/"
          + (parent != null ? parent.getId() : "")
          + "/"
          + key.getId();
  return VKey.create(OneTime.class, path, key);
}
 
Example 2
Source File: PollMessage.java    From nomulus with Apache License 2.0 5 votes vote down vote up
public static VKey<PollMessage> createVKey(Key<PollMessage> key) {
  // TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary key
  // type for the table, which is a single long integer.  Also note that the class id is not
  // correct here and as such the resulting key will not be loadable from SQL.
  if (key == null) {
    return null;
  }
  String path =
      key.getParent().getParent().getName() + "/" + key.getParent().getId() + key.getId();
  return VKey.create(PollMessage.class, path, key);
}
 
Example 3
Source File: BillingEvent.java    From nomulus with Apache License 2.0 5 votes vote down vote up
public static VKey<Recurring> createVKey(Key<Recurring> key) {
  // TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary
  // key type for the table, which is a single long integer.
  if (key == null) {
    return null;
  }
  String path =
      key.getParent().getParent().getName() + "/" + key.getParent().getId() + "/" + key.getId();
  return VKey.create(Recurring.class, path, key);
}
 
Example 4
Source File: BillingEvent.java    From nomulus with Apache License 2.0 5 votes vote down vote up
public static VKey<Cancellation> createVKey(Key<Cancellation> key) {
  // TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary
  // key type for the table, which is a single long integer.
  if (key == null) {
    return null;
  }
  String path =
      key.getParent().getParent().getName() + "/" + key.getParent().getId() + "/" + key.getId();
  return VKey.create(Cancellation.class, path, key);
}
 
Example 5
Source File: BillingEvent.java    From nomulus with Apache License 2.0 5 votes vote down vote up
public static VKey<Modification> createVKey(Key<Modification> key) {
  // TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary
  // key type for the table, which is a single long integer.
  if (key == null) {
    return null;
  }
  String path =
      key.getParent().getParent().getName() + "/" + key.getParent().getId() + "/" + key.getId();
  return VKey.create(Modification.class, path, key);
}
 
Example 6
Source File: EmailServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
private long registerEmailNotification(EmailConfig email, boolean success) {
  EmailNotification emailNotification = new EmailNotification();
  emailNotification.setRecipients(Arrays.asList(email.getTo()));
  emailNotification.setReason(email.getReason());
  emailNotification.setTimestampSend(new Date());
  emailNotification.setEmailStatus(success ? "SUCCESS" : "FAILURE");

  Key<EmailNotification> key = emailNotificationDao.add(emailNotification);
  return key.getId();
}
 
Example 7
Source File: CommitLogManifest.java    From nomulus with Apache License 2.0 4 votes vote down vote up
/** Returns the commit time encoded into a CommitLogManifest key. */
public static DateTime extractCommitTime(Key<CommitLogManifest> manifestKey) {
  return new DateTime(manifestKey.getId(), UTC);
}
 
Example 8
Source File: ConferenceApi.java    From ud859 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new Conference object and stores it to the datastore.
 *
 * @param user A user who invokes this method, null when the user is not signed in.
 * @param conferenceForm A ConferenceForm object representing user's inputs.
 * @return A newly created Conference Object.
 * @throws UnauthorizedException when the user is not signed in.
 */
@ApiMethod(name = "createConference", path = "conference", httpMethod = HttpMethod.POST)
public Conference createConference(final User user, final ConferenceForm conferenceForm)
    throws UnauthorizedException {
    if (user == null) {
        throw new UnauthorizedException("Authorization required");
    }

    // TODO (Lesson 4)
    // Get the userId of the logged in User
    String userId = user.getUserId();

    // TODO (Lesson 4)
    // Get the key for the User's Profile
    Key<Profile> profileKey = Key.create(Profile.class, userId);

    // TODO (Lesson 4)
    // Allocate a key for the conference -- let App Engine allocate the ID
    // Don't forget to include the parent Profile in the allocated ID
    final Key<Conference> conferenceKey = factory().allocateId(profileKey, Conference.class);

    // TODO (Lesson 4)
    // Get the Conference Id from the Key
    final long conferenceId = conferenceKey.getId();

    // TODO (Lesson 4)
    // Get the existing Profile entity for the current user if there is one
    // Otherwise create a new Profile entity with default values
    Profile profile = getProfileFromUser(user);

    // TODO (Lesson 4)
    // Create a new Conference Entity, specifying the user's Profile entity
    // as the parent of the conference
    Conference conference = new Conference(conferenceId, userId, conferenceForm);

    // TODO (Lesson 4)
    // Save Conference and Profile Entities
     ofy().save().entities(conference, profile).now();

     return conference;
     }