Search in sources :

Example 51 with ClassDescriptor

use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.

the class ValueHolderDescriptorFactory method createToManyListProperty.

@Override
protected void createToManyListProperty(PersistentDescriptor descriptor, ObjRelationship relationship) {
    ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship.getTargetEntityName());
    String reverseName = relationship.getReverseRelationshipName();
    Accessor accessor = createAccessor(descriptor, relationship.getName(), List.class);
    descriptor.addDeclaredProperty(new ValueHolderListProperty(descriptor, targetDescriptor, accessor, reverseName));
}
Also used : ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) Accessor(org.apache.cayenne.reflect.Accessor)

Example 52 with ClassDescriptor

use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.

the class ValueHolderDescriptorFactory method createToManyMapProperty.

@Override
protected void createToManyMapProperty(PersistentDescriptor descriptor, ObjRelationship relationship) {
    ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship.getTargetEntityName());
    String reverseName = relationship.getReverseRelationshipName();
    Accessor accessor = createAccessor(descriptor, relationship.getName(), Map.class);
    Accessor mapKeyAccessor = createMapKeyAccessor(relationship, targetDescriptor);
    PropertyDescriptor property = new ValueHolderMapProperty(descriptor, targetDescriptor, accessor, reverseName, mapKeyAccessor);
    descriptor.addDeclaredProperty(property);
}
Also used : ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) PropertyDescriptor(org.apache.cayenne.reflect.PropertyDescriptor) Accessor(org.apache.cayenne.reflect.Accessor)

Example 53 with ClassDescriptor

use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.

the class ValueHolderDescriptorFactory method createToManyCollectionProperty.

@Override
protected void createToManyCollectionProperty(PersistentDescriptor descriptor, ObjRelationship relationship) {
    ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship.getTargetEntityName());
    String reverseName = relationship.getReverseRelationshipName();
    Accessor accessor = createAccessor(descriptor, relationship.getName(), List.class);
    descriptor.addDeclaredProperty(new ValueHolderListProperty(descriptor, targetDescriptor, accessor, reverseName));
}
Also used : ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) Accessor(org.apache.cayenne.reflect.Accessor)

Example 54 with ClassDescriptor

use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.

the class ObjectContextGraphAction method handlePropertyChange.

/**
 * Handles property change in a Persistent object, routing to either
 * {@link #handleArcPropertyChange(Persistent, ArcProperty, Object, Object)} or
 * {@link #handleSimplePropertyChange(Persistent, String, Object, Object)}.
 */
public void handlePropertyChange(Persistent object, String propertyName, Object oldValue, Object newValue) {
    // translate ObjectContext generic property change callback to GraphManager terms
    // (simple properties vs. relationships)
    ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(object.getObjectId().getEntityName());
    PropertyDescriptor property = descriptor.getProperty(propertyName);
    if (property instanceof ArcProperty) {
        handleArcPropertyChange(object, (ArcProperty) property, oldValue, newValue);
    } else {
        handleSimplePropertyChange(object, propertyName, oldValue, newValue);
    }
}
Also used : ArcProperty(org.apache.cayenne.reflect.ArcProperty) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) PropertyDescriptor(org.apache.cayenne.reflect.PropertyDescriptor)

Example 55 with ClassDescriptor

use of org.apache.cayenne.reflect.ClassDescriptor in project cayenne by apache.

the class DataObjectDescriptorFactoryIT method testVisitProperties_IterationOrder.

@Test
public void testVisitProperties_IterationOrder() {
    DataObjectDescriptorFactory factory = new DataObjectDescriptorFactory(resolver.getClassDescriptorMap(), new SingletonFaultFactory());
    for (ObjEntity e : resolver.getObjEntities()) {
        ClassDescriptor descriptor = factory.getDescriptor(e.getName());
        final PropertyDescriptor[] lastProcessed = new PropertyDescriptor[1];
        PropertyVisitor visitor = new PropertyVisitor() {

            public boolean visitToOne(ToOneProperty property) {
                assertPropertiesAreInOrder(lastProcessed[0], property);
                lastProcessed[0] = property;
                return true;
            }

            public boolean visitToMany(ToManyProperty property) {
                assertPropertiesAreInOrder(lastProcessed[0], property);
                lastProcessed[0] = property;
                return true;
            }

            public boolean visitAttribute(AttributeProperty property) {
                assertPropertiesAreInOrder(lastProcessed[0], property);
                lastProcessed[0] = property;
                return true;
            }
        };
        descriptor.visitProperties(visitor);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) SingletonFaultFactory(org.apache.cayenne.reflect.SingletonFaultFactory) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) PropertyDescriptor(org.apache.cayenne.reflect.PropertyDescriptor) ToManyProperty(org.apache.cayenne.reflect.ToManyProperty) AttributeProperty(org.apache.cayenne.reflect.AttributeProperty) PropertyVisitor(org.apache.cayenne.reflect.PropertyVisitor) ToOneProperty(org.apache.cayenne.reflect.ToOneProperty) Test(org.junit.Test)

Aggregations

ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)81 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)23 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)21 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)21 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)21 ObjEntity (org.apache.cayenne.map.ObjEntity)18 ArcProperty (org.apache.cayenne.reflect.ArcProperty)18 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 Persistent (org.apache.cayenne.Persistent)17 ObjectId (org.apache.cayenne.ObjectId)14 PropertyDescriptor (org.apache.cayenne.reflect.PropertyDescriptor)14 DbRelationship (org.apache.cayenne.map.DbRelationship)13 ObjRelationship (org.apache.cayenne.map.ObjRelationship)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 DataRow (org.apache.cayenne.DataRow)10 DbAttribute (org.apache.cayenne.map.DbAttribute)10 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)9 DbEntity (org.apache.cayenne.map.DbEntity)9 DbJoin (org.apache.cayenne.map.DbJoin)9