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 2007/06/13 14:00:33 UTC
svn commit: r546832 -
/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
Author: aadamchik
Date: Wed Jun 13 05:00:33 2007
New Revision: 546832
URL: http://svn.apache.org/viewvc?view=rev&rev=546832
Log:
EJBQL joins processing
(refactoring of private methods)
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java?view=diff&rev=546832&r1=546831&r2=546832
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java Wed Jun 13 05:00:33 2007
@@ -51,10 +51,10 @@
if (finishedChildIndex > 0) {
if (finishedChildIndex + 1 < expression.getChildrenCount()) {
- processIntermediatePath();
+ processIntermediatePathComponent();
}
else {
- processLastPath();
+ processLastPathComponent();
}
}
@@ -87,6 +87,14 @@
return true;
}
+ private EJBQLFromTranslator getJoinAppender() {
+ if (joinAppender == null) {
+ joinAppender = new EJBQLFromTranslator(context);
+ }
+
+ return joinAppender;
+ }
+
private void resolveJoin() {
String newPath = idPath + '.' + lastPathComponent;
@@ -117,13 +125,9 @@
join.jjtAddChild(path, 0);
join.jjtAddChild(joinId, 1);
- if (joinAppender == null) {
- joinAppender = new EJBQLFromTranslator(context);
- }
-
context.switchToMarker(EJBQLTranslationContext.FROM_TAIL_MARKER);
- joinAppender.visitInnerJoin(join, -1);
+ getJoinAppender().visitInnerJoin(join, -1);
context.switchToMainBuffer();
this.idPath = newPath;
@@ -131,7 +135,7 @@
}
}
- private void processIntermediatePath() {
+ private void processIntermediatePathComponent() {
ObjRelationship relationship = (ObjRelationship) currentEntity
.getRelationship(lastPathComponent);
if (relationship == null) {
@@ -145,16 +149,44 @@
this.currentEntity = (ObjEntity) relationship.getTargetEntity();
}
- private void processLastPath() {
- // TODO: andrus 3/25/2007 - process terminal relationships
+ private void processLastPathComponent() {
+
ObjAttribute attribute = (ObjAttribute) currentEntity
.getAttribute(lastPathComponent);
+ if (attribute != null) {
+ processTerminatingAttribute(attribute);
+ return;
+ }
+
+ ObjRelationship relationship = (ObjRelationship) currentEntity
+ .getRelationship(lastPathComponent);
+ if (relationship != null) {
+ processTerminatingRelationship(relationship);
+ return;
+ }
+
+ throw new IllegalStateException("Invalid path component: " + lastPathComponent);
+ }
+
+ private void processTerminatingAttribute(ObjAttribute attribute) {
+
DbEntity table = currentEntity.getDbEntity();
String alias = this.lastAlias != null ? lastAlias : context.getAlias(
idPath,
table.getFullyQualifiedName());
context.append(' ').append(alias).append('.').append(
attribute.getDbAttributeName());
+ }
+
+ private void processTerminatingRelationship(ObjRelationship relationship) {
+
+ // check whether we need a join
+ if (relationship.isSourceIndependentFromTargetChange()) {
+ // TODO: andrus, 6/13/2007 - implement
+ }
+ else {
+ // match FK against the target object
+ }
}
}