本文整理匯總了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();
}