Search in sources :

Example 16 with Entity

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

the class DbAttributePathComboBoxEditor method getFirstEntity.

private Entity getFirstEntity(ObjAttribute attribute) {
    Iterator<CayenneMapEntry> it = attribute.getDbPathIterator();
    Entity firstEnt = attribute.getDbAttribute().getEntity();
    boolean setEnt = false;
    while (it.hasNext()) {
        Object ob = it.next();
        if (ob instanceof DbRelationship) {
            if (!setEnt) {
                firstEnt = ((DbRelationship) ob).getSourceEntity();
                setEnt = true;
            }
        } else if (ob instanceof DbAttribute) {
            if (!setEnt) {
                firstEnt = ((DbAttribute) ob).getEntity();
            }
        }
    }
    return firstEnt;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 17 with Entity

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

the class ProjectUtil method getRelationshipsUsingAttributeAsTarget.

/**
 * Returns a collection of DbRelationships that use this attribute as a source.
 */
public static Collection<DbRelationship> getRelationshipsUsingAttributeAsTarget(DbAttribute attribute) {
    Entity parent = attribute.getEntity();
    if (parent == null) {
        return Collections.EMPTY_LIST;
    }
    DataMap map = parent.getDataMap();
    if (map == null) {
        return Collections.EMPTY_LIST;
    }
    Collection<DbRelationship> relationships = new ArrayList<DbRelationship>();
    for (Entity entity : map.getDbEntities()) {
        if (entity == parent) {
            continue;
        }
        Collection<DbRelationship> entityRelationships = (Collection<DbRelationship>) entity.getRelationships();
        for (DbRelationship relationship : entityRelationships) {
            if (ProjectUtil.containsTargetAttribute(relationship, attribute)) {
                relationships.add(relationship);
            }
        }
    }
    return relationships;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DataMap(org.apache.cayenne.map.DataMap)

Example 18 with Entity

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

the class ProjectUtil method setAttributeName.

/**
 * Changes the name of the attribute and all references to this attribute.
 */
public static void setAttributeName(Attribute attribute, String newName) {
    String oldName = attribute.getName();
    attribute.setName(newName);
    Entity entity = attribute.getEntity();
    if (entity != null) {
        entity.removeAttribute(oldName);
        entity.addAttribute(attribute);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity)

Example 19 with Entity

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

the class AttributeDisplayEventType method fireLastDisplayEvent.

@Override
public void fireLastDisplayEvent() {
    DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
    if (!dataChannel.getName().equals(preferences.getDomain())) {
        return;
    }
    DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(preferences.getNode());
    DataMap dataMap = dataChannel.getDataMap(preferences.getDataMap());
    if (dataMap == null) {
        return;
    }
    Entity entity = getLastEntity(dataMap);
    if (entity == null) {
        return;
    }
    Attribute[] attributes = getLastEntityAttributes(entity);
    EntityDisplayEvent entityDisplayEvent = new EntityDisplayEvent(this, entity, dataMap, dataNode, dataChannel);
    AttributeDisplayEvent attributeDisplayEvent = new AttributeDisplayEvent(this, attributes, entity, dataMap, dataChannel);
    if (entity instanceof ObjEntity) {
        controller.fireObjEntityDisplayEvent(entityDisplayEvent);
        controller.fireObjAttributeDisplayEvent(attributeDisplayEvent);
    } else if (entity instanceof DbEntity) {
        controller.fireDbEntityDisplayEvent(entityDisplayEvent);
        controller.fireDbAttributeDisplayEvent(attributeDisplayEvent);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) ObjEntity(org.apache.cayenne.map.ObjEntity) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) DbEntity(org.apache.cayenne.map.DbEntity) Attribute(org.apache.cayenne.map.Attribute) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 20 with Entity

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

the class EntityEventTest method testConstructor2.

@Test
public void testConstructor2() throws Exception {
    Object src = new Object();
    Entity d = new DbEntity("abc");
    EntityEvent e = new EntityEvent(src, d, "oldname");
    assertSame(src, e.getSource());
    assertSame(d, e.getEntity());
    assertEquals("oldname", e.getOldName());
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) Test(org.junit.Test)

Aggregations

Entity (org.apache.cayenne.map.Entity)38 DbEntity (org.apache.cayenne.map.DbEntity)24 ObjEntity (org.apache.cayenne.map.ObjEntity)23 DataMap (org.apache.cayenne.map.DataMap)10 DbRelationship (org.apache.cayenne.map.DbRelationship)9 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)6 DbAttribute (org.apache.cayenne.map.DbAttribute)6 Attribute (org.apache.cayenne.map.Attribute)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)5 Relationship (org.apache.cayenne.map.Relationship)5 EntityEvent (org.apache.cayenne.map.event.EntityEvent)5 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2