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