public String getNewName() { return (entity != null) ? entity.getName() : null; } }
/** * Helper method to evaluate path expression with Cayenne Entity. */ protected Object evaluateEntityNode(Entity entity) { Iterator path = entity.resolvePathComponents(this); Object next = null; while (path.hasNext()) { next = path.next(); } return next; }
/** * * @since 4.0 */ public void updateAttribute(Attribute attribute) { removeAttribute(attribute.getName()); addAttribute(attribute); }
private String uniqueRelName(Entity entity, String preferredName) { int currentSuffix = 1; String relName = preferredName; while (entity.getRelationship(relName) != null || entity.getAttribute(relName) != null) { relName = preferredName + currentSuffix; currentSuffix++; } return relName; }
final MappingNamespace getNonNullNamespace() { MappingNamespace parent = getDataMap(); if (parent == null) { throw new CayenneRuntimeException("Entity '%s' has no parent MappingNamespace (such as DataMap)", getName()); } return parent; } }
public CayenneMapEntry next() { String pathComp = tokens.nextToken(); if(pathComp.endsWith(OUTER_JOIN_INDICATOR)) { pathComp = pathComp.substring(0, pathComp.length() - 1); } // see if this is an attribute Attribute attr = currentEntity.getAttribute(pathComp); if (attr != null) { // do a sanity check... if (tokens.hasMoreTokens()) { throw new ExpressionException("Attribute must be the last component of the path: '%s'.", path, null, pathComp); } return attr; } Relationship rel = currentEntity.getRelationship(pathComp); if (rel != null) { currentEntity = rel.getTargetEntity(); if (currentEntity != null || !tokens.hasMoreTokens()) { //otherwise an exception will be thrown return rel; } } String entityName = (currentEntity != null) ? currentEntity.getName() : "(?)"; throw new ExpressionException("Can't resolve path component: [%s.%s].", path, null, entityName, pathComp); }
/** Changes the name of the attribute in all places in DataMap. */ public static void setRelationshipName(Entity entity, Relationship rel, String newName) { if (rel == null || rel != entity.getRelationship(rel.getName())) { return; } entity.removeRelationship(rel.getName()); rel.setName(newName); entity.addRelationship(rel); }
/** * Returns a Collection of all relationships that belong to this ObjEntity, excluding * inherited attributes. * * @since 1.1 */ public Collection getDeclaredRelationships() { return super.getRelationships(); }
/** * Returns <code>true</code> if path contains a DataMap object. */ public boolean enableForPath(ConfigurationNode object) { if (object == null) { return false; } return ((Entity) object).getDataMap() != null; } }
protected boolean isNameInUse(String name, Object namingContext) { Entity ent = (Entity) namingContext; return ent.getAttribute(name) != null; } }
/** * Creates label for this cell */ String createLabel() { Entity entity = fetchEntity(); StringBuilder label = new StringBuilder("<html><center><u><b>"). append(entity.getName()).append("</b></u></center>"); for (Attribute attr : entity.getAttributes()) { if (isPrimary(attr)) { label.append("<br><i>").append(attr.getName()).append("</i>"); } } for (Attribute attr : entity.getAttributes()) { if (!isPrimary(attr)) { label.append("<br>").append(attr.getName()); } } return label.toString(); }
protected boolean isNameInUse(String name, Object namingContext) { Entity ent = (Entity) namingContext; return ent.getRelationship(name) != null; }
public void traverseEntities(Iterator entities, ProjectPath path) { if (sort) { entities = Util .sortedIterator(entities, ProjectTraversal.mapObjectComparator); } while (entities.hasNext()) { Entity ent = (Entity) entities.next(); ProjectPath entPath = path.appendToPath(ent); handler.projectNode(entPath); if (handler.shouldReadChildren(ent, path)) { this.traverseAttributes(ent.getAttributes().iterator(), entPath); this.traverseRelationships(ent.getRelationships().iterator(), entPath); } } }
/** * Updates missing mapping artifacts that can be guessed from other mapping * information. This implementation creates missing reverse relationships, * marking newly created relationships as "runtime". * * @since 3.0 */ public void applyDBLayerDefaults() { // connect DB layer for (DataMap map : getDataMaps()) { for (DbEntity entity : map.getDbEntities()) { // iterate by copy to avoid concurrency modification errors on // reflexive relationships DbRelationship[] relationships = entity.getRelationships().toArray( new DbRelationship[entity.getRelationships().size()]); for (DbRelationship relationship : relationships) { if (relationship.getReverseRelationship() == null) { DbRelationship reverse = relationship.createReverseRelationship(); Entity targetEntity = reverse.getSourceEntity(); reverse.setName(getUniqueRelationshipName(targetEntity)); reverse.setRuntime(true); targetEntity.addRelationship(reverse); logger.info("added runtime complimentary DbRelationship from " + targetEntity.getName() + " to " + reverse.getTargetEntityName()); } } } } }
Entity srcEnt = dbRel.getSourceEntity(); if (srcEnt == null || map.getDbEntity(srcEnt.getName()) != srcEnt || srcEnt.getRelationship(dbRel.getName()) != dbRel) { rel.removeDbRelationship(dbRel);
/** * Returns a Collection of all attributes that either belong to this * DbEntity or inherited. */ @SuppressWarnings("unchecked") @Override public Collection<DbAttribute> getAttributes() { return (Collection<DbAttribute>) super.getAttributes(); }
/** * @since 3.0 */ @Override @SuppressWarnings("unchecked") public PathComponent<ObjAttribute, ObjRelationship> lastPathComponent(Expression path, Map aliasMap) { return super.lastPathComponent(path, aliasMap); }
/** * Adds a new attribute to this entity. * * @throws IllegalArgumentException if Attribute has no name or there is an existing attribute * with the same name * @throws IllegalArgumentException if a relationship has the same name as this attribute * @since 3.0 */ public void addAttribute(DbAttribute attr) { super.addAttribute(attr); this.dbAttributeAdded(new AttributeEvent(this, attr, this, MapEvent.ADD)); }
source.removeRelationship(relationship.getName()); relationship.setName(DbLoader.uniqueRelName(source, relationship .getTargetEntityName(), false)); source.addRelationship(relationship);
/** * Convenience method returning the last component in the path iterator. If the last * component is an alias, it is fully resolved down to the last ObjRelationship. * * @since 3.0 */ @SuppressWarnings("unchecked") public <T extends Attribute, U extends Relationship> PathComponent<T, U> lastPathComponent( Expression path, Map aliasMap) { for (PathComponent component : resolvePath(path, aliasMap)) { if (component.isLast()) { // resolve aliases if needed return lastPathComponent(component); } } return null; }