Search in sources :

Example 11 with PropertyDescriptor

use of org.apache.cayenne.reflect.PropertyDescriptor 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 12 with PropertyDescriptor

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

the class RelationshipFault method updateReverse.

// see if reverse relationship is to-one and we can connect source to
// results....
protected void updateReverse(List<E> resolved) {
    EntityResolver resolver = relationshipOwner.getObjectContext().getEntityResolver();
    ObjEntity sourceEntity = resolver.getObjEntity(relationshipOwner.getObjectId().getEntityName());
    ObjRelationship relationship = sourceEntity.getRelationship(relationshipName);
    ObjRelationship reverse = relationship.getReverseRelationship();
    if (reverse != null && !reverse.isToMany()) {
        PropertyDescriptor property = resolver.getClassDescriptor(reverse.getSourceEntity().getName()).getProperty(reverse.getName());
        for (Object o : resolved) {
            property.writePropertyDirectly(o, null, relationshipOwner);
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) PropertyDescriptor(org.apache.cayenne.reflect.PropertyDescriptor) EntityResolver(org.apache.cayenne.map.EntityResolver)

Example 13 with PropertyDescriptor

use of org.apache.cayenne.reflect.PropertyDescriptor 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)

Example 14 with PropertyDescriptor

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

the class DataObjectDescriptorFactory_InheritanceMapsIT 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) {
                DataObjectDescriptorFactoryIT.assertPropertiesAreInOrder(lastProcessed[0], property);
                lastProcessed[0] = property;
                return true;
            }

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

            public boolean visitAttribute(AttributeProperty property) {
                DataObjectDescriptorFactoryIT.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)

Example 15 with PropertyDescriptor

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

the class PersistentObject method getMapKey.

/**
 * Returns a map key for a given to-many map relationship and a target object.
 *
 * @since 3.0
 */
protected Object getMapKey(String relationshipName, Object value) {
    EntityResolver resolver = objectContext.getEntityResolver();
    ClassDescriptor descriptor = resolver.getClassDescriptor(objectId.getEntityName());
    if (descriptor == null) {
        throw new IllegalStateException("DataObject's entity is unmapped, objectId: " + objectId);
    }
    PropertyDescriptor property = descriptor.getProperty(relationshipName);
    if (property instanceof ToManyMapProperty) {
        return ((ToManyMapProperty) property).getMapKey(value);
    }
    throw new IllegalArgumentException("Relationship '" + relationshipName + "' is not a to-many Map");
}
Also used : ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) PropertyDescriptor(org.apache.cayenne.reflect.PropertyDescriptor) ToManyMapProperty(org.apache.cayenne.reflect.ToManyMapProperty) EntityResolver(org.apache.cayenne.map.EntityResolver)

Aggregations

PropertyDescriptor (org.apache.cayenne.reflect.PropertyDescriptor)16 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)14 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)9 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)8 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)8 ArcProperty (org.apache.cayenne.reflect.ArcProperty)5 Persistent (org.apache.cayenne.Persistent)4 ObjEntity (org.apache.cayenne.map.ObjEntity)4 Test (org.junit.Test)4 SingletonFaultFactory (org.apache.cayenne.reflect.SingletonFaultFactory)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ObjectId (org.apache.cayenne.ObjectId)2 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)2 EntityResolver (org.apache.cayenne.map.EntityResolver)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 PrefetchTreeNode (org.apache.cayenne.query.PrefetchTreeNode)2 Accessor (org.apache.cayenne.reflect.Accessor)2