本文整理汇总了Java中org.eclipse.persistence.descriptors.ClassDescriptor.getMappingForAttributeName方法的典型用法代码示例。如果您正苦于以下问题:Java ClassDescriptor.getMappingForAttributeName方法的具体用法?Java ClassDescriptor.getMappingForAttributeName怎么用?Java ClassDescriptor.getMappingForAttributeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.persistence.descriptors.ClassDescriptor
的用法示例。
在下文中一共展示了ClassDescriptor.getMappingForAttributeName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConvertersEstabished_directAssignment
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Test
public void testConvertersEstabished_directAssignment() throws Exception {
ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("nonStandardDataType");
assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
assertNotNull("converter not assigned", converter);
assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
converter.getClass());
Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
f.setAccessible(true);
String attributeConverterClassName = (String) f.get(converter);
assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.testbo.NonStandardDataTypeConverter",
attributeConverterClassName);
}
示例2: testConvertersEstabished_autoApply
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Test
public void testConvertersEstabished_autoApply() throws Exception {
ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("currencyProperty");
assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
assertNotNull("converter not assigned", converter);
assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
converter.getClass());
Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
f.setAccessible(true);
String attributeConverterClassName = (String) f.get(converter);
assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.converters.KualiDecimalConverter",
attributeConverterClassName);
}
示例3: testConvertersEstabished_autoApply_Boolean
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Test
public void testConvertersEstabished_autoApply_Boolean() throws Exception {
ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("booleanProperty");
assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
assertNotNull("converter not assigned", converter);
assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
converter.getClass());
Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
f.setAccessible(true);
String attributeConverterClassName = (String) f.get(converter);
assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter",
attributeConverterClassName);
}
示例4: handleRemoveMapping
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
/**
* Checks class descriptors for {@link @RemoveMapping} and {@link RemoveMappings} annotations at the class level
* and removes any specified mappings from the ClassDescriptor.
*
* @param session the current session.
*/
protected void handleRemoveMapping(Session session) {
Map<Class, ClassDescriptor> descriptors = session.getDescriptors();
if (descriptors == null || descriptors.isEmpty()) {
return;
}
for (ClassDescriptor classDescriptor : descriptors.values()) {
List<DatabaseMapping> mappingsToRemove = new ArrayList<DatabaseMapping>();
List<RemoveMapping> removeMappings = scanForRemoveMappings(classDescriptor);
for (RemoveMapping removeMapping : removeMappings) {
if (StringUtils.isBlank(removeMapping.name())) {
throw DescriptorException.attributeNameNotSpecified();
}
DatabaseMapping databaseMapping = classDescriptor.getMappingForAttributeName(removeMapping.name());
if (databaseMapping == null) {
throw DescriptorException.mappingForAttributeIsMissing(removeMapping.name(), classDescriptor);
}
mappingsToRemove.add(databaseMapping);
}
for (DatabaseMapping mappingToRemove : mappingsToRemove) {
classDescriptor.removeMappingForAttributeName(mappingToRemove.getAttributeName());
}
}
}
示例5: testExtensionAttribute_eclipselink_data
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入方法依赖的package包/类
@Test
public void testExtensionAttribute_eclipselink_data() {
ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
ClassDescriptor referenceDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObjectExtension.class);
assertNotNull("A classDescriptor should have been retrieved from JPA for TestDataObject", classDescriptor);
assertNotNull("A classDescriptor should have been retrieved from JPA for TestDataObjectExtension",
referenceDescriptor);
DatabaseMapping databaseMapping = classDescriptor.getMappingForAttributeName("extension");
assertNotNull("extension mapping missing from metamodel", databaseMapping);
assertTrue("Should be a OneToOne mapping", databaseMapping instanceof OneToOneMapping);
OneToOneMapping mapping = (OneToOneMapping)databaseMapping;
assertEquals("Should be mapped by primaryKeyProperty", "primaryKeyProperty", mapping.getMappedBy());
Map<DatabaseField, DatabaseField> databaseFields = mapping.getSourceToTargetKeyFields();
assertEquals(1, databaseFields.size());
for (DatabaseField sourceField : databaseFields.keySet()) {
DatabaseField targetField = databaseFields.get(sourceField);
assertEquals("PK_PROP", sourceField.getName());
assertEquals("PK_PROP", targetField.getName());
}
assertNotNull("Reference descriptor missing from relationship", mapping.getReferenceDescriptor());
assertEquals("Reference descriptor should be the one for TestDataObjectExtension", referenceDescriptor,
mapping.getReferenceDescriptor());
assertNotNull("selection query relationship missing", mapping.getSelectionQuery());
assertNotNull("selection query missing name", mapping.getSelectionQuery().getName());
assertEquals("selection query name incorrect", "extension", mapping.getSelectionQuery().getName());
assertNotNull("selection query reference class", mapping.getSelectionQuery().getReferenceClass());
assertEquals("selection query reference class incorrect", TestDataObjectExtension.class,
mapping.getSelectionQuery().getReferenceClass());
assertNotNull("selection query reference class name", mapping.getSelectionQuery().getReferenceClassName());
assertNotNull("selection query source mapping missing", mapping.getSelectionQuery().getSourceMapping());
assertEquals("selection query source mapping incorrect", mapping,
mapping.getSelectionQuery().getSourceMapping());
}