public void setSavedDbRelationships(List<DbRelationship> rels) { this.savedDbRelationships = rels; String currPath = ""; for (DbRelationship rel : rels) { currPath += "->" + rel.getName(); } if (rels.size() > 0) { currPath = currPath.substring(2); } currentPath = currPath; view.currentPathLabel.setText(currPath); }
@Override public String relationshipName(DbRelationship... relationshipChain) { if(relationshipChain.length == 0) { return super.relationshipName(relationshipChain); } DbRelationship last = relationshipChain[relationshipChain.length - 1]; // must be in sync with DefaultBaseNameVisitor.visitDbRelationship if(last.getName().startsWith("untitledRel")) { return super.relationshipName(relationshipChain); } // keep manually set relationship name return last.getName(); } }
private void prependReversedPath(LinkedList<String> finalPath, DbRelationship relationship) { DbRelationship revNextDBR = relationship.getReverseRelationship(); if (revNextDBR == null) { throw new CayenneRuntimeException("Unable to find reverse DbRelationship for %s.%s." , relationship.getSourceEntity().getName(), relationship.getName()); } finalPath.addFirst(revNextDBR.getName()); }
private void prependReversedPath(LinkedList finalPath, DbRelationship relationship) { DbRelationship revNextDBR = relationship.getReverseRelationship(); if (revNextDBR == null) { throw new CayenneRuntimeException( "Unable to find reverse DbRelationship for " + relationship.getSourceEntity().getName() + Entity.PATH_SEPARATOR + relationship.getName() + "."); } finalPath.addFirst(revNextDBR.getName()); }
private boolean shouldAddToObjEntity(ObjEntity entity, DbRelationship dbRelationship) { if(dbRelationship.getName() == null) { return false; } for(Relationship relationship : entity.getRelationships()) { ObjRelationship objRelationship = (ObjRelationship)relationship; if(objRelationshipHasDbRelationship(objRelationship, dbRelationship)) { return false; } } return true; }
protected List getRelationshipsToAdd(ObjEntity objEntity) { List missing = new ArrayList(); Iterator it = objEntity.getDbEntity().getRelationships().iterator(); while (it.hasNext()) { DbRelationship dbrel = (DbRelationship) it.next(); // check if adding it makes sense at all if (dbrel.getName() == null) { continue; } if (objEntity.getRelationshipForDbRelationship(dbrel) == null) { missing.add(dbrel); } } return missing; }
/** * Method make direct relationships between 2 entities and remove relationships to * many to many entity * * @param nameGenerator */ public void optimizeRelationships(ObjectNameGenerator nameGenerator) { entity1.removeRelationship(reverseRelationship1.getName()); entity2.removeRelationship(reverseRelationship2.getName()); addFlattenedRelationship(nameGenerator, entity1, entity2, reverseRelationship1, dbRel2); addFlattenedRelationship(nameGenerator, entity2, entity1, reverseRelationship2, dbRel1); }
JoinedDbEntityQualifierTransformer(JoinTreeNode node) { pathToRoot = new StringBuilder(); while (node != null && node.getRelationship() != null) { String relName = node.getRelationship().getName(); /* * We must be in the same join as 'node', otherwise incorrect * join statement like JOIN t1 ... ON (t0.id=t1.id AND * t2.qualifier=0) could be generated */ if (node.getJoinType() == JoinType.LEFT_OUTER) { relName += Entity.OUTER_JOIN_INDICATOR; } relName += ObjEntity.PATH_SEPARATOR; pathToRoot.insert(0, relName); node = node.getParent(); } }
@Override public boolean dbRelationshipLoaded(DbEntity entity, DbRelationship relationship) { checkCanceled(); context.setStatusNote("Load relationship: '" + entity.getName() + "'; '" + relationship.getName() + "'..."); return true; }
private void checkToMany(DbRelationship relationship, ValidationResult validationResult) { if (relationship != null && relationship.getReverseRelationship() != null) { if (relationship.isToMany() && relationship.getReverseRelationship().isToMany()) { addFailure( validationResult, relationship, "Relationship '%s' and reverse '%s' are both toMany", relationship.getName(), relationship.getReverseRelationship().getName()); } } checkTypesOfAttributesInRelationship(relationship, validationResult); }
public static String getTokenValue(DbRelationship rel) { String attributes = ""; if (rel.getJoins().size() == 1) { attributes = rel.getJoins().get(0).getTargetName(); } else { for (DbJoin dbJoin : rel.getJoins()) { attributes += dbJoin.getTargetName() + COMMA_SEPARATOR; } if(attributes.isEmpty()) { attributes = "{}"; } else { attributes = "{" + attributes.substring(0, attributes.length() - COMMA_SEPARATOR_LENGTH) + "}"; } } return rel.getName() + " " + rel.getSourceEntity().getName() + "->" + rel.getTargetEntityName() + "." + attributes; }
@Override public int hashCode() { if (this.hashCode == 0) { HashCodeBuilder builder = new HashCodeBuilder(3, 5); builder.append(sourceId); builder.append(incomingArc.getName()); this.hashCode = builder.toHashCode(); } return hashCode; }
public Object getValueAt(int row, int col) { DbRelationship rel = getRelationship(row); if (rel == null) { return null; } switch (col) { case NAME: return rel.getName(); case TARGET: return rel.getTargetEntity(); case TO_DEPENDENT_KEY: return rel.isToDependentPK() ? Boolean.TRUE : Boolean.FALSE; case CARDINALITY: return rel.isToMany() ? Boolean.TRUE : Boolean.FALSE; default: return null; } }
public void removeDbRelationships(DbEntity entity, DbRelationship[] rels) { ProjectController mediator = getProjectController(); for (DbRelationship rel : rels) { entity.removeRelationship(rel.getName()); RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE); mediator.fireDbRelationshipEvent(e); } ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap()); } }
protected static void remove(ModelMergeDelegate mergerContext, DbRelationship rel, boolean reverse) { if (rel == null) { return; } if (reverse) { remove(mergerContext, rel.getReverseRelationship(), false); } DbEntity dbEntity = rel.getSourceEntity(); for (ObjEntity objEntity : dbEntity.mappedObjEntities()) { remove(mergerContext, objEntity.getRelationshipForDbRelationship(rel), true); } rel.getSourceEntity().removeRelationship(rel.getName()); mergerContext.dbRelationshipRemoved(rel); }
@Override public void execute(MergerContext context) { // Set name to relationship if it was created without it, e.g. in createReverse() action if(relationship.getName() == null) { relationship.setName(context.getNameGenerator().relationshipName(relationship)); } getEntity().addRelationship(relationship); for (ObjEntity e : getMappedObjEntities()) { context.getEntityMergeSupport().synchronizeOnDbRelationshipAdded(e, relationship); } context.getDelegate().dbRelationshipAdded(relationship); }
private void checkTypesOfAttributesInRelationship(DbRelationship relationship, ValidationResult validationResult) { for (DbJoin join: relationship.getJoins()) { if (join.getSource() != null && join.getTarget() != null && join.getSource().getType() != join.getTarget().getType()) { addFailure( validationResult, relationship, "Attributes '%s' and '%s' have different types in a relationship '%s'", join.getSourceName(), join.getTargetName(), relationship.getName()); } } }