Search in sources :

Example 1 with SingletonFaultFactory

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

the class DataObjectDescriptorFactoryIT method testVisitDeclaredProperties_IterationOrder.

@Test
public void testVisitDeclaredProperties_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.visitDeclaredProperties(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 2 with SingletonFaultFactory

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

the class EntityResolver method getClassDescriptorMap.

/**
 * Returns an object that compiles and stores {@link ClassDescriptor}
 * instances for all entities.
 *
 * @since 3.0
 */
public ClassDescriptorMap getClassDescriptorMap() {
    if (classDescriptorMap == null) {
        synchronized (this) {
            if (classDescriptorMap == null) {
                ClassDescriptorMap classDescriptorMap = new ClassDescriptorMap(this);
                FaultFactory faultFactory = new SingletonFaultFactory();
                // add factories in reverse of the desired chain order
                classDescriptorMap.addFactory(new ValueHolderDescriptorFactory(classDescriptorMap));
                classDescriptorMap.addFactory(new DataObjectDescriptorFactory(classDescriptorMap, faultFactory));
                // it with entity proxies here.
                for (DataMap map : maps) {
                    for (String entityName : map.getObjEntityMap().keySet()) {
                        classDescriptorMap.getDescriptor(entityName);
                    }
                }
                this.classDescriptorMap = classDescriptorMap;
            }
        }
    }
    return classDescriptorMap;
}
Also used : ValueHolderDescriptorFactory(org.apache.cayenne.reflect.valueholder.ValueHolderDescriptorFactory) SingletonFaultFactory(org.apache.cayenne.reflect.SingletonFaultFactory) DataObjectDescriptorFactory(org.apache.cayenne.reflect.generic.DataObjectDescriptorFactory) ClassDescriptorMap(org.apache.cayenne.reflect.ClassDescriptorMap) FaultFactory(org.apache.cayenne.reflect.FaultFactory) SingletonFaultFactory(org.apache.cayenne.reflect.SingletonFaultFactory)

Example 3 with SingletonFaultFactory

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

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

Aggregations

SingletonFaultFactory (org.apache.cayenne.reflect.SingletonFaultFactory)4 ObjEntity (org.apache.cayenne.map.ObjEntity)3 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)3 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)3 PropertyDescriptor (org.apache.cayenne.reflect.PropertyDescriptor)3 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)3 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)3 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)3 Test (org.junit.Test)3 ClassDescriptorMap (org.apache.cayenne.reflect.ClassDescriptorMap)1 FaultFactory (org.apache.cayenne.reflect.FaultFactory)1 DataObjectDescriptorFactory (org.apache.cayenne.reflect.generic.DataObjectDescriptorFactory)1 ValueHolderDescriptorFactory (org.apache.cayenne.reflect.valueholder.ValueHolderDescriptorFactory)1