private void processStartDbRelationship(Attributes atts) throws SAXException { String name = atts.getValue("", "name"); if (name == null) { throw new SAXException("MapLoader::processStartDbRelationship()," + " Unable to parse name. Attributes:\n" + printAttributes(atts).toString()); } String sourceName = atts.getValue("", "source"); if (sourceName == null) { throw new SAXException( "MapLoader::processStartDbRelationship() - null source entity"); } DbEntity source = dataMap.getDbEntity(sourceName); if (source == null) { return; } String toManyString = atts.getValue("", "toMany"); boolean toMany = toManyString != null && toManyString.equalsIgnoreCase(TRUE); String toDependPkString = atts.getValue("", "toDependentPK"); boolean toDependentPK = toDependPkString != null && toDependPkString.equalsIgnoreCase(TRUE); dbRelationship = new DbRelationship(name); dbRelationship.setSourceEntity(source); dbRelationship.setTargetEntityName(atts.getValue("", "target")); dbRelationship.setToMany(toMany); dbRelationship.setToDependentPK(toDependentPK); source.addRelationship(dbRelationship); }
private void processStartDbRelationship(Attributes atts) throws SAXException { String name = atts.getValue("", "name"); if (name == null) { throw new SAXException("MapLoader::processStartDbRelationship()," + " Unable to parse name. Attributes:\n" + printAttributes(atts)); } String sourceName = atts.getValue("", "source"); if (sourceName == null) { throw new SAXException("MapLoader::processStartDbRelationship() - null source entity"); } DbEntity source = dataMap.getDbEntity(sourceName); if (source == null) { return; } String toManyString = atts.getValue("", "toMany"); boolean toMany = toManyString != null && toManyString.equalsIgnoreCase(TRUE); String toDependPkString = atts.getValue("", "toDependentPK"); boolean toDependentPK = toDependPkString != null && toDependPkString.equalsIgnoreCase(TRUE); dbRelationship = new DbRelationship(name); dbRelationship.setSourceEntity(source); dbRelationship.setTargetEntityName(atts.getValue("", "target")); dbRelationship.setToMany(toMany); dbRelationship.setToDependentPK(toDependentPK); source.addRelationship(dbRelationship); }
DbRelationship rel = (DbRelationship) rit.next(); if (rel.getTargetEntity() == this) { rel.setTargetEntityName(newName);
/** * Creates a new relationship with the same set of joins, but going in the opposite * direction. * * @since 1.0.5 */ public DbRelationship createReverseRelationship() { DbRelationship reverse = new DbRelationship(); reverse.setSourceEntity(getTargetEntity()); reverse.setTargetEntityName(getSourceEntity().getName()); // TODO: must set toDepPK correctly // must set toMany correctly reverse.setToMany(!toMany); Iterator it = joins.iterator(); while (it.hasNext()) { DbJoin join = (DbJoin) it.next(); DbJoin reverseJoin = join.createReverseJoin(); reverseJoin.setRelationship(reverse); reverse.addJoin(reverseJoin); } return reverse; }
dbRel.setTargetEntityName(dbTarget); dbRel.setToMany(toMany); dbRel.setName(relName);
/** * Creates a new relationship with the same set of joins, but going in the * opposite direction. * * @since 1.0.5 */ public DbRelationship createReverseRelationship() { DbEntity targetEntity = (DbEntity) getTargetEntity(); DbRelationship reverse = new DbRelationship(); reverse.setSourceEntity(targetEntity); reverse.setTargetEntityName(getSourceEntity().getName()); // TODO: andrus 12/24/2007 - one more case to handle - set reverse // toDepPK = true // if this relationship toDepPK is false, but the entities are joined on // a PK... // on the other hand, these can still be two independent entities... if (isToDependentPK() && !toMany && joins.size() == targetEntity.getPrimaryKeys().size()) { reverse.setToMany(false); } else { reverse.setToMany(!toMany); } for (DbJoin join : joins) { DbJoin reverseJoin = join.createReverseJoin(); reverseJoin.setRelationship(reverse); reverse.addJoin(reverseJoin); } return reverse; }
/** * @param imported DbRelationship that is in db but not in model * @return generated tokens */ @Override Collection<MergerToken> createTokensForMissingOriginal(DbRelationship imported) { DbEntity originalDbEntity = getOriginalSourceDbEntity(imported); DbEntity targetEntity = getOriginalTargetDbEntity(imported); if (targetEntity != null) { imported.setTargetEntityName(targetEntity); } imported.setSourceEntity(originalDbEntity); // manipulate the joins to match the DbAttributes in the model for (DbJoin join : imported.getJoins()) { DbAttribute sourceAttr = findDbAttribute(originalDbEntity, join.getSourceName()); if (sourceAttr != null) { join.setSourceName(sourceAttr.getName()); } DbAttribute targetAttr = findDbAttribute(targetEntity, join.getTargetName()); if (targetAttr != null) { join.setTargetName(targetAttr.getName()); } } // Add all relationships. Tokens will decide whether or not to execute MergerToken token = getTokenFactory().createDropRelationshipToDb(originalDbEntity, imported); return Collections.singleton(token); }
forwardRelationship.setTargetEntityName(fkEntity);
for (DbRelationship relationship : dbe.getRelationships()) { if (relationship.getTargetEntity() == this) { relationship.setTargetEntityName(newName);
protected void createNames() { for (InferredRelationship myir : inferredRelationships) { DbRelationship localRelationship = new DbRelationship(); localRelationship.setToMany(myir.isToMany()); if (myir.getJoinSource().isPrimaryKey()) { localRelationship.addJoin( new DbJoin(localRelationship, myir.getJoinSource().getName(), myir.getJoinTarget().getName()) ); localRelationship.setSourceEntity(myir.getSource()); localRelationship.setTargetEntityName(myir.getTarget().getName()); } else { localRelationship.addJoin( new DbJoin(localRelationship, myir.getJoinTarget().getName(), myir.getJoinSource().getName()) ); localRelationship.setSourceEntity(myir.getTarget()); localRelationship.setTargetEntityName(myir.getSource().getName()); } myir.setName(strategy.relationshipName(localRelationship)); } }
reverseRelationship.setTargetEntityName(relationship.getSourceEntity()); reverseRelationship.setToMany(!relationship.isToMany()); relationship.getTargetEntity().addRelationship(reverseRelationship);
dbRelationship.setTargetEntityName(targetModel.getTarget()); dbRelationship.setToMany(targetModel.isToMany());
public void generateAction() { ProjectController mediator = application .getFrameController() .getProjectController(); InferRelationshipsUndoableEdit undoableEdit = new InferRelationshipsUndoableEdit(); for (InferredRelationship temp : selectedEntities) { DbRelationship rel = new DbRelationship(uniqueRelName(temp.getSource(), temp .getName())); RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, temp .getSource(), MapEvent.ADD); mediator.fireDbRelationshipEvent(e); rel.setSourceEntity(temp.getSource()); rel.setTargetEntityName(temp.getTarget()); DbJoin join = new DbJoin(rel, temp.getJoinSource().getName(), temp .getJoinTarget() .getName()); rel.addJoin(join); rel.setToMany(temp.isToMany()); temp.getSource().addRelationship(rel); undoableEdit.addEdit(new CreateRelationshipUndoableEdit(temp.getSource(), new DbRelationship[] { rel })); } JOptionPane.showMessageDialog(this.getView(), getSelectedEntitiesSize() + " relationships generated"); view.dispose(); }
for (DbRelationship rel : dbEntity.getRelationships()) { if (renamedDbEntities.containsKey(rel.getTargetEntityName())) { rel.setTargetEntityName(renamedDbEntities.get(rel .getTargetEntityName()));