本文整理匯總了Java中javax.jdo.annotations.PersistenceCapable類的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceCapable類的具體用法?Java PersistenceCapable怎麽用?Java PersistenceCapable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PersistenceCapable類屬於javax.jdo.annotations包,在下文中一共展示了PersistenceCapable類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shouldBuildEnhancedDDE
import javax.jdo.annotations.PersistenceCapable; //導入依賴的package包/類
@Test
public void shouldBuildEnhancedDDE() throws Exception {
FieldDto strField = fieldDto("testStr", String.class);
FieldDto boolField = fieldDto("testBool", Boolean.class);
strField.setReadOnly(true);
boolField.setReadOnly(true);
fields.addAll(asList(
strField, boolField, fieldDto("fromUser", DateTime.class)
));
when(entity.getClassName()).thenReturn(EntBuilderTestClass.class.getName());
ClassData classData = entityBuilder.buildDDE(entity, fields, bundle);
Class<?> builtClass = MDSClassLoader.getStandaloneInstance()
.defineClass(classData.getClassName(), classData.getBytecode());
assertField(builtClass, "testStr", String.class, "defValForTestStr");
assertField(builtClass, "testBool", boolean.class, false, "is");
assertField(builtClass, "fromUser", DateTime.class);
// check annotations
assertNotNull(builtClass.getAnnotation(PersistenceCapable.class));
java.lang.reflect.Field field = builtClass.getDeclaredField("testStr");
assertNotNull(field.getAnnotation(Unique.class));
}
示例2: isClassPersistable
import javax.jdo.annotations.PersistenceCapable; //導入依賴的package包/類
@Override
protected AnnotationObject isClassPersistable(Class cls) {
AnnotationObject annotationObject = super.isClassPersistable(cls);
// if super does not recognize this object as PC, then try looking for the Entity annotation
// only when FileMetadata has been already loaded
if (annotationObject == null && ReflectionsUtil.hasAnnotation(cls, Entity.class) &&
!ArrayUtils.isEmpty(mgr.getFileMetaData())) {
// default params
HashMap<String, Object> annotationParams = new HashMap<>();
annotationParams.put("identityType", IdentityType.DATASTORE);
Class superClass = cls.getSuperclass();
while (superClass != null) {
if (superClass == MdsEntity.class || superClass == MdsVersionedEntity.class) {
annotationParams.put("identityType", IdentityType.APPLICATION);
}
superClass = superClass.getSuperclass();
}
annotationParams.put("detachable", Constants.Util.TRUE);
// we fake a persistence capable annotation
annotationObject = new AnnotationObject(PersistenceCapable.class.getName(), annotationParams);
}
return annotationObject;
}
示例3: shouldRecognizeRegularPCAnnotation
import javax.jdo.annotations.PersistenceCapable; //導入依賴的package包/類
@Test
public void shouldRecognizeRegularPCAnnotation() {
AnnotationObject result = mdsJdoAnnotationReader.isClassPersistable(JustPc.class);
assertEquals(PersistenceCapable.class.getName(), result.getName());
assertNotNull(result.getNameValueMap());
assertEquals("false", result.getNameValueMap().get("cacheable"));
assertEquals("true", result.getNameValueMap().get("detachable"));
}
示例4: shouldRecognizeEntityAnnotation
import javax.jdo.annotations.PersistenceCapable; //導入依賴的package包/類
@Test
public void shouldRecognizeEntityAnnotation() {
when(metaDataManager.getFileMetaData()).thenReturn(new FileMetaData[1]);
AnnotationObject result = mdsJdoAnnotationReader.isClassPersistable(Record.class);
assertEquals(PersistenceCapable.class.getName(), result.getName());
assertNotNull(result.getNameValueMap());
assertEquals(IdentityType.DATASTORE, result.getNameValueMap().get("identityType"));
assertEquals("true", result.getNameValueMap().get("detachable"));
}
示例5: shouldPrioritizePersistenceCapableAnnotationValuesOverEntityDefaults
import javax.jdo.annotations.PersistenceCapable; //導入依賴的package包/類
@Test
public void shouldPrioritizePersistenceCapableAnnotationValuesOverEntityDefaults() {
AnnotationObject result = mdsJdoAnnotationReader.isClassPersistable(PcAndEntity.class);
assertEquals(PersistenceCapable.class.getName(), result.getName());
assertNotNull(result.getNameValueMap());
assertEquals(IdentityType.APPLICATION, result.getNameValueMap().get("identityType"));
assertEquals("false", result.getNameValueMap().get("detachable"));
assertEquals("testCatalog", result.getNameValueMap().get("catalog"));
}
示例6: searchAndTest
import javax.jdo.annotations.PersistenceCapable; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
@Test
public void searchAndTest() {
Reflections reflections = new Reflections("org.estatio.dom");
Set<Class<? extends UdoDomainObject>> subtypes =
reflections.getSubTypesOf(UdoDomainObject.class);
for (Class<? extends UdoDomainObject> subtype : subtypes) {
if (subtype.isAnonymousClass() || subtype.isLocalClass() || subtype.isMemberClass() || subtype.getName().endsWith("ForTesting")) {
// skip (probably a testing class)
continue;
}
if (UdoDomainObject.class == subtype || UdoDomainObject2.class == subtype) {
// skip
continue;
}
System.out.println(">>> " + subtype.getName());
// must have a @PersistenceCapable(identityType=...) annotation
final PersistenceCapable persistenceCapable = subtype.getAnnotation(PersistenceCapable.class);
Assertions.assertThat(persistenceCapable).isNotNull();
IdentityType identityType = persistenceCapable.identityType();
Assertions.assertThat(identityType).isNotNull();
if (identityType == IdentityType.DATASTORE) {
// NOT mandatory to have a @DatastoreIdentity, but if does, then @DatastoreIdentity(..., column="id")
final DatastoreIdentity datastoreIdentity = subtype.getAnnotation(DatastoreIdentity.class);
if (datastoreIdentity != null) {
Assertions.assertThat(datastoreIdentity.column()).isEqualTo("id");
}
}
Inheritance inheritance = subtype.getAnnotation(Inheritance.class);
if (inheritance != null && inheritance.strategy() == InheritanceStrategy.SUPERCLASS_TABLE) {
// must NOT have a @Discriminator(..., column="discriminator")
final Annotation[] declaredAnnotations = subtype.getDeclaredAnnotations();
for (Annotation declaredAnnotation : declaredAnnotations) {
if (declaredAnnotation.annotationType() == Discriminator.class) {
Assert.fail("Class " + subtype.getName() + " inherits from " + subtype.getSuperclass().getName()
+ "and has (incorrectly) been annotated with @Discriminator");
}
}
// check if supertype has discriminator
// must have a @Discriminator(..., column="discriminator") on one of its supertypes
final Discriminator superDiscriminator = subtype.getSuperclass().getAnnotation(Discriminator.class);
Assertions.assertThat(superDiscriminator).isNotNull();
Assertions.assertThat(superDiscriminator.column()).isEqualTo("discriminator");
}
if (subtype.getSuperclass().equals(UdoDomainObject.class)) {
// must have a @Version(..., column="version")
final Version version = getAnnotationOfTypeOfItsSupertypes(subtype, Version.class);
Assertions.assertThat(version).isNotNull();
Assertions.assertThat(version.column()).isEqualTo("version");
}
}
}