本文整理汇总了Java中org.eclipse.persistence.descriptors.ClassDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java ClassDescriptor类的具体用法?Java ClassDescriptor怎么用?Java ClassDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassDescriptor类属于org.eclipse.persistence.descriptors包,在下文中一共展示了ClassDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMappingOnChildren
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
private DatabaseMapping findMappingOnChildren(InheritancePolicy policy, String name) {
ArrayList<DatabaseMapping> found = new ArrayList<>();
for (ClassDescriptor child : policy.getChildDescriptors()) {
DatabaseMapping childMapping = child.getObjectBuilder().getMappingForAttributeName(name);
if (childMapping != null) {
found.add(childMapping);
}
}
switch (found.size()) {
case 0:
return null;
case 1:
return found.get(0);
default:
throw new JoinerException("Multiple mappings found for name " + name);
}
}
示例2: extractIdPropertyNames
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
@Override
public String[] extractIdPropertyNames(Object entity)
{
final EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
final ClassDescriptor desc = em.unwrap(JpaEntityManager.class).getServerSession().getClassDescriptor(entity);
if (desc != null)
{
final Collection<DatabaseMapping> fieldNames = desc.getMappings();
final List<DatabaseMapping> tmp = new LinkedList<>();
for (DatabaseMapping m : fieldNames)
{
if (m.isPrimaryKeyMapping())
{
tmp.add(m);
}
}
final String[] retVal = new String[tmp.size()];
for (int i = 0; i < retVal.length; i++)
{
retVal[i] = tmp.get(i).getAttributeName();
}
return retVal;
}
return null;
}
示例3: getPrimaryKeys
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
public String[] getPrimaryKeys(ClassDescriptor cd) {
if (!cd.hasSimplePrimaryKey()) {
throw new RuntimeException("only simple primary key is currently supported.");
}
List<DatabaseField> primaryKeyFields = cd.getPrimaryKeyFields();
String[] res = new String[primaryKeyFields.size()];
int i = 0;
for (DatabaseField f : primaryKeyFields) {
try {
Field field = cd.getJavaClass().getDeclaredField(f.getName()); // f.getTypeName() is null :-(
res[i++] = field.getType().getSimpleName() + " " + f.getName();
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
return res;
}
示例4: customize
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
@Override
public void customize(Session session) throws Exception {
for (ClassDescriptor descriptor : session.getDescriptors().values()) {
if (!descriptor.getTables().isEmpty() && descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) {
String tableName = addUnderscores(descriptor.getAlias()).toUpperCase();
System.out.println(descriptor.getAlias() + ":" + tableName);
descriptor.setTableName(tableName);
DatabaseTable databaseTable = descriptor.getTables().get(0);
for (IndexDefinition indexDef : databaseTable.getIndexes()) {
indexDef.setTargetTable(tableName);
}
}
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (mapping.getField() != null
&& !mapping.getAttributeName().isEmpty()
&& mapping.getField().getName().equalsIgnoreCase(mapping.getAttributeName())) {
mapping.getField().setName(
addUnderscores(mapping.getAttributeName()).toUpperCase()
);
}
}
}
}
示例5: findExtensionInverse
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
/**
* Gets the inverse extension of the given {@link ClassDescriptor}.
*
* @param extensionEntityDescriptor the {@link ClassDescriptor} of which to get the inverse.
* @param entityType the type of the entity.
* @return the inverse extension of the given {@link ClassDescriptor}.
*/
protected OneToOneMapping findExtensionInverse(ClassDescriptor extensionEntityDescriptor, Class<?> entityType) {
Collection<DatabaseMapping> derivedIdMappings = extensionEntityDescriptor.getDerivesIdMappinps();
String extensionInfo = "(" + extensionEntityDescriptor.getJavaClass().getName() + " -> " + entityType.getName()
+ ")";
if (derivedIdMappings == null || derivedIdMappings.isEmpty()) {
throw new MetadataConfigurationException("Attempting to use extension framework, but extension "
+ extensionInfo + " does not have a valid inverse OneToOne Id mapping back to the extended data "
+ "object. Please ensure it is annotated property for use of the extension framework with JPA.");
} else if (derivedIdMappings.size() > 1) {
throw new MetadataConfigurationException("When attempting to determine the inverse relationship for use "
+ "with extension framework " + extensionInfo + " encountered more than one 'derived id' mapping, "
+ "there should be only one!");
}
DatabaseMapping inverseMapping = derivedIdMappings.iterator().next();
if (!(inverseMapping instanceof OneToOneMapping)) {
throw new MetadataConfigurationException("Identified an inverse derived id mapping for extension "
+ "relationship " + extensionInfo + " but it was not a one-to-one mapping: " + inverseMapping);
}
return (OneToOneMapping)inverseMapping;
}
示例6: loadQueryCustomizers
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
/**
* Load Query Customizer based on annotations on fields and call customizer to modify descriptor.
*
* @param session the EclipseLink session.
*/
protected void loadQueryCustomizers(Session session) {
Map<Class, ClassDescriptor> descriptors = session.getDescriptors();
for (Class<?> entityClass : descriptors.keySet()) {
for (Field field : entityClass.getDeclaredFields()) {
String queryCustEntry = entityClass.getName() + "_" + field.getName();
buildQueryCustomizers(entityClass,field,queryCustEntry);
List<FilterGenerator> queryCustomizers = queryCustomizerMap.get(queryCustEntry);
if (queryCustomizers != null && !queryCustomizers.isEmpty()) {
Filter.customizeField(queryCustomizers, descriptors.get(entityClass), field.getName());
}
}
}
}
示例7: handleDisableVersioning
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
/**
* Checks class descriptors for {@link @DisableVersioning} annotations at the class level and removes the version
* database mapping for optimistic locking.
*
* @param session the current session.
*/
protected void handleDisableVersioning(Session session) {
Map<Class, ClassDescriptor> descriptors = session.getDescriptors();
if (descriptors == null || descriptors.isEmpty()) {
return;
}
for (ClassDescriptor classDescriptor : descriptors.values()) {
if (classDescriptor != null && AnnotationUtils.findAnnotation(classDescriptor.getJavaClass(),
DisableVersioning.class) != null) {
OptimisticLockingPolicy olPolicy = classDescriptor.getOptimisticLockingPolicy();
if (olPolicy != null) {
classDescriptor.setOptimisticLockingPolicy(null);
}
}
}
}
示例8: scanForRemoveMappings
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
/**
* Gets any {@link RemoveMapping}s out of the given {@link ClassDescriptor}.
*
* @param classDescriptor the {@link ClassDescriptor} to scan.
* @return a list of {@link RemoveMapping}s from the given {@link ClassDescriptor}.
*/
protected List<RemoveMapping> scanForRemoveMappings(ClassDescriptor classDescriptor) {
List<RemoveMapping> removeMappings = new ArrayList<RemoveMapping>();
RemoveMappings removeMappingsAnnotation = AnnotationUtils.findAnnotation(classDescriptor.getJavaClass(),
RemoveMappings.class);
if (removeMappingsAnnotation == null) {
RemoveMapping removeMappingAnnotation = AnnotationUtils.findAnnotation(classDescriptor.getJavaClass(),
RemoveMapping.class);
if (removeMappingAnnotation != null) {
removeMappings.add(removeMappingAnnotation);
}
} else {
for (RemoveMapping removeMapping : removeMappingsAnnotation.value()) {
removeMappings.add(removeMapping);
}
}
return removeMappings;
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: customize
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
@Override
public void customize(final Session session) throws SQLException {
for (ClassDescriptor descriptor : session.getDescriptors().values()) {
if (!descriptor.getTables().isEmpty()) {
// Take table name from @Table if exists
String tableName = null;
if (descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) {
tableName = unqualify(descriptor.getJavaClassName());
} else {
tableName = descriptor.getTableName();
}
tableName = camelCaseToUnderscore(tableName);
descriptor.setTableName(tableName);
for (IndexDefinition index : descriptor.getTables().get(0).getIndexes()) {
index.setTargetTable(tableName);
}
Vector<DatabaseMapping> mappings = descriptor.getMappings();
camelCaseToUnderscore(mappings);
} else if (descriptor.isAggregateDescriptor() || descriptor.isChildDescriptor()) {
camelCaseToUnderscore(descriptor.getMappings());
}
}
}
示例13: customize
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
@Override
public void customize(final Session session) throws SQLException {
for (ClassDescriptor descriptor : session.getDescriptors().values()) {
if (!descriptor.getTables().isEmpty()) {
// Take table name from @Table if exists
String tableName = null;
if (descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) {
tableName = unqualify(descriptor.getJavaClassName());
} else {
tableName = descriptor.getTableName();
}
tableName = camelCaseToUnderscore(tableName);
descriptor.setTableName(tableName);
for (IndexDefinition index : descriptor.getTables().get(0).getIndexes()) {
index.setTargetTable(tableName);
}
Vector<DatabaseMapping> mappings = descriptor.getMappings();
camelCaseToUnderscore(mappings);
} else if (descriptor.isAggregateDescriptor() || descriptor.isChildDescriptor()) {
camelCaseToUnderscore(descriptor.getMappings());
}
}
}
示例14: getManagedAttribute
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
private Attribute getManagedAttribute(ClassDescriptor refDescriptor, DatabaseField dbField, LinkedList<Attribute> intrinsicAttribute) {
if (refDescriptor != null) {
for (DatabaseMapping refMapping : refDescriptor.getMappings()) {
if(!refMapping.getFields()
.stream()
.filter(field -> field == dbField)
.findAny()
.isPresent()){
continue;
}
if (refMapping.getFields().size() > 1) {
intrinsicAttribute.add((Attribute) refMapping.getProperty(Attribute.class));
if(refMapping.getReferenceDescriptor() == refDescriptor){ //self-relationship with composite pk
return (Attribute) refMapping.getProperty(Attribute.class);
} else {
return getManagedAttribute(refMapping.getReferenceDescriptor(), dbField, intrinsicAttribute);
}
} else if (!refMapping.getFields().isEmpty() && refMapping.getFields().get(0) == dbField) {
intrinsicAttribute.add((Attribute) refMapping.getProperty(Attribute.class));
return (Attribute) refMapping.getProperty(Attribute.class);
}
}
}
return null;
}
示例15: getDatabaseMapping
import org.eclipse.persistence.descriptors.ClassDescriptor; //导入依赖的package包/类
private DatabaseMapping getDatabaseMapping(ClassDescriptor descriptor, DatabaseField databaseField) {
DatabaseMapping databaseMapping = mappings.get(databaseField);
if (databaseMapping == null) {
for (DatabaseMapping m : descriptor.getMappings()) {
for (DatabaseField f : m.getFields()) {
if (mappings.get(f) == null) {
mappings.put(f, m);
}
if (databaseField == f) {
databaseMapping = m;
}
}
}
}
return databaseMapping;
}