本文整理汇总了Java中com.googlecode.objectify.ObjectifyService类的典型用法代码示例。如果您正苦于以下问题:Java ObjectifyService类的具体用法?Java ObjectifyService怎么用?Java ObjectifyService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectifyService类属于com.googlecode.objectify包,在下文中一共展示了ObjectifyService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
@Before
public void setUp() {
helper.setUp();
//ObjectifyRegistrar.registerDataModel();
closeable = ObjectifyService.begin();
ObjectifyService.register(Item.class);
ObjectifyService.register(User.class);
ObjectifyService.register(ItemRating.class);
ObjectifyService.register(Availability.class);
ObjectifyService.register(Address.class);
ObjectifyService.register(UserRating.class);
testCreateItem();
}
示例2: shouldReindexEntitiesBasedOnSearch
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
@Test
public void shouldReindexEntitiesBasedOnSearch() {
KeyTestEntity testEntity = new KeyTestEntity(1, "original");
KeyTestEntity testEntity2 = new KeyTestEntity(2, "original");
KeyTestEntity testEntity3 = new KeyTestEntity(3, "original");
repository.putAsync(testEntity, testEntity2, testEntity3).complete();
assertThat(repository.search().field("name", Is.Is, "original").run().getResults(), hasItems(testEntity, testEntity2, testEntity3));
List<KeyTestEntity> all = ObjectifyService.ofy().load().type(KeyTestEntity.class).list();
for (KeyTestEntity e : all) {
e.setName("other name");
}
ObjectifyService.ofy().save().entities(all).now();
List<Key<KeyTestEntity>> keys = Arrays.asList(testEntity.getKey(), testEntity2.getKey(), testEntity3.getKey());
int reindexed = repository.reindex(keys, 10, null);
assertThat(reindexed, is(3));
assertThat(repository.search().field("name", Is.Is, "original").run().getResults().isEmpty(), is(true));
assertThat(repository.search().field("name", Is.Is, "other name").run().getResults().size(), is(3));
}
示例3: shouldReindexEntitiesBasedOnSearch
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
@Test
public void shouldReindexEntitiesBasedOnSearch() {
StringTestEntity testEntity = new StringTestEntity("1", "original");
StringTestEntity testEntity2 = new StringTestEntity("2", "original");
StringTestEntity testEntity3 = new StringTestEntity("3", "original");
repository.putAsync(testEntity, testEntity2, testEntity3).complete();
assertThat(repository.search().field("name", Is.Is, "original").run().getResults(), hasItems(testEntity, testEntity2, testEntity3));
List<StringTestEntity> all = ObjectifyService.ofy().load().type(StringTestEntity.class).list();
for (StringTestEntity e : all) {
e.setName("other name");
}
ObjectifyService.ofy().save().entities(all).now();
List<String> keys = list(testEntity.getId(), testEntity2.getId(), testEntity3.getId());
int reindexed = repository.reindex(keys, 10, null);
assertThat(reindexed, is(3));
assertThat(repository.search().field("name", Is.Is, "original").run().getResultIds().isEmpty(), is(true));
assertThat(repository.search().field("name", Is.Is, "other name").run().getResultIds().size(), is(3));
}
示例4: shouldReindexEntities
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
@Test
public void shouldReindexEntities() {
DatastoreKeyTestEntity testEntity = new DatastoreKeyTestEntity(1, "original");
DatastoreKeyTestEntity testEntity2 = new DatastoreKeyTestEntity(2, "original");
DatastoreKeyTestEntity testEntity3 = new DatastoreKeyTestEntity(3, "original");
repository.putAsync(testEntity, testEntity2, testEntity3).complete();
assertThat(repository.search().field("name", Is.Is, "original").run().getResults(), hasItems(testEntity, testEntity2, testEntity3));
List<DatastoreKeyTestEntity> all = ObjectifyService.ofy().load().type(DatastoreKeyTestEntity.class).list();
for (DatastoreKeyTestEntity e : all) {
e.setName("other name");
}
ObjectifyService.ofy().save().entities(all).now();
List<Key> keys = list(testEntity.getKey(), testEntity2.getKey(), testEntity3.getKey());
int reindexed = repository.reindex(keys, 10, null);
assertThat(reindexed, is(3));
assertThat(repository.search().field("name", Is.Is, "original").run().getResults().isEmpty(), is(true));
assertThat(repository.search().field("name", Is.Is, "other name").run().getResults().size(), is(3));
}
示例5: shouldReindexEntitiesBasedOnSearch
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
@Test
public void shouldReindexEntitiesBasedOnSearch() {
LongTestEntity testEntity = new LongTestEntity(1, "original");
LongTestEntity testEntity2 = new LongTestEntity(2, "original");
LongTestEntity testEntity3 = new LongTestEntity(3, "original");
repository.putAsync(testEntity, testEntity2, testEntity3).complete();
Search<LongTestEntity, Long> search = repository.search().field("name", Is.Is, "original");
assertThat(search.run().getResults(), hasItems(testEntity, testEntity2, testEntity3));
List<LongTestEntity> all = ObjectifyService.ofy().load().type(LongTestEntity.class).list();
for (LongTestEntity e : all) {
e.setName("other name");
}
ObjectifyService.ofy().save().entities(all).now();
List<Long> keys = list(testEntity.getId(), testEntity2.getId(), testEntity3.getId());
int reindexed = repository.reindex(keys, 10, null);
assertThat(reindexed, is(3));
assertThat(search.run().getResults().isEmpty(), is(true));
assertThat(repository.search().field("name", Is.Is, "other name").run().getResultIds().size(), is(3));
}
示例6: getRecentGalleryApps
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
/**
* Returns a wrapped class which contains list of most recently
* updated galleryApps and total number of results in database
* @param start starting index of apps you want
* @param count number of apps you want
* @return list of {@link GalleryApp}
*/
@Override
public GalleryAppListResult getRecentGalleryApps(int start, final int count) {
final List<GalleryApp> apps = new ArrayList<GalleryApp>();
// If I try to run this in runjobwithretries, it tells me can't run
// non-ancestor query as a transaction. ObjectifyStorageio has some samples
// of not using transactions (run with) so I grabbed.
Objectify datastore = ObjectifyService.begin();
for (GalleryAppData appData:datastore.query(GalleryAppData.class).order("-dateModified").filter("active", true).offset(start).limit(count)) {
GalleryApp gApp = new GalleryApp();
makeGalleryApp(appData, gApp);
apps.add(gApp);
}
int totalCount = datastore.query(GalleryAppData.class).order("-dateModified").filter("active", true).count();
return new GalleryAppListResult(apps, totalCount);
}
示例7: getMostDownloadedApps
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
/**
* Returns a wrapped class which contains a list of most downloaded
* gallery apps and total number of results in database
* @param start starting index of apps you want
* @param count number of apps you want
* @return list of {@link GalleryApp}
*/
@Override
public GalleryAppListResult getMostDownloadedApps(int start, final int count) {
final List<GalleryApp> apps = new ArrayList<GalleryApp>();
// If I try to run this in runjobwithretries, it tells me can't run
// non-ancestor query as a transaction. ObjectifyStorageio has some samples
// of not using transactions (run with) so I grabbed.
Objectify datastore = ObjectifyService.begin();
for (GalleryAppData appData:datastore.query(GalleryAppData.class).order("-numDownloads").filter("active", true).offset(start).limit(count)) {
GalleryApp gApp = new GalleryApp();
makeGalleryApp(appData, gApp);
apps.add(gApp);
}
int totalCount = datastore.query(GalleryAppData.class).order("-numDownloads").filter("active", true).count();
return new GalleryAppListResult(apps, totalCount);
}
示例8: getDeveloperApps
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
/**
* Returns a wrapped class which contains a list of galleryApps
* by a particular developer and total number of results in database
* @param userId id of developer
* @param start starting index of apps you want
* @param count number of apps you want
* @return list of {@link GalleryApp}
*/ @Override
public GalleryAppListResult getDeveloperApps(String userId, int start, final int count) {
final List<GalleryApp> apps = new ArrayList<GalleryApp>();
// if i try to run this in runjobwithretries it tells me can't run
// non-ancestor query as a transaction. ObjectifyStorageio has some samples
// of not using transactions (run with) so i grabbed
Objectify datastore = ObjectifyService.begin();
for (GalleryAppData appData:datastore.query(GalleryAppData.class).filter("userId",userId).filter("active", true).offset(start).limit(count)) {
GalleryApp gApp = new GalleryApp();
makeGalleryApp(appData, gApp);
apps.add(gApp);
}
int totalCount = datastore.query(GalleryAppData.class).filter("userId",userId).filter("active", true).count();
return new GalleryAppListResult(apps, totalCount);
}
示例9: remixedTo
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
/**
* get the list of children Gallery Apps
*
* @param galleryId
* id of gallery app
* @return the list of children Gallery Apps
*/
public List<GalleryApp> remixedTo(final long galleryId) {
final List<GalleryApp> apps = new ArrayList<GalleryApp>();
try {
runJobWithRetries(new JobRetryHelper() {
@Override
public void run(Objectify datastore) {
datastore = ObjectifyService.begin();
for (GalleryAppAttributionData attributionData:datastore.query(GalleryAppAttributionData.class).filter("attributionId",galleryId)) {
GalleryAppData galleryAppData = datastore.find(galleryKey(attributionData.galleryId));
if(!galleryAppData.active) continue;
GalleryApp gApp = new GalleryApp();
makeGalleryApp(galleryAppData, gApp);
apps.add(gApp);
}
}
});
} catch (ObjectifyException e) {
throw CrashReport.createAndLogError(LOG, null,
"error in galleryStorageIo.saveAttribution", e);
}
return apps;
}
示例10: markReportAsResolved
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
/**
* mark an report as resolved
* @param reportId the id of the app
*/
@Override
public boolean markReportAsResolved(final long reportId, final long galleryId){
final Result<Boolean> success = new Result<Boolean>();
try {
runJobWithRetries(new JobRetryHelper() {
@Override
public void run(Objectify datastore) {
datastore = ObjectifyService.begin();
success.t = false;
Key<GalleryAppData> galleryKey = galleryKey(galleryId);
for (GalleryAppReportData reportData : datastore.query(GalleryAppReportData.class).ancestor(galleryKey)) {
if(reportData.id == reportId){
reportData.resolved = !reportData.resolved;
datastore.put(reportData);
success.t = true;
break;
}
}
}
});
} catch (ObjectifyException e) {
throw CrashReport.createAndLogError(LOG, null, "error in galleryStorageIo.markReportAsResolved", e);
}
return success.t;
}
示例11: isGalleryAppActivated
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
/**
* check if gallery app is activated
* @param galleryId the id of the gallery app
*/
@Override
public boolean isGalleryAppActivated(final long galleryId){
final Result<Boolean> success = new Result<Boolean>();
try {
runJobWithRetries(new JobRetryHelper() {
@Override
public void run(Objectify datastore) {
datastore = ObjectifyService.begin();
success.t = false;
Key<GalleryAppData> galleryKey = galleryKey(galleryId);
GalleryAppData appData = datastore.find(galleryKey);
if(appData != null){
if(appData.active){
success.t = true;
}
}
}
});
} catch (ObjectifyException e) {
throw CrashReport.createAndLogError(LOG, null, "error in galleryStorageIo.markReportAsResolved", e);
}
return success.t;
}
示例12: getCommentReports
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
/**
* Returns a list of reports (flags) for all comments
* @return list of {@link GalleryCommentReport}
*/
@Override
public List<GalleryCommentReport> getCommentReports() {
final List<GalleryCommentReport> reports = new ArrayList<GalleryCommentReport>();
Objectify datastore = ObjectifyService.begin();
for (GalleryCommentReportData reportData : datastore.query(GalleryCommentReportData.class).order("-dateCreated")) {
User commenter = storageIo.getUser(reportData.userId);
String name="unknown";
if (commenter!= null) {
name = commenter.getUserName();
}
GalleryCommentReport galleryCommentReport = new GalleryCommentReport(reportData.galleryCommentKey.getId(),
reportData.userId,reportData.report,reportData.dateCreated);
galleryCommentReport.setUserName(name);
reports.add(galleryCommentReport);
}
return reports;
}
示例13: getEmail
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
/**
* Returns the email with a particular emailId
* @param emailId id of the email
*/ @Override
public Email getEmail(final long emailId) {
final Result<Email> result = new Result<Email>();
// if i try to run this in runjobwithretries it tells me can't run
// non-ancestor query as a transaction. ObjectifyStorageio has some samples
// of not using transactions (run with) so i grabbed
Objectify datastore = ObjectifyService.begin();
for (EmailData emailData : datastore.query(EmailData.class)
.filter("id", emailId)/*.order("-datestamp")*/) {
Email email = new Email(emailData.id, emailData.senderId, emailData.receiverId,
emailData.title, emailData.body, emailData.datestamp);
result.t = email;
break;
}
return result.t;
}
示例14: getUserFromEmail
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
@Override
public User getUserFromEmail(String email) {
String emaillower = email.toLowerCase();
LOG.info("getUserFromEmail: email = " + email + " emaillower = " + emaillower);
Objectify datastore = ObjectifyService.begin();
String newId = UUID.randomUUID().toString();
// First try lookup using entered case (which will be the case for Google Accounts)
UserData user = datastore.query(UserData.class).filter("email", email).get();
if (user == null) {
LOG.info("getUserFromEmail: first attempt failed using " + email);
// Now try lower case version
user = datastore.query(UserData.class).filter("emaillower", emaillower).get();
if (user == null) { // Finally, create it (in lower case)
LOG.info("getUserFromEmail: second attempt failed using " + emaillower);
user = createUser(datastore, newId, email);
}
}
User retUser = new User(user.id, email, user.name, user.link, 0, user.tosAccepted,
false, user.type, user.sessionid);
retUser.setPassword(user.password);
return retUser;
}
示例15: getRequestResponseEntries
import com.googlecode.objectify.ObjectifyService; //导入依赖的package包/类
public static List<User> getRequestResponseEntries(WebsiteRequest request) throws Exception {
String name = request.getParameter("name");
User user = new User(name);
Key<User> key = ObjectifyService.ofy()
.save()
.entity(user)
.now();
List<User> results = new ArrayList<User>();
results.add(user);
log.info("Added a new user with name: " + name + " and id: " + user.getId());
return results;
}