1 19 package org.apache.cayenne.reflect.pojo; 20 21 import java.util.Collection ; 22 23 import org.apache.cayenne.map.ObjEntity; 24 import org.apache.cayenne.map.ObjRelationship; 25 import org.apache.cayenne.reflect.Accessor; 26 import org.apache.cayenne.reflect.ClassDescriptor; 27 import org.apache.cayenne.reflect.ClassDescriptorFactory; 28 import org.apache.cayenne.reflect.ClassDescriptorMap; 29 import org.apache.cayenne.reflect.PersistentDescriptor; 30 import org.apache.cayenne.reflect.PersistentDescriptorFactory; 31 32 38 public class EnhancedPojoDescriptorFactory extends PersistentDescriptorFactory { 39 40 static final String PERSISTENCE_STATE_FIELD = "$cay_persistenceState"; 41 42 public EnhancedPojoDescriptorFactory(ClassDescriptorMap descriptorMap) { 43 super(descriptorMap); 44 } 45 46 protected ClassDescriptor getDescriptor(ObjEntity entity, Class entityClass) { 47 try { 49 Integer.TYPE.equals(entityClass 50 .getDeclaredField(PERSISTENCE_STATE_FIELD) 51 .getType()); 52 } 53 catch (Throwable th) { 54 return null; 55 } 56 57 return super.getDescriptor(entity, entityClass); 58 } 59 60 protected void createToManyProperty( 61 PersistentDescriptor descriptor, 62 ObjRelationship relationship) { 63 64 ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship 65 .getTargetEntityName()); 66 String reverseName = relationship.getReverseRelationshipName(); 67 68 Accessor accessor = createAccessor( 69 descriptor, 70 relationship.getName(), 71 Collection .class); 72 descriptor.addDeclaredProperty(new EnhancedPojoToManyProperty( 73 descriptor, 74 targetDescriptor, 75 accessor, 76 reverseName)); 77 } 78 79 protected void createToOneProperty( 80 PersistentDescriptor descriptor, 81 ObjRelationship relationship) { 82 83 ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship 84 .getTargetEntityName()); 85 String reverseName = relationship.getReverseRelationshipName(); 86 87 Accessor accessor = createAccessor( 88 descriptor, 89 relationship.getName(), 90 targetDescriptor.getObjectClass()); 91 descriptor.addDeclaredProperty(new EnhancedPojoToOneProperty( 92 descriptor, 93 targetDescriptor, 94 accessor, 95 reverseName)); 96 } 97 } 98 | Popular Tags |