You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2010/03/28 17:12:45 UTC
svn commit: r928428 -
/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/
Author: aadamchik
Date: Sun Mar 28 15:12:44 2010
New Revision: 928428
URL: http://svn.apache.org/viewvc?rev=928428&view=rev
Log:
Some refactoring of imprecise naming of the Infer Relationships code
(no actual logic changes)
Added:
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferredRelationship.java
- copied, changed from r928407, cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationships.java
Removed:
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationships.java
Modified:
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java?rev=928428&r1=928427&r2=928428&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java Sun Mar 28 15:12:44 2010
@@ -162,7 +162,7 @@ public class InferRelationshipsControlle
}
setNamingStrategy(strategy);
- createName();
+ createNames();
entitySelector.initBindings();
view.setChoice(SELECT);
@@ -184,7 +184,7 @@ public class InferRelationshipsControlle
InferRelationshipsUndoableEdit undoableEdit = new InferRelationshipsUndoableEdit();
- for (InferRelationships temp : selectedEntities) {
+ for (InferredRelationship temp : selectedEntities) {
DbRelationship rel = new DbRelationship(uniqueRelName(temp.getSource(), temp
.getName()));
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java?rev=928428&r1=928427&r2=928428&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java Sun Mar 28 15:12:44 2010
@@ -30,7 +30,6 @@ import org.apache.cayenne.map.DbAttribut
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.DbJoin;
import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.Relationship;
import org.apache.cayenne.map.naming.ExportedKey;
import org.apache.cayenne.map.naming.NamingStrategy;
import org.apache.cayenne.modeler.util.CayenneController;
@@ -42,52 +41,53 @@ public class InferRelationshipsControlle
protected DataMap dataMap;
- protected List<InferRelationships> ir;
+ protected List<InferredRelationship> inferredRelationships;
protected List<DbEntity> entities;
- protected Set<InferRelationships> selectedEntities;
+ protected Set<InferredRelationship> selectedEntities;
protected int index = 0;
protected NamingStrategy strategy;
- protected transient InferRelationships currentEntity;
+ protected transient InferredRelationship currentEntity;
protected transient Integer entityNumber;
public InferRelationshipsControllerBase(CayenneController parent, DataMap dataMap) {
super(parent);
this.dataMap = dataMap;
- this.entities = new ArrayList(dataMap.getDbEntities());
- this.selectedEntities = new HashSet();
-
+ this.entities = new ArrayList<DbEntity>(dataMap.getDbEntities());
+ this.selectedEntities = new HashSet<InferredRelationship>();
}
public void setRelationships() {
- ir = new ArrayList<InferRelationships>();
+ inferredRelationships = new ArrayList<InferredRelationship>();
for (DbEntity entity : entities) {
createRelationships(entity);
}
- createJoin();
- createName();
+ createJoins();
+ createNames();
}
- public void createRelationships(DbEntity entity) {
+ protected void createRelationships(DbEntity entity) {
Collection<DbAttribute> attr = entity.getAttributes();
for (DbAttribute attribute : attr) {
for (DbEntity myEntity : entities) {
- if ((attribute.getName().equalsIgnoreCase(myEntity.getName() + "_ID"))
- && (!attribute.isPrimaryKey())
- && (myEntity.getAttributes().size() != 0)
- && (myEntity != entity)) {
+ if (attribute.getName().equalsIgnoreCase(myEntity.getName() + "_ID")
+ && !attribute.isPrimaryKey()
+ && !myEntity.getAttributes().isEmpty()
+ && myEntity != entity) {
+
if (!attribute.isForeignKey()) {
- InferRelationships myir = new InferRelationships();
+ InferredRelationship myir = new InferredRelationship();
myir.setSource(entity);
myir.setTarget(myEntity);
- ir.add(myir);
+ inferredRelationships.add(myir);
}
+
createReversRelationship(myEntity, entity);
}
}
@@ -96,9 +96,9 @@ public class InferRelationshipsControlle
}
public void createReversRelationship(DbEntity eSourse, DbEntity eTarget) {
- InferRelationships myir = new InferRelationships();
- for (Relationship relationship : eSourse.getRelationships()) {
- for (DbJoin join : ((DbRelationship) relationship).getJoins()) {
+ InferredRelationship myir = new InferredRelationship();
+ for (DbRelationship relationship : eSourse.getRelationships()) {
+ for (DbJoin join : relationship.getJoins()) {
if (((DbEntity) join.getSource().getEntity()).equals(eSourse)
&& ((DbEntity) join.getTarget().getEntity()).equals(eTarget)) {
return;
@@ -107,16 +107,16 @@ public class InferRelationshipsControlle
}
myir.setSource(eSourse);
myir.setTarget(eTarget);
- ir.add(myir);
+ inferredRelationships.add(myir);
}
- public String getJoin(InferRelationships irItem) {
+ public String getJoin(InferredRelationship irItem) {
return irItem.getJoinSource().getName()
+ " : "
+ irItem.getJoinTarget().getName();
}
- public String getToMany(InferRelationships irItem) {
+ public String getToMany(InferredRelationship irItem) {
if (irItem.isToMany()) {
return "to many";
}
@@ -125,7 +125,7 @@ public class InferRelationshipsControlle
}
}
- public DbAttribute getJoinAttribute(DbEntity sEntity, DbEntity tEntity) {
+ protected DbAttribute getJoinAttribute(DbEntity sEntity, DbEntity tEntity) {
if (sEntity.getAttributes().size() == 1) {
return sEntity.getAttributes().iterator().next();
}
@@ -135,12 +135,14 @@ public class InferRelationshipsControlle
return attr;
}
}
+
for (DbAttribute attr : sEntity.getAttributes()) {
if ((attr.getName().equalsIgnoreCase(sEntity.getName() + "_ID"))
&& (!attr.isPrimaryKey())) {
- return (DbAttribute) sEntity.getAttribute(attr.getName());
+ return attr;
}
}
+
for (DbAttribute attr : sEntity.getAttributes()) {
if (attr.isPrimaryKey()) {
return attr;
@@ -150,22 +152,24 @@ public class InferRelationshipsControlle
return null;
}
- public void createJoin() {
- for (InferRelationships myir : ir) {
- DbAttribute temp = getJoinAttribute(myir.getSource(), myir.getTarget());
- myir.setJoinSource(temp);
- if (temp.isPrimaryKey()) {
- myir.setToMany(true);
+ protected void createJoins() {
+ for (InferredRelationship inferred : inferredRelationships) {
+ DbAttribute join = getJoinAttribute(inferred.getSource(), inferred
+ .getTarget());
+ inferred.setJoinSource(join);
+ if (join.isPrimaryKey()) {
+ inferred.setToMany(true);
}
- myir.setJoinTarget(getJoinAttribute(myir.getTarget(), myir.getSource()));
- }
+ inferred.setJoinTarget(getJoinAttribute(inferred.getTarget(), inferred
+ .getSource()));
+ }
}
- public void createName() {
+ protected void createNames() {
ExportedKey key = null;
- for (InferRelationships myir : ir) {
+ for (InferredRelationship myir : inferredRelationships) {
if (myir.getJoinSource().isPrimaryKey()) {
key = getExportedKey(myir.getSource().getName(), myir
.getJoinSource()
@@ -192,11 +196,11 @@ public class InferRelationshipsControlle
return new ExportedKey(pkTable, pkColumn, null, fkTable, fkColumn, null);
}
- public List<InferRelationships> getSelectedEntities() {
- List<InferRelationships> selected = new ArrayList<InferRelationships>(
+ public List<InferredRelationship> getSelectedEntities() {
+ List<InferredRelationship> selected = new ArrayList<InferredRelationship>(
selectedEntities.size());
- for (InferRelationships entity : ir) {
+ for (InferredRelationship entity : inferredRelationships) {
if (selectedEntities.contains(entity)) {
selected.add(entity);
}
@@ -208,7 +212,7 @@ public class InferRelationshipsControlle
public boolean updateSelection(Predicate predicate) {
boolean modified = false;
- for (InferRelationships entity : ir) {
+ for (InferredRelationship entity : inferredRelationships) {
boolean select = predicate.evaluate(entity);
if (select) {
@@ -256,14 +260,14 @@ public class InferRelationshipsControlle
}
public List getEntities() {
- return ir;
+ return inferredRelationships;
}
- public InferRelationships getCurrentEntity() {
+ public InferredRelationship getCurrentEntity() {
return currentEntity;
}
- public void setCurrentEntity(InferRelationships currentEntity) {
+ public void setCurrentEntity(InferredRelationship currentEntity) {
this.currentEntity = currentEntity;
}
Copied: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferredRelationship.java (from r928407, cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationships.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferredRelationship.java?p2=cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferredRelationship.java&p1=cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationships.java&r1=928407&r2=928428&rev=928428&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationships.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferredRelationship.java Sun Mar 28 15:12:44 2010
@@ -21,21 +21,19 @@ package org.apache.cayenne.modeler.dialo
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
+public class InferredRelationship {
-public class InferRelationships {
private DbEntity source;
private DbEntity target;
private DbAttribute joinSource;
private DbAttribute joinTarget;
private String name;
private boolean toMany;
-
-
+
public boolean isToMany() {
return toMany;
}
-
public void setToMany(boolean toMany) {
this.toMany = toMany;
}
@@ -43,41 +41,40 @@ public class InferRelationships {
public DbEntity getSource() {
return source;
}
-
+
public void setSource(DbEntity source) {
this.source = source;
}
-
+
public DbEntity getTarget() {
return target;
}
-
+
public void setTarget(DbEntity target) {
this.target = target;
}
-
+
public DbAttribute getJoinSource() {
return joinSource;
}
-
+
public void setJoinSource(DbAttribute joinSource) {
this.joinSource = joinSource;
}
-
+
public DbAttribute getJoinTarget() {
return joinTarget;
}
-
+
public void setJoinTarget(DbAttribute joinTarget) {
this.joinTarget = joinTarget;
}
-
+
public String getName() {
return name;
}
-
+
public void setName(String name) {
this.name = name;
}
-
}