Java Code Examples for com.googlecode.objectify.Objectify#put()

The following examples show how to use com.googlecode.objectify.Objectify#put() . 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: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
private UserData createUser(Objectify datastore, String userId, String email) {
  String emaillower = null;
  if (email != null) {
    emaillower = email.toLowerCase();
  }
  UserData userData = new UserData();
  userData.id = userId;
  userData.tosAccepted = false;
  userData.settings = "";
  userData.email = email == null ? "" : email;
  userData.name = User.getDefaultName(email);
  userData.type = User.USER;
  userData.link = "";
  userData.emaillower = email == null ? "" : emaillower;
  userData.emailFrequency = User.DEFAULT_EMAIL_NOTIFICATION_FREQUENCY;
  datastore.put(userData);
  return userData;
}
 
Example 2
Source File: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
private void addUserFileContents(Objectify datastore, String userId, String fileName, byte[] content) {
  UserFileData ufd = datastore.find(userFileKey(userKey(userId), fileName));
  byte [] empty = new byte[] { (byte)0x5b, (byte)0x5d }; // "[]" in bytes
  if (ufd == null) {          // File doesn't exist
    if (fileName.equals(StorageUtil.USER_BACKPACK_FILENAME) &&
      Arrays.equals(empty, content)) {
      return;                 // Nothing to do
    }
    ufd = new UserFileData();
    ufd.fileName = fileName;
    ufd.userKey = userKey(userId);
  } else {
    if (fileName.equals(StorageUtil.USER_BACKPACK_FILENAME) &&
      Arrays.equals(empty, content)) {
      // Storing an empty backback, just delete the file
      datastore.delete(userFileKey(userKey(userId), fileName));
      return;
    }
  }
  ufd.content = content;
  datastore.put(ufd);
}
 
Example 3
Source File: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
private void addFilesToProject(Objectify datastore, long projectId, FileData.RoleEnum role,
  boolean changeModDate, String userId, String... fileNames) {
  List<FileData> addedFiles = new ArrayList<FileData>();
  Key<ProjectData> projectKey = projectKey(projectId);
  for (String fileName : fileNames) {
    FileData fd = createProjectFile(datastore, projectKey, role, fileName);
    if (fd != null) {
      fd.userId = userId;
      addedFiles.add(fd);
    }
  }
  datastore.put(addedFiles); // batch put
  if (changeModDate) {
    updateProjectModDate(datastore, projectId, false);
  }
}
 
Example 4
Source File: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
private long updateProjectModDate(Objectify datastore, long projectId, boolean doingConversion) {
  long modDate = System.currentTimeMillis();
  ProjectData pd = datastore.find(projectKey(projectId));
  if (pd != null) {
    // Only update the ProjectData dateModified if it is more then a minute
    // in the future. Do this to avoid unnecessary datastore puts.
    // Also do not update modification time when doing conversion from
    // blobstore to GCS
    if ((modDate > (pd.dateModified + 1000*60)) && !doingConversion) {
      pd.dateModified = modDate;
      datastore.put(pd);
    } else {
      // return the (old) dateModified
      modDate = pd.dateModified;
    }
    return modDate;
  } else {
    throw CrashReport.createAndLogError(LOG, null, null,
        new IllegalArgumentException("project " + projectId + " doesn't exist"));
  }
}
 
Example 5
Source File: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void createRawUserFile(String userId, String fileName, byte[] content) {
  Objectify datastore = ObjectifyService.begin();
  UserFileData ufd = createUserFile(datastore, userKey(userId), fileName);
  if (ufd != null) {
    ufd.content = content;
    datastore.put(ufd);
  }
}
 
Example 6
Source File: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
public void doUpgrade(String userId) {
  if (!conversionEnabled)     // Unless conversion is enabled...
    return;                   // shouldn't really ever happen but...
  Objectify datastore = ObjectifyService.begin();
  UserData userData = datastore.find(userKey(userId));
  if ((userData.upgradedGCS && useGcs) ||
    (!userData.upgradedGCS && !useGcs))
    return;                   // All done, another task did it!
  List<Long> projectIds = getProjects(userId);
  boolean anyFailed = false;
  for (long projectId : projectIds) {
    for (FileData fd : datastore.query(FileData.class).ancestor(projectKey(projectId))) {
      if (fd.isBlob) {
        if (useGcs) {         // Let's convert by just reading it!
          downloadRawFile(userId, projectId, fd.fileName);
        }
      } else if (isTrue(fd.isGCS)) {
        if (!useGcs) {        // Let's downgrade by just reading it!
          downloadRawFile(userId, projectId, fd.fileName);
        }
      }
    }
  }

  /*
   * If we are running low on time, we may have not moved all files
   * so exit now without marking the user as having been finished
   */
  if (ApiProxy.getCurrentEnvironment().getRemainingMillis() <= 5000)
    return;

  /* If anything failed, also return without marking user */
  if (anyFailed)
    return;

  datastore = ObjectifyService.beginTransaction();
  userData = datastore.find(userKey(userId));
  userData.upgradedGCS = useGcs;
  datastore.put(userData);
  datastore.getTxn().commit();
}