本文整理汇总了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();
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
}
示例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);
}
示例9: getIdentifyingAnnotations
import com.googlecode.objectify.annotation.Entity; //导入依赖的package包/类
@Override
protected Collection<Class<? extends Annotation>> getIdentifyingAnnotations() {
return Arrays.asList(Entity.class, Subclass.class);
}
示例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);
}
示例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();
}