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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
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");
}
Aggregations