当前位置: 首页>>代码示例>>Java>>正文


Java Key类代码示例

本文整理汇总了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;
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:23,代码来源:BaseRepository.java

示例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;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:20,代码来源:ObjectifyStorageIo.java

示例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;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:19,代码来源:ObjectifyStorageIo.java

示例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]);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:20,代码来源:LongDeleteRepositoryTest.java

示例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;
    };
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:18,代码来源:AbstractRepository.java

示例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;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:17,代码来源:ObjectifyStorageIo.java

示例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);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:19,代码来源:StringLoadRepositoryTest.java

示例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);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:19,代码来源:LongLoadRepositoryTest.java

示例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));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:23,代码来源:KeyRepositoryTest.java

示例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]);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:20,代码来源:StringDeleteRepositoryTest.java

示例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;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:27,代码来源:ObjectifyGalleryStorageIo.java

示例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));
}
 
开发者ID:lorderikir,项目名称:googlecloud-techtalk,代码行数:23,代码来源:KeyRepositoryTest.java

示例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));
}
 
开发者ID:lorderikir,项目名称:googlecloud-techtalk,代码行数:22,代码来源:KeyRepositoryTest.java

示例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)));
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:9,代码来源:RefToStringTest.java

示例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;
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:8,代码来源:SearchModule.java


注:本文中的com.googlecode.objectify.Key类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。