Search in sources :

Example 71 with EntityResolver

use of org.apache.cayenne.map.EntityResolver 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 72 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class DbEntityRelationshipPanel method createComboModel.

/**
 * Creates a list of DbEntities.
 */
private ComboBoxModel<DbEntity> createComboModel() {
    EntityResolver resolver = mediator.getEntityResolver();
    DbEntity[] objects = resolver.getDbEntities().toArray(new DbEntity[0]);
    return new DefaultComboBoxModel<>(objects);
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) EntityResolver(org.apache.cayenne.map.EntityResolver) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 73 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class CayenneContextGraphManager method remapTargets.

/**
 * Remaps keys in to-many map relationships that contain dirty objects with
 * potentially modified properties.
 */
private void remapTargets() {
    Iterator<Object> it = stateLog.dirtyIds().iterator();
    EntityResolver resolver = context.getEntityResolver();
    while (it.hasNext()) {
        ObjectId id = (ObjectId) it.next();
        ClassDescriptor descriptor = resolver.getClassDescriptor(id.getEntityName());
        Collection<ArcProperty> mapArcProperties = descriptor.getMapArcProperties();
        if (!mapArcProperties.isEmpty()) {
            Object object = getNode(id);
            for (ArcProperty arc : mapArcProperties) {
                ToManyMapProperty reverseArc = (ToManyMapProperty) arc.getComplimentaryReverseArc();
                Object source = arc.readPropertyDirectly(object);
                if (source != null && !reverseArc.isFault(source)) {
                    remapTarget(reverseArc, source, object);
                }
            }
        }
    }
}
Also used : ArcProperty(org.apache.cayenne.reflect.ArcProperty) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) ToManyMapProperty(org.apache.cayenne.reflect.ToManyMapProperty) EntityResolver(org.apache.cayenne.map.EntityResolver)

Example 74 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class CayenneContextQueryAction method invalidateLocally.

private void invalidateLocally(CayenneContextGraphManager graphManager, Iterator<?> it) {
    if (!it.hasNext()) {
        return;
    }
    EntityResolver resolver = actingContext.getEntityResolver();
    while (it.hasNext()) {
        final Persistent object = (Persistent) it.next();
        // present
        if (object.getPersistenceState() == PersistenceState.NEW) {
            continue;
        }
        ObjectId id = object.getObjectId();
        // per CAY-1082 ROP objects (unlike CayenneDataObject) require all
        // relationship faults invalidation.
        ClassDescriptor descriptor = resolver.getClassDescriptor(id.getEntityName());
        PropertyVisitor arcInvalidator = new PropertyVisitor() {

            public boolean visitAttribute(AttributeProperty property) {
                return true;
            }

            public boolean visitToMany(ToManyProperty property) {
                property.invalidate(object);
                return true;
            }

            public boolean visitToOne(ToOneProperty property) {
                property.invalidate(object);
                return true;
            }
        };
        descriptor.visitProperties(arcInvalidator);
        object.setPersistenceState(PersistenceState.HOLLOW);
        // remove cached changes
        graphManager.changeLog.unregisterNode(id);
        graphManager.stateLog.unregisterNode(id);
    }
}
Also used : ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) ToManyProperty(org.apache.cayenne.reflect.ToManyProperty) EntityResolver(org.apache.cayenne.map.EntityResolver) AttributeProperty(org.apache.cayenne.reflect.AttributeProperty) PropertyVisitor(org.apache.cayenne.reflect.PropertyVisitor) ToOneProperty(org.apache.cayenne.reflect.ToOneProperty)

Example 75 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class HessianConfigTest method testLoadFactoryInjection.

@Test
public void testLoadFactoryInjection() throws Exception {
    EntityResolver resolver = new EntityResolver();
    AbstractSerializerFactory factory = HessianConfig.loadFactory(MockAbstractSerializerFactory.class.getName(), resolver);
    assertTrue(factory instanceof MockAbstractSerializerFactory);
    assertSame(resolver, ((MockAbstractSerializerFactory) factory).getEntityResolver());
}
Also used : AbstractSerializerFactory(com.caucho.hessian.io.AbstractSerializerFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Aggregations

EntityResolver (org.apache.cayenne.map.EntityResolver)87 Test (org.junit.Test)57 ObjEntity (org.apache.cayenne.map.ObjEntity)17 ObjectId (org.apache.cayenne.ObjectId)14 DataMap (org.apache.cayenne.map.DataMap)14 DbEntity (org.apache.cayenne.map.DbEntity)10 ArrayList (java.util.ArrayList)7 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)7 HashMap (java.util.HashMap)6 QueryResponse (org.apache.cayenne.QueryResponse)6 DataNode (org.apache.cayenne.access.DataNode)6 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)6 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)6 MockEventManager (org.apache.cayenne.event.MockEventManager)5 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)5 GenericResponse (org.apache.cayenne.util.GenericResponse)5 List (java.util.List)4 MappingNamespace (org.apache.cayenne.map.MappingNamespace)4 Artist (org.apache.cayenne.testdo.testmap.Artist)4 Map (java.util.Map)3