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


Java Entity类代码示例

本文整理汇总了Java中com.googlecode.objectify.annotation.Entity的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Entity类属于com.googlecode.objectify.annotation包,在下文中一共展示了Entity类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: expandPolymorphicClasses

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
/** Expands non-entity polymorphic classes into their child types. */
@SuppressWarnings("unchecked")
private ImmutableList<Class<? extends I>> expandPolymorphicClasses(
    ImmutableSet<Class<? extends I>> resourceClasses) {
  ImmutableList.Builder<Class<? extends I>> builder = new ImmutableList.Builder<>();
  for (Class<? extends I> clazz : resourceClasses) {
    if (clazz.isAnnotationPresent(Entity.class)) {
      builder.add(clazz);
    } else {
      for (Class<? extends ImmutableObject> entityClass : ALL_CLASSES) {
        if (clazz.isAssignableFrom(entityClass)) {
          builder.add((Class<? extends I>) entityClass);
        }
      }
    }
  }
  return builder.build();
}
 
开发者ID:google,项目名称:nomulus,代码行数:19,代码来源:ChildEntityReader.java

示例2: testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
@Test
public void testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities() throws Exception {
  Set<String> baseEntityKinds =
      ALL_CLASSES
          .stream()
          .filter(hasAnnotation(Entity.class))
          .map(Key::getKind)
          .collect(toImmutableSet());
  Set<String> entitySubclassKinds =
      ALL_CLASSES
          .stream()
          .filter(hasAnnotation(EntitySubclass.class))
          .map(Key::getKind)
          .collect(toImmutableSet());
  assertThat(baseEntityKinds).named("base entity kinds").containsAllIn(entitySubclassKinds);
}
 
开发者ID:google,项目名称:nomulus,代码行数:17,代码来源:EntityClassesTest.java

示例3: registerEntityClasses

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
/** Register classes that can be persisted via Objectify as Datastore entities. */
private static void registerEntityClasses(
    ImmutableSet<Class<? extends ImmutableObject>> entityClasses) {
  // Register all the @Entity classes before any @EntitySubclass classes so that we can check
  // that every @Entity registration is a new kind and every @EntitySubclass registration is not.
  // This is future-proofing for Objectify 5.x where the registration logic gets less lenient.

  for (Class<?> clazz :
      Streams.concat(
              entityClasses.stream().filter(hasAnnotation(Entity.class)),
              entityClasses.stream().filter(hasAnnotation(Entity.class).negate()))
          .collect(toImmutableSet())) {
    String kind = Key.getKind(clazz);
    boolean registered = factory().getMetadata(kind) != null;
    if (clazz.isAnnotationPresent(Entity.class)) {
      // Objectify silently ignores re-registrations for a given kind string, even if the classes
      // being registered are distinct. Throw an exception if that would happen here.
      checkState(!registered,
          "Kind '%s' already registered, cannot register new @Entity %s",
          kind, clazz.getCanonicalName());
    } else if (clazz.isAnnotationPresent(EntitySubclass.class)) {
      // Ensure that any @EntitySubclass classes have also had their parent @Entity registered,
      // which Objectify nominally requires but doesn't enforce in 4.x (though it may in 5.x).
      checkState(registered,
          "No base entity for kind '%s' registered yet, cannot register new @EntitySubclass %s",
          kind, clazz.getCanonicalName());
    }
    com.googlecode.objectify.ObjectifyService.register(clazz);
    // Autogenerated ids make the commit log code very difficult since we won't always be able
    // to create a key for an entity immediately when requesting a save. Disallow that here.
    checkState(
        !factory().getMetadata(clazz).getKeyMetadata().isIdGeneratable(),
        "Can't register %s: Autogenerated ids (@Id on a Long) are not supported.", kind);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:36,代码来源:ObjectifyService.java

示例4: createFromRaw

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
/**
 * Returns a new mutation entity created from a raw Datastore Entity instance.
 *
 * <p>The mutation key is generated deterministically from the {@code entity} key. The Entity
 * itself is serialized to bytes and stored within the returned mutation.
 */
@VisibleForTesting
public static CommitLogMutation createFromRaw(
    Key<CommitLogManifest> parent,
    com.google.appengine.api.datastore.Entity rawEntity) {
  CommitLogMutation instance = new CommitLogMutation();
  instance.parent = checkNotNull(parent);
  // Creates a web-safe key string.
  instance.entityKey = KeyFactory.keyToString(rawEntity.getKey());
  instance.entityProtoBytes = convertToPb(rawEntity).toByteArray();
  return instance;
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:CommitLogMutation.java

示例5: testRawEntityLayout

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testRawEntityLayout() throws Exception {
  save(new TestObject());
  clock.advanceBy(standardDays(1));
  com.google.appengine.api.datastore.Entity entity =
      ofy().transactNewReadOnly(() -> ofy().save().toEntity(reload()));
  assertThat(entity.getProperties().keySet()).containsExactly("revisions.key", "revisions.value");
  assertThat(entity.getProperties()).containsEntry(
      "revisions.key", ImmutableList.of(START_TIME.toDate(), START_TIME.plusDays(1).toDate()));
  assertThat(entity.getProperty("revisions.value")).isInstanceOf(List.class);
  assertThat(((List<Object>) entity.getProperty("revisions.value")).get(0))
      .isInstanceOf(com.google.appengine.api.datastore.Key.class);
}
 
开发者ID:google,项目名称:nomulus,代码行数:15,代码来源:CommitLogRevisionsTranslatorFactoryTest.java

示例6: testLoad_missingRevisionRawProperties_createsEmptyObject

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
@Test
public void testLoad_missingRevisionRawProperties_createsEmptyObject() throws Exception {
  com.google.appengine.api.datastore.Entity entity =
      ofy().transactNewReadOnly(() -> ofy().save().toEntity(new TestObject()));
  entity.removeProperty("revisions.key");
  entity.removeProperty("revisions.value");
  TestObject object = ofy().load().fromEntity(entity);
  assertThat(object.revisions).isNotNull();
  assertThat(object.revisions).isEmpty();
}
 
开发者ID:google,项目名称:nomulus,代码行数:11,代码来源:CommitLogRevisionsTranslatorFactoryTest.java

示例7: testEntityClasses_eitherBaseEntityOrEntitySubclass

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
@Test
public void testEntityClasses_eitherBaseEntityOrEntitySubclass() throws Exception {
  for (Class<?> clazz : ALL_CLASSES) {
    boolean isEntityXorEntitySubclass =
        clazz.isAnnotationPresent(Entity.class) ^ clazz.isAnnotationPresent(EntitySubclass.class);
    assertThat(isEntityXorEntitySubclass)
        .named("class " + clazz.getSimpleName() + " is @Entity or @EntitySubclass")
        .isTrue();
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:11,代码来源:EntityClassesTest.java

示例8: getAnnotatedClasses

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
private Stream<Class<?>> getAnnotatedClasses() {
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class, false, false));
    return scanner.findCandidateComponents(basePackage).stream()
            .map(this::beanClass);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:7,代码来源:ObjectifyEntityScanner.java

示例9: getIdentifyingAnnotations

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
@Override
protected Collection<Class<? extends Annotation>> getIdentifyingAnnotations() {
    return Arrays.asList(Entity.class, Subclass.class);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:5,代码来源:ObjectifyRepositoryConfigurationExtension.java

示例10: getEntity

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
/** Deserializes embedded entity bytes and returns it. */
public com.google.appengine.api.datastore.Entity getEntity() {
  return createFromPbBytes(entityProtoBytes);
}
 
开发者ID:google,项目名称:nomulus,代码行数:5,代码来源:CommitLogMutation.java

示例11: testEntityClasses_baseEntitiesHaveUniqueKinds

import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
@Test
public void testEntityClasses_baseEntitiesHaveUniqueKinds() throws Exception {
  assertThat(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind))
      .named("base entity kinds")
      .containsNoDuplicates();
}
 
开发者ID:google,项目名称:nomulus,代码行数:7,代码来源:EntityClassesTest.java


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