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

The following examples show how to use com.googlecode.objectify.Objectify#delete() . 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 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 2
Source File: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
private void removeFilesFromProject(Objectify datastore, long projectId,
    FileData.RoleEnum role, boolean changeModDate, String... fileNames) {
  Key<ProjectData> projectKey = projectKey(projectId);
  List<Key<FileData>> filesToRemove = new ArrayList<Key<FileData>>();
  for (String fileName : fileNames) {
    Key<FileData> key = projectFileKey(projectKey, fileName);
    memcache.delete(key.getString()); // Remove it from memcache (if it is there)
    FileData fd = datastore.find(key);
    if (fd != null) {
      if (fd.role.equals(role)) {
        filesToRemove.add(projectFileKey(projectKey, fileName));
      } else {
        throw CrashReport.createAndLogError(LOG, null,
            collectProjectErrorInfo(null, projectId, fileName),
            new IllegalStateException("File role change is not supported"));
      }
    }
  }
  datastore.delete(filesToRemove);  // batch delete
  if (changeModDate) {
    updateProjectModDate(datastore, projectId, false);
  }
}
 
Example 3
Source File: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
public void cleanupNonces() {
  Objectify datastore = ObjectifyService.begin();
  // We do not use runJobWithRetries because if we fail here, we will be
  // called again the next time someone attempts to download a built APK
  // via a QR Code.
  try {
    datastore.delete(datastore.query(NonceData.class)
      .filter("timestamp <", new Date((new Date()).getTime() - 3600*3*1000L))
      .limit(10).fetchKeys());
  } catch (Exception ex) {
      LOG.log(Level.WARNING, "Exception during cleanupNonces", ex);
  }

}
 
Example 4
Source File: ObjectifyStorageIo.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void cleanuppwdata() {
  Objectify datastore = ObjectifyService.begin();
  // We do not use runJobWithRetries because if we fail here, we will be
  // called again the next time someone attempts to set a password
  // Note: we remove data after 24 hours.
  try {
    datastore.delete(datastore.query(PWData.class)
      .filter("timestamp <", new Date((new Date()).getTime() - 3600*24*1000L))
      .limit(10).fetchKeys());
  } catch (Exception ex) {
      LOG.log(Level.WARNING, "Exception during cleanupNonces", ex);
  }
}