protected Object create(String name, Object namingContext) { return new DbRelationship(name); }
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); }
/** * 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; }
if (dbRel == null) { dbRel = new DbRelationship(); dbRel.setSourceEntity(dbSrc); dbRel.setTargetEntityName(dbTarget);
if (dbRel == null) { dbRel = new DbRelationship(); dbRel.setSourceEntity(dbSrc); dbRel.setTargetEntity(dbTarget);
while (rit.hasNext()) { DbRelationship protoRel = (DbRelationship) rit.next(); DbRelationship rel = new DbRelationship(); rel.setName(protoRel.getName()); rel.setSourceEntity(this);
forwardRelationship = new DbRelationship(DbLoader .uniqueRelName(pkEntity, fkEntityName, true)); pkEntity.addRelationship(forwardRelationship); reverseRelationship = new DbRelationship(uniqueRelName( fkEntity, pkEntName,
/** * 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; }
DbRelationship forwardRelationship = new DbRelationship(); forwardRelationship.setSourceEntity(pkEntity); forwardRelationship.setTargetEntityName(fkEntity);
reverseRelationship = new DbRelationship(); reverseRelationship.setName(NameBuilder .builder(reverseRelationship, relationship.getTargetEntity())
DbRelationship dbRelationship = new DbRelationship(); dbRelationship.setSourceEntity(targetModel.getSource()); dbRelationship.setTargetEntityName(targetModel.getTarget());
/** * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent) */ @Override public void performAction(ActionEvent e) { ObjEntity objEnt = getProjectController().getCurrentObjEntity(); if (objEnt != null) { ObjRelationship rel = new ObjRelationship(); rel.setName(NameBuilder.builder(rel, objEnt).name()); createObjRelationship(objEnt, rel); application.getUndoManager().addEdit( new CreateRelationshipUndoableEdit(objEnt, new ObjRelationship[]{rel})); } else { DbEntity dbEnt = getProjectController().getCurrentDbEntity(); if (dbEnt != null) { DbRelationship rel = new DbRelationship(); rel.setName(NameBuilder.builder(rel, dbEnt).name()); createDbRelationship(dbEnt, rel); application.getUndoManager().addEdit( new CreateRelationshipUndoableEdit(dbEnt, new DbRelationship[]{rel})); } } }
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(); }
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)); } }