本文整理匯總了Java中com.googlecode.objectify.Key類的典型用法代碼示例。如果您正苦於以下問題:Java Key類的具體用法?Java Key怎麽用?Java Key使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Key類屬於com.googlecode.objectify包,在下文中一共展示了Key類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deleteAll
import com.googlecode.objectify.Key; //導入依賴的package包/類
/**
* Delete all entities in batches of {@value BATCH_SIZE}.
*
* @return number of entities deleted
*/
public long deleteAll() {
Query<E> query = ofy().load().type(entityType).limit(BATCH_SIZE);
QueryResultIterator<Key<E>> iterator = query.keys().iterator();
List<Key<E>> keysToDelete = new ArrayList<>();
long numDeleted = 0;
while (iterator.hasNext()) {
Key<E> key = iterator.next();
keysToDelete.add(key);
if (!iterator.hasNext()) {
deleteByKey(fromKeys.from(keysToDelete));
numDeleted += keysToDelete.size();
keysToDelete.clear();
iterator = query.startAt(iterator.getCursor()).keys().iterator();
}
}
return numDeleted;
}
示例2: getProjects
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Override
public List<Long> getProjects(final String userId) {
final List<Long> projects = new ArrayList<Long>();
try {
runJobWithRetries(new JobRetryHelper() {
@Override
public void run(Objectify datastore) {
Key<UserData> userKey = userKey(userId);
for (UserProjectData upd : datastore.query(UserProjectData.class).ancestor(userKey)) {
projects.add(upd.projectId);
}
}
}, false);
} catch (ObjectifyException e) {
throw CrashReport.createAndLogError(LOG, null, collectUserErrorInfo(userId), e);
}
return projects;
}
示例3: getUserFiles
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Override
public List<String> getUserFiles(final String userId) {
final List<String> fileList = new ArrayList<String>();
try {
runJobWithRetries(new JobRetryHelper() {
@Override
public void run(Objectify datastore) {
Key<UserData> userKey = userKey(userId);
for (UserFileData ufd : datastore.query(UserFileData.class).ancestor(userKey)) {
fileList.add(ufd.fileName);
}
}
}, false);
} catch (ObjectifyException e) {
throw CrashReport.createAndLogError(LOG, null, collectUserErrorInfo(userId), e);
}
return fileList;
}
示例4: deleteByKeyCollection
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Test
public void deleteByKeyCollection() throws Exception {
TestLongEntity[] entities = fixture.get(3);
ofy().save().entities(entities).now();
List<TestLongEntity> listBeforeDelete = ofy().load().type(TestLongEntity.class).list();
assertThat(listBeforeDelete).hasSize(3);
repository.deleteByKey(
Arrays.asList(
Key.create(TestLongEntity.class, 1L),
Key.create(TestLongEntity.class, 2L)
)
);
List<TestLongEntity> listAfterDelete = ofy().load().type(TestLongEntity.class).list();
assertThat(listAfterDelete).hasSize(1);
assertThat(listAfterDelete).containsExactly(entities[2]);
}
示例5: putAsync
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Override
public AsyncResult<E> putAsync(final E entity) {
boolean hasId = hasId(entity);
final Result<Key<E>> ofyFuture = ofy().save().entity(entity);
if (!hasId) {
// if no id exists - we need objectify to complete so that the id can be used in indexing the record.
ofyFuture.now();
}
final IndexOperation searchFuture = shouldSearch() ? index(entity) : null;
return () -> {
ofyFuture.now();
if (searchFuture != null) {
searchFuture.complete();
}
return entity;
};
}
示例6: createProjectFile
import com.googlecode.objectify.Key; //導入依賴的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;
}
示例7: findAllCollection
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Test
public void findAllCollection() throws Exception {
TestStringEntity[] entities = fixture.get(3);
ofy().save().entities(entities).now();
List<TestStringEntity> result = repository.findAll(
Arrays.asList(
Key.create(TestStringEntity.class, "id1"),
Key.create(TestStringEntity.class, "id2"),
Key.create(TestStringEntity.class, "id3")
)
);
assertThat(result)
.isNotNull()
.hasSize(3)
.containsExactly(entities);
}
示例8: findAllCollection
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Test
public void findAllCollection() throws Exception {
TestLongEntity[] entities = fixture.get(3);
ofy().save().entities(entities).now();
List<TestLongEntity> result = repository.findAll(
Arrays.asList(
Key.create(TestLongEntity.class, 1L),
Key.create(TestLongEntity.class, 2L),
Key.create(TestLongEntity.class, 3L)
)
);
assertThat(result)
.isNotNull()
.hasSize(3)
.containsExactly(entities);
}
示例9: shouldReindexEntitiesBasedOnKeysAndWriteBackToDatastoreWhenReindexOperationProvided
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Test
public void shouldReindexEntitiesBasedOnKeysAndWriteBackToDatastoreWhenReindexOperationProvided() {
KeyTestEntity testEntity = new KeyTestEntity(1, "original");
KeyTestEntity testEntity2 = new KeyTestEntity(2, "original");
KeyTestEntity testEntity3 = new KeyTestEntity(3, "original");
repository.putAsync(testEntity, testEntity2, testEntity3).complete();
repository.searchService.removeAll();
assertThat(repository.search().field("name", Is.Is, "original").run().getResults(), hasSize(0));
List<Key<KeyTestEntity>> keys = Arrays.asList(testEntity.getKey(), testEntity2.getKey(), testEntity3.getKey());
int reindexed = repository.reindex(keys, 10, batch -> {
for (KeyTestEntity entity : batch) {
entity.setName("different");
}
return batch;
});
assertThat(reindexed, is(3));
assertThat(repository.search().field("name", Is.Is, "different").run().getResults(), hasItems(testEntity, testEntity2, testEntity3));
assertThat(repository.getByField("name", "different"), hasItems(testEntity, testEntity2, testEntity3));
}
示例10: deleteByKeyCollection
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Test
public void deleteByKeyCollection() throws Exception {
TestStringEntity[] entities = fixture.get(3);
ofy().save().entities(entities).now();
List<TestStringEntity> listBeforeDelete = ofy().load().type(TestStringEntity.class).list();
assertThat(listBeforeDelete).hasSize(3);
repository.deleteByKey(
Arrays.asList(
Key.create(TestStringEntity.class, "id1"),
Key.create(TestStringEntity.class, "id2")
)
);
List<TestStringEntity> listAfterDelete = ofy().load().type(TestStringEntity.class).list();
assertThat(listAfterDelete).hasSize(1);
assertThat(listAfterDelete).containsExactly(entities[2]);
}
示例11: getModerationActions
import com.googlecode.objectify.Key; //導入依賴的package包/類
/**
* get moderation actions associated with given reportId
* @param reportId
*/
@Override
public List<GalleryModerationAction> getModerationActions(final long reportId){
final List<GalleryModerationAction> moderationActions = new ArrayList<GalleryModerationAction>();
try {
runJobWithRetries(new JobRetryHelper() {
@Override
public void run(Objectify datastore) {
Key<GalleryAppReportData> galleryReportKey = galleryReportKey(reportId);
for (GalleryModerationActionData moderationActionData : datastore.query(GalleryModerationActionData.class)
.ancestor(galleryReportKey).order("-date")) {
GalleryModerationAction moderationAction = new GalleryModerationAction(reportId, moderationActionData.galleryId,
moderationActionData.emailId, moderationActionData.moderatorId, moderationActionData.actionType,
moderationActionData.moderatorName, moderationActionData.emailPreview, moderationActionData.date);
moderationActions.add(moderationAction);
}
}
});
} catch (ObjectifyException e) {
throw CrashReport.createAndLogError(LOG, null, "error in galleryStorageIo.getCommentReports", e);
}
return moderationActions;
}
示例12: shouldReindexEntitiesBasedOnSearch
import com.googlecode.objectify.Key; //導入依賴的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));
}
示例13: shouldReindexEntitiesBasedOnSearchAndWriteBackToDatastoreWhenReindexOperationProvided
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Test
public void shouldReindexEntitiesBasedOnSearchAndWriteBackToDatastoreWhenReindexOperationProvided() {
KeyTestEntity testEntity = new KeyTestEntity(1, "name");
KeyTestEntity testEntity2 = new KeyTestEntity(2, "name");
KeyTestEntity testEntity3 = new KeyTestEntity(3, "name");
repository.putAsync(testEntity, testEntity2, testEntity3).complete();
assertThat(repository.search().field("id", Is.GreaterThan, 0).run().getResults(), hasItems(testEntity, testEntity2, testEntity3));
List<Key<KeyTestEntity>> keys = Arrays.asList(testEntity.getKey(), testEntity2.getKey(), testEntity3.getKey());
int reindexed = repository.reindex(keys, 10, batch -> {
for (KeyTestEntity entity : batch) {
entity.setName("different");
}
return batch;
});
assertThat(reindexed, is(3));
assertThat(repository.search().field("name", Is.Is, "different").run().getResults(), hasItems(testEntity, testEntity2, testEntity3));
assertThat(repository.getByField("name", "different"), hasItems(testEntity, testEntity2, testEntity3));
}
示例14: from
import com.googlecode.objectify.Key; //導入依賴的package包/類
@Test
public void from() {
Key<AppUser> key = Key.create(AppUser.class, "ref");
Ref<AppUser> ref = Ref.create(key);
String webSafeString = toString.from(ref);
assertThat(Key.create(webSafeString), is(equalTo(key)));
}
示例15: defaultIndexTypeLookup
import com.googlecode.objectify.Key; //導入依賴的package包/類
public static IndexTypeLookup defaultIndexTypeLookup() {
IndexTypeLookup indexTypeLookup = new IndexTypeLookup();
indexTypeLookup.addMapping(Key.class, IndexType.Identifier);
indexTypeLookup.addMapping(com.google.appengine.api.datastore.Key.class, IndexType.Identifier);
indexTypeLookup.addMapping(GeoPt.class, IndexType.GeoPoint);
return indexTypeLookup;
}