You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/03/21 13:03:59 UTC
cayenne git commit: cleanup
Repository: cayenne
Updated Branches:
refs/heads/master 32bdcda54 -> 7901698c9
cleanup
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/7901698c
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/7901698c
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/7901698c
Branch: refs/heads/master
Commit: 7901698c9eeb4b92d92ec89eb84cd89bee92d7dc
Parents: 32bdcda
Author: Nikita Timofeev <st...@gmail.com>
Authored: Tue Mar 21 16:03:54 2017 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Tue Mar 21 16:03:54 2017 +0300
----------------------------------------------------------------------
.../translator/ejbql/EJBQLJoinAppender.java | 91 +++++++-------------
1 file changed, 30 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/7901698c/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java
index c98a1ce..59333c8 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ejbql/EJBQLJoinAppender.java
@@ -33,7 +33,6 @@ import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.DbJoin;
import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.Entity;
import org.apache.cayenne.map.ObjAttribute;
import org.apache.cayenne.query.EntityResultSegment;
import org.apache.cayenne.util.CayenneMapEntry;
@@ -108,15 +107,8 @@ public class EJBQLJoinAppender {
// TODO: andrus, 1/6/2008 - move reusable join check here...
- Entity sourceEntity = incomingDB.getSourceEntity();
- String tableName;
-
- if (sourceEntity instanceof DbEntity) {
- tableName = quoter.quotedFullyQualifiedName((DbEntity) sourceEntity);
- }
- else {
- tableName = sourceEntity.getName();
- }
+ DbEntity sourceEntity = incomingDB.getSourceEntity();
+ String tableName = quoter.quotedFullyQualifiedName(sourceEntity);
String sourceAlias = context.getTableAlias(lhsId.getEntityId(), tableName);
@@ -125,9 +117,7 @@ public class EJBQLJoinAppender {
}
try {
-
context.append(" ").append(semantics);
- String targetAlias = "";
if (joinRelationships.size() > 1) {
// if size of relationship list greater than 1,
// it's a flattened relationship
@@ -136,16 +126,14 @@ public class EJBQLJoinAppender {
for (int i = 1; i < joinRelationships.size(); i++) {
DbRelationship dbRelationship = joinRelationships.get(i);
- String subquerySourceTableName = quoter.quotedFullyQualifiedName((DbEntity) dbRelationship
- .getSourceEntity());
+ String subquerySourceTableName = quoter.quotedFullyQualifiedName(dbRelationship.getSourceEntity());
String subquerySourceAlias = context.getTableAlias(
subquerySourceTableName,
subquerySourceTableName);
- String subqueryTargetTableName = quoter.quotedFullyQualifiedName(
- (DbEntity) dbRelationship.getTargetEntity());
-
- String subqueryTargetAlias = "";
+ String subqueryTargetTableName = quoter.quotedFullyQualifiedName(dbRelationship.getTargetEntity());
+
+ String subqueryTargetAlias;
if(i==joinRelationships.size()-1){
// it's the last table alias
subqueryTargetAlias = context.getTableAlias(rhsId.getEntityId(), subqueryTargetTableName);
@@ -156,8 +144,7 @@ public class EJBQLJoinAppender {
}
if (i == 1) {
// first apply the joins defined in query
- context.append(subquerySourceTableName).append(' ').append(
- subquerySourceAlias);
+ context.append(subquerySourceTableName).append(' ').append(subquerySourceAlias);
generateJoiningExpression(
incomingDB,
@@ -167,24 +154,21 @@ public class EJBQLJoinAppender {
}
context.append(" JOIN ");
- context.append(subqueryTargetTableName).append(' ').append(
- subqueryTargetAlias);
+ context.append(subqueryTargetTableName).append(' ').append(subqueryTargetAlias);
generateJoiningExpression(
dbRelationship,
subquerySourceAlias,
subqueryTargetAlias);
}
- }
- else {
+ } else {
// non-flattened relationship
- targetAlias = appendTable(rhsId);
+ String targetAlias = appendTable(rhsId);
// apply the joins defined in query
generateJoiningExpression(incomingDB, sourceAlias, targetAlias);
}
- }
- finally {
+ } finally {
if (marker != null) {
context.popMarker();
}
@@ -240,16 +224,14 @@ public class EJBQLJoinAppender {
// TODO: andrus 1/5/2007 - if the same table is joined more than once, this
// will create an incorrect alias.
alias = context.getTableAlias(id.getEntityId(), tableName);
-
+
// not using "AS" to separate table name and alias name - OpenBase doesn't
- // support
- // "AS", and the rest of the databases do not care
+ // support "AS", and the rest of the databases do not care
context.append(' ').append(tableName).append(' ').append(alias);
-
- generateJoinsForFlattenedAttributes(id, alias);
-
- }
- else {
+
+ generateJoinsForFlattenedAttributes(id);
+
+ } else {
context.append(' ').append(tableName);
alias = tableName;
}
@@ -288,18 +270,15 @@ public class EJBQLJoinAppender {
* Generates Joins statements for those flattened attributes that appear after the
* FROM clause, e.g. in WHERE, ORDER BY, etc clauses. Flattened attributes of the
* entity from the SELECT clause are processed earlier and therefore are omitted.
- *
+ *
* @param id table to JOIN id
- * @param alias table alias
*/
- private void generateJoinsForFlattenedAttributes(EJBQLTableId id, String alias) {
- String entityName = context
- .getEntityDescriptor(id.getEntityId())
+ private void generateJoinsForFlattenedAttributes(EJBQLTableId id) {
+ String entityName = context.getEntityDescriptor(id.getEntityId())
.getEntity()
.getName();
- boolean isProcessingOmitted = false;
// if the dbPath is not null, all attributes of the entity are processed earlier
- isProcessingOmitted = id.getDbPath() != null;
+ boolean isProcessingOmitted = id.getDbPath() != null;
String sourceExpression = context.getCompiledExpression().getSource();
List<Object> resultSetMapping = context.getMetadata().getResultSetMapping();
@@ -313,53 +292,43 @@ public class EJBQLJoinAppender {
isProcessingOmitted = true;
break;
}
-
}
}
if (!isProcessingOmitted) {
-
+
QuotingStrategy quoter = context.getQuotingStrategy();
-
- Collection<ObjAttribute> attributes = context.getEntityDescriptor(
- id.getEntityId()).getEntity().getAttributes();
+ Collection<ObjAttribute> attributes = context.getEntityDescriptor(id.getEntityId())
+ .getEntity().getAttributes();
for (ObjAttribute objAttribute : attributes) {
if (objAttribute.isFlattened()
- && sourceExpression.contains(id.getEntityId()
- + "."
- + objAttribute.getName())) {
+ && sourceExpression.contains(id.getEntityId() + "." + objAttribute.getName())) {
// joins for attribute are generated if it is flattened and appears in original statement
- Iterator<CayenneMapEntry> dbPathIterator = objAttribute
- .getDbPathIterator();
+ Iterator<CayenneMapEntry> dbPathIterator = objAttribute.getDbPathIterator();
while (dbPathIterator.hasNext()) {
CayenneMapEntry next = dbPathIterator.next();
if (next instanceof DbRelationship) {
DbRelationship rel = (DbRelationship) next;
context.append(" LEFT OUTER JOIN ");
- String targetEntityName = quoter.quotedFullyQualifiedName((DbEntity) rel.getTargetEntity());
+ String targetEntityName = quoter.quotedFullyQualifiedName(rel.getTargetEntity());
String subqueryTargetAlias = context.getTableAlias(id.getEntityId(), targetEntityName);
context.append(targetEntityName).append(' ').append(subqueryTargetAlias);
generateJoiningExpression(
rel,
context.getTableAlias(id.getEntityId(),
- quoter.quotedFullyQualifiedName((DbEntity) rel.getSourceEntity())),
+ quoter.quotedFullyQualifiedName(rel.getSourceEntity())),
subqueryTargetAlias);
}
}
}
-
}
}
}
- private EJBQLExpression ejbqlQualifierForEntityAndSubclasses(
- Expression qualifier,
- String entityId) {
-
- // parser only works on full queries, so prepend a dummy query and then strip it
- // out...
+ private EJBQLExpression ejbqlQualifierForEntityAndSubclasses(Expression qualifier, String entityId) {
+ // parser only works on full queries, so prepend a dummy query and then strip it out...
String ejbqlChunk = qualifier.toEJBQL(entityId);
EJBQLExpression expression = EJBQLParserFactory.getParser().parse(
"DELETE FROM DUMMY WHERE " + ejbqlChunk);