use of org.apache.cayenne.map.Relationship in project cayenne by apache.
the class PrefetchModel method isToMany.
private boolean isToMany(String prefetch) {
// totally invalid path would result in ExpressionException
try {
Expression exp = ExpressionFactory.exp(prefetch);
Object object = exp.evaluate(root);
return object instanceof Relationship && ((Relationship) object).isToMany();
} catch (ExpressionException e) {
return false;
}
}
use of org.apache.cayenne.map.Relationship in project cayenne by apache.
the class ObjRelationshipInfo method connectEnds.
// Connects last selected DbRelationship in the path to the
// last DbEntity, creating a dummy relationship if needed.
private void connectEnds() {
Relationship last = null;
int size = dbRelationships.size();
if (size > 0) {
last = dbRelationships.get(size - 1);
}
Entity target = getEndEntity();
if (target != null && (last == null || last.getTargetEntity() != target)) {
// try to connect automatically, if we can't use dummy connector
Entity source = (last == null) ? getStartEntity() : last.getTargetEntity();
if (source != null) {
Relationship anyConnector = source != null ? source.getAnyRelationship(target) : null;
if (anyConnector != null) {
dbRelationships.add((DbRelationship) anyConnector);
}
}
}
}
use of org.apache.cayenne.map.Relationship in project cayenne by apache.
the class EntityTreeModel method sortedChildren.
private ConfigurationNode[] sortedChildren(Object node) {
Entity entity = entityForNonLeafNode(node);
// may happen in incomplete relationships
if (entity == null) {
return new ConfigurationNode[0];
}
ConfigurationNode[] sortedForNode = sortedChildren.get(node);
if (sortedForNode == null) {
Collection<? extends Attribute> attributes = entity.getAttributes();
Collection<? extends Relationship> relationships = entity.getRelationships();
List<ConfigurationNode> nodes = new ArrayList<>();
// combine two collections in an array
for (Attribute attr : attributes) {
if (filter == null || filter.attributeMatch(node, attr)) {
nodes.add((ConfigurationNode) attr);
}
}
for (Relationship rel : relationships) {
if (filter == null || filter.relationshipMatch(node, rel)) {
nodes.add((ConfigurationNode) rel);
}
}
sortedForNode = nodes.toArray(new ConfigurationNode[0]);
Arrays.sort(sortedForNode, Comparators.getEntityChildrenComparator());
sortedChildren.put(node, sortedForNode);
}
return sortedForNode;
}
use of org.apache.cayenne.map.Relationship in project cayenne by apache.
the class RelationshipDisplayEventType method getLastEntityRelationships.
private Relationship[] getLastEntityRelationships(Entity entity) {
List<Relationship> relationshipList = new ArrayList<>();
String rels = (entity instanceof ObjEntity) ? preferences.getObjRels() : preferences.getDbRels();
for (String objRelName : rels.split(",")) {
Relationship rel = entity.getRelationship(objRelName);
if (rel != null) {
relationshipList.add(rel);
}
}
return relationshipList.toArray(new Relationship[0]);
}
use of org.apache.cayenne.map.Relationship in project cayenne by apache.
the class RelationshipDisplayEventType 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;
}
Relationship[] relationships = getLastEntityRelationships(entity);
EntityDisplayEvent entityDisplayEvent = new EntityDisplayEvent(this, entity, dataMap, dataNode, dataChannel);
RelationshipDisplayEvent displayEvent = new RelationshipDisplayEvent(this, relationships, entity, dataMap, dataChannel);
if (entity instanceof ObjEntity) {
controller.fireObjEntityDisplayEvent(entityDisplayEvent);
controller.fireObjRelationshipDisplayEvent(displayEvent);
} else if (entity instanceof DbEntity) {
controller.fireDbEntityDisplayEvent(entityDisplayEvent);
controller.fireDbRelationshipDisplayEvent(displayEvent);
}
}
Aggregations