本文整理匯總了Java中com.googlecode.objectify.Objectify.find方法的典型用法代碼示例。如果您正苦於以下問題:Java Objectify.find方法的具體用法?Java Objectify.find怎麽用?Java Objectify.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.googlecode.objectify.Objectify
的用法示例。
在下文中一共展示了Objectify.find方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addUserFileContents
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
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);
}
示例2: createProjectFile
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
private FileData createProjectFile(Objectify datastore, Key<ProjectData> projectKey,
FileData.RoleEnum role, String fileName) {
FileData fd = datastore.find(projectFileKey(projectKey, fileName));
if (fd == null) {
fd = new FileData();
fd.fileName = fileName;
fd.projectKey = projectKey;
fd.role = role;
return fd;
} else if (!fd.role.equals(role)) {
throw CrashReport.createAndLogError(LOG, null,
collectProjectErrorInfo(null, projectKey.getId(), fileName),
new IllegalStateException("File role change is not supported"));
}
return null;
}
示例3: removeFilesFromProject
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
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);
}
}
示例4: updateProjectModDate
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
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"));
}
}
示例5: getFeaturedApp
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
/**
* Returns a wrapped class which contains a list of featured gallery app
* @param start start index
* @param count count number
* @return list of gallery app
*/
public GalleryAppListResult getFeaturedApp(int start, int count){
final List<GalleryApp> apps = new ArrayList<GalleryApp>();
Objectify datastore = ObjectifyService.begin();
for (GalleryAppFeatureData appFeatureData:datastore.query(GalleryAppFeatureData.class).offset(start).limit(count)) {
Long galleryId = appFeatureData.galleryKey.getId();
GalleryApp gApp = new GalleryApp();
GalleryAppData galleryAppData = datastore.find(galleryKey(galleryId));
makeGalleryApp(galleryAppData, gApp);
apps.add(gApp);
}
int totalCount = datastore.query(GalleryAppFeatureData.class).count();
return new GalleryAppListResult(apps, totalCount);
}
示例6: getTutorialApp
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
/**
* Returns a wrapped class which contains a list of tutorial gallery app
* @param start start index
* @param count count number
* @return list of gallery app
*/
public GalleryAppListResult getTutorialApp(int start, int count){
final List<GalleryApp> apps = new ArrayList<GalleryApp>();
Objectify datastore = ObjectifyService.begin();
for (GalleryAppTutorialData appTutorialData:datastore.query(GalleryAppTutorialData.class).offset(start).limit(count)) {
Long galleryId = appTutorialData.galleryKey.getId();
GalleryApp gApp = new GalleryApp();
GalleryAppData galleryAppData = datastore.find(galleryKey(galleryId));
makeGalleryApp(galleryAppData, gApp);
apps.add(gApp);
}
int totalCount = datastore.query(GalleryAppTutorialData.class).count();
return new GalleryAppListResult(apps, totalCount);
}
示例7: createUserFile
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
private UserFileData createUserFile(Objectify datastore, Key<UserData> userKey,
String fileName) {
UserFileData ufd = datastore.find(userFileKey(userKey, fileName));
if (ufd == null) {
ufd = new UserFileData();
ufd.fileName = fileName;
ufd.userKey = userKey;
return ufd;
}
return null;
}
示例8: isGcsFile
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
@VisibleForTesting
boolean isGcsFile(long projectId, String fileName) {
Objectify datastore = ObjectifyService.begin();
Key<FileData> fileKey = projectFileKey(projectKey(projectId), fileName);
FileData fd;
fd = (FileData) memcache.get(fileKey.getString());
if (fd == null) {
fd = datastore.find(fileKey);
}
if (fd != null) {
return isTrue(fd.isGCS);
} else {
return false;
}
}
示例9: checkUpgrade
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
public void checkUpgrade(String userId) {
if (!conversionEnabled) // Unless conversion is enabled...
return;
Objectify datastore = ObjectifyService.begin();
UserData userData = datastore.find(userKey(userId));
if ((userData.upgradedGCS && useGcs) ||
(!userData.upgradedGCS && !useGcs))
return; // All done.
Queue queue = QueueFactory.getQueue("blobupgrade");
queue.add(TaskOptions.Builder.withUrl("/convert").param("user", userId)
.etaMillis(System.currentTimeMillis() + 60000));
return;
}
示例10: doUpgrade
import com.googlecode.objectify.Objectify; //導入方法依賴的package包/類
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();
}