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 2013/02/24 14:05:15 UTC
svn commit: r1449474 [1/2] - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src:
main/java/org/apache/cayenne/access/jdbc/
test/java/org/apache/cayenne/access/jdbc/
Author: aadamchik
Date: Sun Feb 24 13:05:14 2013
New Revision: 1449474
URL: http://svn.apache.org/r1449474
Log:
CAY-1522 EJBQL query don't support quotes
integrating Ilya's fix with the current state of the quoter
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDbPathTranslator.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLIdentifierColumnsTranslator.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JdbcEJBQLTranslatorFactory.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java Sun Feb 24 13:05:14 2013
@@ -57,11 +57,8 @@ public class EJBQLAction extends BaseSQL
.getExpression(getEntityResolver());
final EJBQLTranslatorFactory translatorFactory = ((JdbcAdapter) getAdapter())
.getEjbqlTranslatorFactory();
- final EJBQLTranslationContext context = new EJBQLTranslationContext(
- entityResolver,
- query,
- compiledExpression,
- translatorFactory);
+ final EJBQLTranslationContext context = new EJBQLTranslationContext(entityResolver, query, compiledExpression,
+ translatorFactory, adapter.getQuotingStrategy());
compiledExpression.getExpression().visit(new EJBQLBaseVisitor(false) {
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java Sun Feb 24 13:05:14 2013
@@ -73,14 +73,11 @@ class EJBQLAggregateColumnTranslator ext
return false;
}
- private void visitAggregateColumn(
- EJBQLAggregateColumn column,
- EJBQLExpressionVisitor pathVisitor) {
+ private void visitAggregateColumn(EJBQLAggregateColumn column, EJBQLExpressionVisitor pathVisitor) {
if (context.isAppendingResultColumns()) {
context.append(" #result('");
- }
- else {
+ } else {
context.append(' ');
}
@@ -91,12 +88,8 @@ class EJBQLAggregateColumnTranslator ext
context.append(')');
if (context.isAppendingResultColumns()) {
- context
- .append("' '")
- .append(column.getJavaType(attributeType))
- .append("' '")
- .append(context.nextColumnAlias())
- .append("')");
+ context.append("' '").append(column.getJavaType(attributeType)).append("' '")
+ .append(context.nextColumnAlias()).append("')");
}
}
@@ -121,19 +114,17 @@ class EJBQLAggregateColumnTranslator ext
protected void processTerminatingAttribute(ObjAttribute attribute) {
EJBQLAggregateColumnTranslator.this.attributeType = attribute.getType();
-
+
DbEntity table = currentEntity.getDbEntity();
- String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(
- idPath,
- context.getQuotingSupport().generateTableName(table));
- context.append(alias).append('.').append(
- context.getQuotingSupport().generateColumnName(attribute.getDbAttribute()));
+ String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context
+ .getQuotingStrategy().quotedFullyQualifiedName(table));
+ context.append(alias).append('.')
+ .append(context.getQuotingStrategy().quotedName(attribute.getDbAttribute()));
}
-
+
@Override
protected void processTerminatingRelationship(ObjRelationship relationship) {
- Collection<DbAttribute> dbAttr = ((ObjEntity) relationship
- .getTargetEntity()).getDbEntity().getAttributes();
+ Collection<DbAttribute> dbAttr = ((ObjEntity) relationship.getTargetEntity()).getDbEntity().getAttributes();
if (dbAttr.size() > 0) {
this.resolveJoin(true);
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java Sun Feb 24 13:05:14 2013
@@ -27,7 +27,7 @@ import java.util.Map;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.Persistent;
-import org.apache.cayenne.dba.QuotingSupport;
+import org.apache.cayenne.dba.QuotingStrategy;
import org.apache.cayenne.dba.TypesMapping;
import org.apache.cayenne.ejbql.EJBQLBaseVisitor;
import org.apache.cayenne.ejbql.EJBQLException;
@@ -76,8 +76,7 @@ public class EJBQLConditionTranslator ex
@Override
public boolean visitAggregate(EJBQLExpression expression) {
- expression.visit(context.getTranslatorFactory().getAggregateColumnTranslator(
- context));
+ expression.visit(context.getTranslatorFactory().getAggregateColumnTranslator(context));
return false;
}
@@ -90,15 +89,15 @@ public class EJBQLConditionTranslator ex
@Override
public boolean visitBetween(EJBQLExpression expression, int finishedChildIndex) {
switch (finishedChildIndex) {
- case 0:
- if (expression.isNegated()) {
- context.append(" NOT");
- }
- context.append(" BETWEEN");
- break;
- case 1:
- context.append(" AND");
- break;
+ case 0:
+ if (expression.isNegated()) {
+ context.append(" NOT");
+ }
+ context.append(" BETWEEN");
+ break;
+ case 1:
+ context.append(" AND");
+ break;
}
return true;
@@ -113,7 +112,8 @@ public class EJBQLConditionTranslator ex
@Override
public boolean visitIsEmpty(EJBQLExpression expression) {
- // handle as "path is [not] null" (an alt. way would've been a correlated subquery
+ // handle as "path is [not] null" (an alt. way would've been a
+ // correlated subquery
// on the target entity)...
if (expression.isNegated()) {
@@ -136,34 +136,31 @@ public class EJBQLConditionTranslator ex
// run as a correlated subquery.
// see "visitMemberOf" for correlated subquery logic
- // also note that the code below is mostly copy/paste from MEMBER OF method ...
- // maybe there's enough commonality in building correlated subqueries to make it
+ // also note that the code below is mostly copy/paste from MEMBER OF
+ // method ...
+ // maybe there's enough commonality in building correlated subqueries to
+ // make it
// reusable???
if (expression.getChildrenCount() != 1) {
- throw new EJBQLException("SIZE must have exactly one child, got: "
- + expression.getChildrenCount());
+ throw new EJBQLException("SIZE must have exactly one child, got: " + expression.getChildrenCount());
}
if (!(expression.getChild(0) instanceof EJBQLPath)) {
- throw new EJBQLException(
- "First child of SIZE must be a collection path, got: "
- + expression.getChild(1));
+ throw new EJBQLException("First child of SIZE must be a collection path, got: " + expression.getChild(1));
}
+ QuotingStrategy quoter = context.getQuotingStrategy();
+
EJBQLPath path = (EJBQLPath) expression.getChild(0);
String id = path.getAbsolutePath();
String correlatedEntityId = path.getId();
- ClassDescriptor correlatedEntityDescriptor = context
- .getEntityDescriptor(correlatedEntityId);
- String correlatedTableName = context.getQuotingSupport().generateTableName(correlatedEntityDescriptor
- .getEntity()
+ ClassDescriptor correlatedEntityDescriptor = context.getEntityDescriptor(correlatedEntityId);
+ String correlatedTableName = quoter.quotedFullyQualifiedName(correlatedEntityDescriptor.getEntity()
.getDbEntity());
- String correlatedTableAlias = context.getTableAlias(
- correlatedEntityId,
- correlatedTableName);
+ String correlatedTableAlias = context.getTableAlias(correlatedEntityId, correlatedTableName);
String subqueryId = context.createIdAlias(id);
ClassDescriptor targetDescriptor = context.getEntityDescriptor(subqueryId);
@@ -174,38 +171,31 @@ public class EJBQLConditionTranslator ex
context.append(" EXISTS (SELECT 1 FROM ");
- String subqueryTableName = context.getQuotingSupport().generateTableName(targetDescriptor
- .getEntity()
- .getDbEntity());
+ String subqueryTableName = quoter.quotedFullyQualifiedName(targetDescriptor.getEntity().getDbEntity());
String subqueryRootAlias = context.getTableAlias(subqueryId, subqueryTableName);
- ObjRelationship relationship = (ObjRelationship) correlatedEntityDescriptor
- .getEntity()
- .getRelationship(path.getRelativePath());
+ ObjRelationship relationship = (ObjRelationship) correlatedEntityDescriptor.getEntity().getRelationship(
+ path.getRelativePath());
if (relationship.getDbRelationshipPath().contains(".")) {
- // if the DbRelationshipPath contains '.', the relationship is flattened
- subqueryRootAlias = processFlattenedRelationShip(
- subqueryRootAlias,
- relationship);
- }
- else {
- // not using "AS" to separate table name and alias name - OpenBase doesn't
+ // if the DbRelationshipPath contains '.', the relationship is
+ // flattened
+ subqueryRootAlias = processFlattenedRelationShip(subqueryRootAlias, relationship);
+ } else {
+ // not using "AS" to separate table name and alias name - OpenBase
+ // doesn't
// support "AS", and the rest of the databases do not care
context.append(subqueryTableName).append(' ').append(subqueryRootAlias);
}
context.append(" WHERE");
- DbRelationship correlatedJoinRelationship = context.getIncomingRelationships(
- new EJBQLTableId(id)).get(0);
+ DbRelationship correlatedJoinRelationship = context.getIncomingRelationships(new EJBQLTableId(id)).get(0);
Iterator<DbJoin> it = correlatedJoinRelationship.getJoins().iterator();
while (it.hasNext()) {
DbJoin join = it.next();
- context.append(' ').append(subqueryRootAlias).append('.').append(
- join.getTargetName()).append(" = ");
- context.append(correlatedTableAlias).append('.')
- .append(context.getQuotingSupport().generateColumnName(join.getSource()));
+ context.append(' ').append(subqueryRootAlias).append('.').append(join.getTargetName()).append(" = ");
+ context.append(correlatedTableAlias).append('.').append(quoter.quotedSourceName(join));
if (it.hasNext()) {
context.append(" AND");
@@ -223,23 +213,25 @@ public class EJBQLConditionTranslator ex
// create a correlated subquery, using the following transformation:
// * Subquery Root is always an entity that is a target of relationship
- // * A subquery has a join based on reverse relationship, pointing to the
+ // * A subquery has a join based on reverse relationship, pointing to
+ // the
// original ID.
- // * Join must be transled as a part of the subquery WHERE clause instead of
+ // * Join must be translated as a part of the subquery WHERE clause
+ // instead of
// FROM.
// * A condition is added: subquery_root_id = LHS_memberof
if (expression.getChildrenCount() != 2) {
- throw new EJBQLException("MEMBER OF must have exactly two children, got: "
- + expression.getChildrenCount());
+ throw new EJBQLException("MEMBER OF must have exactly two children, got: " + expression.getChildrenCount());
}
if (!(expression.getChild(1) instanceof EJBQLPath)) {
- throw new EJBQLException(
- "Second child of the MEMBER OF must be a collection path, got: "
- + expression.getChild(1));
+ throw new EJBQLException("Second child of the MEMBER OF must be a collection path, got: "
+ + expression.getChild(1));
}
+ QuotingStrategy quoter = context.getQuotingStrategy();
+
EJBQLPath path = (EJBQLPath) expression.getChild(1);
// make sure the ID for the path does not overlap with other condition
@@ -247,14 +239,10 @@ public class EJBQLConditionTranslator ex
String id = path.getAbsolutePath();
String correlatedEntityId = path.getId();
- ClassDescriptor correlatedEntityDescriptor = context
- .getEntityDescriptor(correlatedEntityId);
- String correlatedTableName = context.getQuotingSupport().generateTableName(correlatedEntityDescriptor
- .getEntity()
+ ClassDescriptor correlatedEntityDescriptor = context.getEntityDescriptor(correlatedEntityId);
+ String correlatedTableName = quoter.quotedFullyQualifiedName(correlatedEntityDescriptor.getEntity()
.getDbEntity());
- String correlatedTableAlias = context.getTableAlias(
- correlatedEntityId,
- correlatedTableName);
+ String correlatedTableAlias = context.getTableAlias(correlatedEntityId, correlatedTableName);
String subqueryId = context.createIdAlias(id);
ClassDescriptor targetDescriptor = context.getEntityDescriptor(subqueryId);
@@ -265,23 +253,19 @@ public class EJBQLConditionTranslator ex
context.append(" EXISTS (SELECT 1 FROM ");
- String subqueryTableName = context.getQuotingSupport().generateTableName(targetDescriptor
- .getEntity()
- .getDbEntity());
+ String subqueryTableName = quoter.quotedFullyQualifiedName(targetDescriptor.getEntity().getDbEntity());
String subqueryRootAlias = context.getTableAlias(subqueryId, subqueryTableName);
- ObjRelationship relationship = (ObjRelationship) correlatedEntityDescriptor
- .getEntity()
- .getRelationship(path.getRelativePath());
+ ObjRelationship relationship = (ObjRelationship) correlatedEntityDescriptor.getEntity().getRelationship(
+ path.getRelativePath());
if (relationship.getDbRelationshipPath().contains(".")) {
- // if the DbRelationshipPath contains '.', the relationship is flattened
- subqueryRootAlias = processFlattenedRelationShip(
- subqueryRootAlias,
- relationship);
- }
- else {
- // not using "AS" to separate table name and alias name - OpenBase doesn't
+ // if the DbRelationshipPath contains '.', the relationship is
+ // flattened
+ subqueryRootAlias = processFlattenedRelationShip(subqueryRootAlias, relationship);
+ } else {
+ // not using "AS" to separate table name and alias name - OpenBase
+ // doesn't
// support "AS", and the rest of the databases do not care
context.append(subqueryTableName).append(' ').append(subqueryRootAlias);
@@ -289,14 +273,11 @@ public class EJBQLConditionTranslator ex
context.append(" WHERE");
- DbRelationship correlatedJoinRelationship = context.getIncomingRelationships(
- new EJBQLTableId(id)).get(0);
+ DbRelationship correlatedJoinRelationship = context.getIncomingRelationships(new EJBQLTableId(id)).get(0);
- QuotingSupport quotingSupport = context.getQuotingSupport();
for (DbJoin join : correlatedJoinRelationship.getJoins()) {
- context.append(' ').append(subqueryRootAlias).append('.').append(
- join.getTargetName()).append(" = ");
- context.append(correlatedTableAlias).append('.').append(quotingSupport.generateColumnName(join.getSource()));
+ context.append(' ').append(subqueryRootAlias).append('.').append(join.getTargetName()).append(" = ");
+ context.append(correlatedTableAlias).append('.').append(quoter.quotedSourceName(join));
context.append(" AND");
}
@@ -313,37 +294,32 @@ public class EJBQLConditionTranslator ex
return false;
}
- private String processFlattenedRelationShip(
- String subqueryRootAlias,
- ObjRelationship relationship) {
+ private String processFlattenedRelationShip(String subqueryRootAlias, ObjRelationship relationship) {
+
+ QuotingStrategy quoter = context.getQuotingStrategy();
+
List<DbRelationship> dbRelationships = relationship.getDbRelationships();
- // reverse order to get the nearest to the correlated of the direct relation
+ // reverse order to get the nearest to the correlated of the direct
+ // relation
for (int i = dbRelationships.size() - 1; i > 0; i--) {
DbRelationship dbRelationship = dbRelationships.get(i);
- String subqueryTargetTableName = context.getQuotingSupport().generateTableName(
- (DbEntity) dbRelationship.getTargetEntity());
+ String subqueryTargetTableName = quoter.quotedFullyQualifiedName((DbEntity) dbRelationship
+ .getTargetEntity());
String subqueryTargetAlias;
if (i == dbRelationships.size() - 1) {
subqueryTargetAlias = subqueryRootAlias;
- context.append(subqueryTargetTableName).append(' ').append(
- subqueryTargetAlias);
- }
- else {
- subqueryTargetAlias = context.getTableAlias(
- subqueryTargetTableName,
- subqueryTargetTableName);
+ context.append(subqueryTargetTableName).append(' ').append(subqueryTargetAlias);
+ } else {
+ subqueryTargetAlias = context.getTableAlias(subqueryTargetTableName, subqueryTargetTableName);
}
context.append(" JOIN ");
- String subquerySourceTableName = context.getQuotingSupport().generateTableName(
- (DbEntity) dbRelationship.getSourceEntity());
- String subquerySourceAlias = context.getTableAlias(
- subquerySourceTableName,
- subquerySourceTableName);
+ String subquerySourceTableName = quoter.quotedFullyQualifiedName((DbEntity) dbRelationship
+ .getSourceEntity());
+ String subquerySourceAlias = context.getTableAlias(subquerySourceTableName, subquerySourceTableName);
- context.append(subquerySourceTableName).append(' ').append(
- subquerySourceAlias);
+ context.append(subquerySourceTableName).append(' ').append(subquerySourceAlias);
context.append(" ON (");
@@ -351,10 +327,8 @@ public class EJBQLConditionTranslator ex
Iterator<DbJoin> it = joins.iterator();
while (it.hasNext()) {
DbJoin join = it.next();
- context.append(' ').append(subqueryTargetAlias).append('.').append(
- join.getTargetName()).append(" = ");
- context.append(subquerySourceAlias).append('.').append(
- join.getSourceName());
+ context.append(' ').append(subqueryTargetAlias).append('.').append(join.getTargetName()).append(" = ");
+ context.append(subquerySourceAlias).append('.').append(join.getSourceName());
if (it.hasNext()) {
context.append(" AND");
}
@@ -383,30 +357,30 @@ public class EJBQLConditionTranslator ex
visitConditional((AggregateConditionNode) expression, " OR", finishedChildIndex);
return true;
}
-
+
/**
- * Checks expression for containing null input parameter.
- * For that, we'll append IS NULL or IS NOT NULL instead of =null or <>null
- * @return whether replacement was done and there's no need for normal expression processing
+ * Checks expression for containing null input parameter. For that, we'll
+ * append IS NULL or IS NOT NULL instead of =null or <>null
+ *
+ * @return whether replacement was done and there's no need for normal
+ * expression processing
*/
protected boolean checkNullParameter(EJBQLExpression expression, String toAppend) {
if (expression.getChildrenCount() == 2) {
// We rewrite expression "parameter = :x" where x=null
// as "parameter IS NULL"
- // BUT in such as ":x = parameter" (where x=null) we don't do anything
+ // BUT in such as ":x = parameter" (where x=null) we don't do
+ // anything
// as a result it can be unsupported in some DB
if (expression.getChild(1) instanceof EJBQLNamedInputParameter) {
- EJBQLNamedInputParameter par = (EJBQLNamedInputParameter) expression
- .getChild(1);
+ EJBQLNamedInputParameter par = (EJBQLNamedInputParameter) expression.getChild(1);
if (context.namedParameters.containsKey(par.getText())
&& context.namedParameters.get(par.getText()) == null) {
context.append(toAppend);
return true;
}
- }
- else if (expression.getChild(1) instanceof EJBQLPositionalInputParameter) {
- EJBQLPositionalInputParameter par = (EJBQLPositionalInputParameter) expression
- .getChild(1);
+ } else if (expression.getChild(1) instanceof EJBQLPositionalInputParameter) {
+ EJBQLPositionalInputParameter par = (EJBQLPositionalInputParameter) expression.getChild(1);
if (context.positionalParameters.containsKey(par.getPosition())
&& context.positionalParameters.get(par.getPosition()) == null) {
context.append(toAppend);
@@ -420,45 +394,46 @@ public class EJBQLConditionTranslator ex
@Override
public boolean visitEquals(EJBQLExpression expression, int finishedChildIndex) {
switch (finishedChildIndex) {
- case 0:
- if (checkNullParameter(expression, " IS NULL")) {
- return false;
+ case 0:
+ if (checkNullParameter(expression, " IS NULL")) {
+ return false;
+ }
+ context.append(" =");
+ break;
+ case 1:
+ // check multicolumn match condition and undo op insertion and
+ // append it
+ // from scratch if needed
+ if (multiColumnOperands != null) {
+
+ if (multiColumnOperands.size() != 2) {
+ throw new EJBQLException(
+ "Invalid multi-column equals expression. Expected 2 multi-column operands, got "
+ + multiColumnOperands.size());
}
- context.append(" =");
- break;
- case 1:
- // check multicolumn match condition and undo op insertion and append it
- // from scratch if needed
- if (multiColumnOperands != null) {
-
- if (multiColumnOperands.size() != 2) {
- throw new EJBQLException(
- "Invalid multi-column equals expression. Expected 2 multi-column operands, got "
- + multiColumnOperands.size());
- }
- context.trim(2);
+ context.trim(2);
- EJBQLMultiColumnOperand lhs = multiColumnOperands.get(0);
- EJBQLMultiColumnOperand rhs = multiColumnOperands.get(1);
+ EJBQLMultiColumnOperand lhs = multiColumnOperands.get(0);
+ EJBQLMultiColumnOperand rhs = multiColumnOperands.get(1);
- Iterator<?> it = lhs.getKeys().iterator();
- while (it.hasNext()) {
- Object key = it.next();
-
- lhs.appendValue(key);
- context.append(" =");
- rhs.appendValue(key);
-
- if (it.hasNext()) {
- context.append(" AND");
- }
- }
+ Iterator<?> it = lhs.getKeys().iterator();
+ while (it.hasNext()) {
+ Object key = it.next();
+
+ lhs.appendValue(key);
+ context.append(" =");
+ rhs.appendValue(key);
- multiColumnOperands = null;
+ if (it.hasNext()) {
+ context.append(" AND");
+ }
}
- break;
+ multiColumnOperands = null;
+ }
+
+ break;
}
return true;
@@ -480,45 +455,46 @@ public class EJBQLConditionTranslator ex
@Override
public boolean visitNotEquals(EJBQLExpression expression, int finishedChildIndex) {
switch (finishedChildIndex) {
- case 0:
- if (checkNullParameter(expression, " IS NOT NULL")) {
- return false;
+ case 0:
+ if (checkNullParameter(expression, " IS NOT NULL")) {
+ return false;
+ }
+ context.append(" <>");
+ break;
+ case 1:
+ // check multicolumn match condition and undo op insertion and
+ // append it
+ // from scratch if needed
+ if (multiColumnOperands != null) {
+
+ if (multiColumnOperands.size() != 2) {
+ throw new EJBQLException(
+ "Invalid multi-column equals expression. Expected 2 multi-column operands, got "
+ + multiColumnOperands.size());
}
- context.append(" <>");
- break;
- case 1:
- // check multicolumn match condition and undo op insertion and append it
- // from scratch if needed
- if (multiColumnOperands != null) {
-
- if (multiColumnOperands.size() != 2) {
- throw new EJBQLException(
- "Invalid multi-column equals expression. Expected 2 multi-column operands, got "
- + multiColumnOperands.size());
- }
- context.trim(3);
+ context.trim(3);
- EJBQLMultiColumnOperand lhs = multiColumnOperands.get(0);
- EJBQLMultiColumnOperand rhs = multiColumnOperands.get(1);
+ EJBQLMultiColumnOperand lhs = multiColumnOperands.get(0);
+ EJBQLMultiColumnOperand rhs = multiColumnOperands.get(1);
- Iterator<?> it = lhs.getKeys().iterator();
- while (it.hasNext()) {
- Object key = it.next();
-
- lhs.appendValue(key);
- context.append(" <>");
- rhs.appendValue(key);
-
- if (it.hasNext()) {
- context.append(" OR");
- }
- }
+ Iterator<?> it = lhs.getKeys().iterator();
+ while (it.hasNext()) {
+ Object key = it.next();
+
+ lhs.appendValue(key);
+ context.append(" <>");
+ rhs.appendValue(key);
- multiColumnOperands = null;
+ if (it.hasNext()) {
+ context.append(" OR");
+ }
}
- break;
+ multiColumnOperands = null;
+ }
+
+ break;
}
return true;
}
@@ -565,7 +541,7 @@ public class EJBQLConditionTranslator ex
if (checkNullParameter(expression, " IS NULL")) {
return false;
}
-
+
if (expression.isNegated()) {
context.append(" NOT");
}
@@ -583,20 +559,18 @@ public class EJBQLConditionTranslator ex
}
context.append(" IN");
- // a cosmetic hack for preventing extra pair of parenthesis from being
+ // a cosmetic hack for preventing extra pair of parenthesis from
+ // being
// appended in 'visitSubselect'
- if (expression.getChildrenCount() == 2
- && expression.getChild(1) instanceof EJBQLSubselect) {
+ if (expression.getChildrenCount() == 2 && expression.getChild(1) instanceof EJBQLSubselect) {
visitSubselect(expression.getChild(1));
return false;
}
context.append(" (");
- }
- else if (finishedChildIndex == expression.getChildrenCount() - 1) {
+ } else if (finishedChildIndex == expression.getChildrenCount() - 1) {
context.append(")");
- }
- else if (finishedChildIndex > 0) {
+ } else if (finishedChildIndex > 0) {
context.append(',');
}
@@ -623,8 +597,7 @@ public class EJBQLConditionTranslator ex
*/
boolean needBracket(AggregateConditionNode e) {
return (e.jjtGetParent() instanceof AggregateConditionNode)
- && e.getPriority() > ((AggregateConditionNode) e.jjtGetParent())
- .getPriority();
+ && e.getPriority() > ((AggregateConditionNode) e.jjtGetParent()).getPriority();
}
protected void afterChild(EJBQLExpression e, String text, int childIndex) {
@@ -641,22 +614,20 @@ public class EJBQLConditionTranslator ex
ClassDescriptor descriptor = context.getEntityDescriptor(expression.getText());
if (descriptor == null) {
- throw new EJBQLException("Invalid identification variable: "
- + expression.getText());
+ throw new EJBQLException("Invalid identification variable: " + expression.getText());
}
DbEntity table = descriptor.getEntity().getDbEntity();
- String alias = context.getTableAlias(expression.getText(), context.getQuotingSupport().generateTableName(table));
+ String alias = context
+ .getTableAlias(expression.getText(), context.getQuotingStrategy().quotedFullyQualifiedName(table));
Collection<DbAttribute> pks = table.getPrimaryKeys();
if (pks.size() == 1) {
DbAttribute pk = pks.iterator().next();
- context.append(' ').append(alias).append('.').append(context.getQuotingSupport().generateColumnName(pk));
- }
- else {
- throw new EJBQLException(
- "Multi-column PK to-many matches are not yet supported.");
+ context.append(' ').append(alias).append('.').append(context.getQuotingStrategy().quotedName(pk));
+ } else {
+ throw new EJBQLException("Multi-column PK to-many matches are not yet supported.");
}
return false;
}
@@ -690,16 +661,14 @@ public class EJBQLConditionTranslator ex
public boolean visitIntegerLiteral(EJBQLIntegerLiteral expression) {
if (expression.getText() == null) {
context.append("null");
- }
- else {
+ } else {
String text = expression.getText();
if (expression.isNegative() && text != null) {
if (text.startsWith("-")) {
text = text.substring(1);
- }
- else {
+ } else {
text = "-" + text;
}
}
@@ -708,8 +677,7 @@ public class EJBQLConditionTranslator ex
try {
value = new Integer(text);
- }
- catch (NumberFormatException nfex) {
+ } catch (NumberFormatException nfex) {
throw new EJBQLException("Invalid integer: " + expression.getText());
}
@@ -723,16 +691,14 @@ public class EJBQLConditionTranslator ex
public boolean visitDecimalLiteral(EJBQLDecimalLiteral expression) {
if (expression.getText() == null) {
context.append("null");
- }
- else {
+ } else {
String text = expression.getText();
if (expression.isNegative() && text != null) {
if (text.startsWith("-")) {
text = text.substring(1);
- }
- else {
+ } else {
text = "-" + text;
}
}
@@ -741,8 +707,7 @@ public class EJBQLConditionTranslator ex
try {
value = new BigDecimal(text);
- }
- catch (NumberFormatException nfex) {
+ } catch (NumberFormatException nfex) {
throw new EJBQLException("Invalid decimal: " + expression.getText());
}
@@ -780,8 +745,7 @@ public class EJBQLConditionTranslator ex
public boolean visitBooleanLiteral(EJBQLExpression expression) {
if (expression.getText() == null) {
context.append("null");
- }
- else {
+ } else {
Object value = Boolean.valueOf(expression.getText());
String var = context.bindParameter(value);
context.append(" #bind($").append(var).append(" 'BOOLEAN')");
@@ -794,9 +758,9 @@ public class EJBQLConditionTranslator ex
public boolean visitStringLiteral(EJBQLExpression expression) {
if (expression.getText() == null) {
context.append("null");
- }
- else {
- // note that String Literal text is already wrapped in single quotes, with
+ } else {
+ // note that String Literal text is already wrapped in single
+ // quotes, with
// quotes that are part of the string escaped.
context.append(" #bind(").append(expression.getText()).append(" 'VARCHAR')");
}
@@ -818,38 +782,31 @@ public class EJBQLConditionTranslator ex
Map<?, ?> map = null;
if (object instanceof Persistent) {
map = ((Persistent) object).getObjectId().getIdSnapshot();
- }
- else if (object instanceof ObjectId) {
+ } else if (object instanceof ObjectId) {
map = ((ObjectId) object).getIdSnapshot();
- }
- else if (object instanceof Map) {
+ } else if (object instanceof Map) {
map = (Map<?, ?>) object;
}
if (map != null) {
if (map.size() == 1) {
context.rebindParameter(boundName, map.values().iterator().next());
- }
- else {
- addMultiColumnOperand(EJBQLMultiColumnOperand.getObjectOperand(
- context,
- map));
+ } else {
+ addMultiColumnOperand(EJBQLMultiColumnOperand.getObjectOperand(context, map));
return;
}
}
if (object != null) {
context.append(" #bind($").append(boundName).append(")");
- }
- else {
+ } else {
String type = null;
Node parent = ((SimpleNode) expression).jjtGetParent();
context.pushMarker("@processParameter", true);
- EJBQLPathAnaliserTranslator translator = new EJBQLPathAnaliserTranslator(
- context);
+ EJBQLPathAnaliserTranslator translator = new EJBQLPathAnaliserTranslator(context);
parent.visit(translator);
translator.visitPath(parent, parent.getChildrenCount());
@@ -864,12 +821,9 @@ public class EJBQLConditionTranslator ex
PropertyDescriptor property = descriptor.getProperty(pathChunk);
if (property instanceof AttributeProperty) {
- String atrType = ((AttributeProperty) property)
- .getAttribute()
- .getType();
+ String atrType = ((AttributeProperty) property).getAttribute().getType();
- type = TypesMapping.getSqlNameByType(TypesMapping
- .getSqlTypeByJava(atrType));
+ type = TypesMapping.getSqlNameByType(TypesMapping.getSqlTypeByJava(atrType));
}
}
context.popMarker();
@@ -877,12 +831,17 @@ public class EJBQLConditionTranslator ex
if (type == null) {
type = "VARCHAR";
}
- // this is a hack to prevent execptions on DB's like Derby for expressions
- // "X = NULL". The 'VARCHAR' parameter is totally bogus, but seems to work on
- // all tested DB's... Also note what JPA spec, chapter 4.11 says: "Comparison
- // or arithmetic operations with a NULL value always yield an unknown value."
+ // this is a hack to prevent execptions on DB's like Derby for
+ // expressions
+ // "X = NULL". The 'VARCHAR' parameter is totally bogus, but seems
+ // to work on
+ // all tested DB's... Also note what JPA spec, chapter 4.11 says:
+ // "Comparison
+ // or arithmetic operations with a NULL value always yield an
+ // unknown value."
- // TODO: andrus 6/28/2007 Ideally we should track the type of the current
+ // TODO: andrus 6/28/2007 Ideally we should track the type of the
+ // current
// expression to provide a meaningful type.
context.append(" #bind($").append(boundName).append(" '" + type + "')");
@@ -893,16 +852,16 @@ public class EJBQLConditionTranslator ex
public boolean visitAdd(EJBQLExpression expression, int finishedChildIndex) {
switch (finishedChildIndex) {
- case -1:
- context.append(" (");
- break;
- case 0:
- context.append(" +");
- break;
-
- case 1:
- context.append(")");
- break;
+ case -1:
+ context.append(" (");
+ break;
+ case 0:
+ context.append(" +");
+ break;
+
+ case 1:
+ context.append(")");
+ break;
}
return true;
@@ -912,16 +871,16 @@ public class EJBQLConditionTranslator ex
public boolean visitSubtract(EJBQLExpression expression, int finishedChildIndex) {
switch (finishedChildIndex) {
- case -1:
- context.append(" (");
- break;
- case 0:
- context.append(" -");
- break;
-
- case 1:
- context.append(")");
- break;
+ case -1:
+ context.append(" (");
+ break;
+ case 0:
+ context.append(" -");
+ break;
+
+ case 1:
+ context.append(")");
+ break;
}
return true;
@@ -930,16 +889,16 @@ public class EJBQLConditionTranslator ex
@Override
public boolean visitMultiply(EJBQLExpression expression, int finishedChildIndex) {
switch (finishedChildIndex) {
- case -1:
- context.append(" (");
- break;
- case 0:
- context.append(" *");
- break;
-
- case 1:
- context.append(")");
- break;
+ case -1:
+ context.append(" (");
+ break;
+ case 0:
+ context.append(" *");
+ break;
+
+ case 1:
+ context.append(")");
+ break;
}
return true;
@@ -948,16 +907,16 @@ public class EJBQLConditionTranslator ex
@Override
public boolean visitDivide(EJBQLExpression expression, int finishedChildIndex) {
switch (finishedChildIndex) {
- case -1:
- context.append(" (");
- break;
- case 0:
- context.append(" /");
- break;
-
- case 1:
- context.append(")");
- break;
+ case -1:
+ context.append(" (");
+ break;
+ case 0:
+ context.append(" /");
+ break;
+
+ case 1:
+ context.append(")");
+ break;
}
return true;
@@ -985,8 +944,7 @@ public class EJBQLConditionTranslator ex
public boolean visitAbs(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn ABS(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
}
@@ -997,8 +955,7 @@ public class EJBQLConditionTranslator ex
public boolean visitSqrt(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn SQRT(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
}
@@ -1009,11 +966,9 @@ public class EJBQLConditionTranslator ex
public boolean visitMod(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn MOD(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
- }
- else {
+ } else {
context.append(',');
}
@@ -1024,11 +979,9 @@ public class EJBQLConditionTranslator ex
public boolean visitConcat(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn CONCAT(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
- }
- else {
+ } else {
context.append(',');
}
@@ -1039,11 +992,9 @@ public class EJBQLConditionTranslator ex
public boolean visitSubstring(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn SUBSTRING(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
- }
- else {
+ } else {
context.append(',');
}
@@ -1054,8 +1005,7 @@ public class EJBQLConditionTranslator ex
public boolean visitLower(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn LCASE(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
}
@@ -1066,8 +1016,7 @@ public class EJBQLConditionTranslator ex
public boolean visitUpper(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn UCASE(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
}
@@ -1078,8 +1027,7 @@ public class EJBQLConditionTranslator ex
public boolean visitLength(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn LENGTH(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
}
@@ -1090,11 +1038,9 @@ public class EJBQLConditionTranslator ex
public boolean visitLocate(EJBQLExpression expression, int finishedChildIndex) {
if (finishedChildIndex < 0) {
context.append(" {fn LOCATE(");
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
context.append(")}");
- }
- else {
+ } else {
context.append(',');
}
@@ -1108,13 +1054,11 @@ public class EJBQLConditionTranslator ex
if (!(expression.getChild(0) instanceof EJBQLTrimSpecification)) {
context.append(" {fn LTRIM({fn RTRIM(");
}
- }
- else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
+ } else if (finishedChildIndex + 1 == expression.getChildrenCount()) {
if (!(expression.getChild(0) instanceof EJBQLTrimSpecification)
|| expression.getChild(0) instanceof EJBQLTrimBoth) {
context.append(")})}");
- }
- else {
+ } else {
context.append(")}");
}
}
@@ -1127,8 +1071,7 @@ public class EJBQLConditionTranslator ex
// this is expected to be overwritten in adapter-specific translators
if (!"' '".equals(expression.getText())) {
throw new UnsupportedOperationException(
- "TRIM character other than space is not supported by a generic adapter: "
- + expression.getText());
+ "TRIM character other than space is not supported by a generic adapter: " + expression.getText());
}
return false;
@@ -1171,15 +1114,13 @@ class EJBQLPathAnaliserTranslator extend
public boolean visitPath(EJBQLExpression expression, int finishedChildIndex) {
if (isPath) {
return false;
- }
- else {
+ } else {
if (finishedChildIndex > 0) {
if (finishedChildIndex + 1 < expression.getChildrenCount()) {
processIntermediatePathComponent();
- }
- else {
+ } else {
processLastPathComponent();
if (idPath != null && lastPathComponent != null) {
isPath = true;
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDbPathTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDbPathTranslator.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDbPathTranslator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDbPathTranslator.java Sun Feb 24 13:05:14 2013
@@ -58,8 +58,7 @@ public abstract class EJBQLDbPathTransla
if (finishedChildIndex + 1 < expression.getChildrenCount()) {
processIntermediatePathComponent();
- }
- else {
+ } else {
processLastPathComponent();
}
}
@@ -73,8 +72,7 @@ public abstract class EJBQLDbPathTransla
// expression id is always rooted in an ObjEntity, even for DbPath...
ClassDescriptor descriptor = context.getEntityDescriptor(expression.getText());
if (descriptor == null) {
- throw new EJBQLException("Invalid identification variable: "
- + expression.getText());
+ throw new EJBQLException("Invalid identification variable: " + expression.getText());
}
this.currentEntity = descriptor.getEntity().getDbEntity();
@@ -87,7 +85,8 @@ public abstract class EJBQLDbPathTransla
@Override
public boolean visitIdentificationVariable(EJBQLExpression expression) {
- // TODO: andrus 6/11/2007 - if the path ends with relationship, the last join will
+ // TODO: andrus 6/11/2007 - if the path ends with relationship, the last
+ // join will
// get lost...
if (lastPathComponent != null) {
resolveJoin(true);
@@ -99,46 +98,34 @@ public abstract class EJBQLDbPathTransla
private void resolveJoin(boolean inner) {
- EJBQLJoinAppender joinAppender = context.getTranslatorFactory().getJoinAppender(
- context);
+ EJBQLJoinAppender joinAppender = context.getTranslatorFactory().getJoinAppender(context);
// TODO: andrus 1/6/2007 - conflict with object path naming... maybe
// 'registerReusableJoin' should normalize everything to a db path?
String newPath = idPath + '.' + lastPathComponent;
- String oldPath = joinAppender.registerReusableJoin(
- idPath,
- lastPathComponent,
- newPath);
+ String oldPath = joinAppender.registerReusableJoin(idPath, lastPathComponent, newPath);
this.fullPath = fullPath + '.' + lastPathComponent;
if (oldPath != null) {
this.idPath = oldPath;
- this.lastAlias = context.getTableAlias(oldPath, context.getQuotingSupport().generateTableName(currentEntity));
- }
- else {
+ this.lastAlias = context.getTableAlias(oldPath,
+ context.getQuotingStrategy().quotedFullyQualifiedName(currentEntity));
+ } else {
// register join
if (inner) {
- joinAppender.appendInnerJoin(
- joinMarker,
- new EJBQLTableId(idPath),
- new EJBQLTableId(fullPath));
- this.lastAlias = context.getTableAlias(fullPath, context.getQuotingSupport().generateTableName(
- currentEntity));
- }
- else {
- joinAppender.appendOuterJoin(
- joinMarker,
- new EJBQLTableId(idPath),
- new EJBQLTableId(fullPath));
+ joinAppender.appendInnerJoin(joinMarker, new EJBQLTableId(idPath), new EJBQLTableId(fullPath));
+ this.lastAlias = context.getTableAlias(fullPath,
+ context.getQuotingStrategy().quotedFullyQualifiedName(currentEntity));
+ } else {
+ joinAppender.appendOuterJoin(joinMarker, new EJBQLTableId(idPath), new EJBQLTableId(fullPath));
- Relationship lastRelationship = currentEntity
- .getRelationship(lastPathComponent);
+ Relationship lastRelationship = currentEntity.getRelationship(lastPathComponent);
DbEntity targetEntity = (DbEntity) lastRelationship.getTargetEntity();
- this.lastAlias = context.getTableAlias(fullPath, context.getQuotingSupport().generateTableName(
- targetEntity));
+ this.lastAlias = context.getTableAlias(fullPath,
+ context.getQuotingStrategy().quotedFullyQualifiedName(targetEntity));
}
this.idPath = newPath;
@@ -146,14 +133,10 @@ public abstract class EJBQLDbPathTransla
}
private void processIntermediatePathComponent() {
- DbRelationship relationship = (DbRelationship) currentEntity
- .getRelationship(lastPathComponent);
+ DbRelationship relationship = (DbRelationship) currentEntity.getRelationship(lastPathComponent);
if (relationship == null) {
- throw new EJBQLException("Unknown relationship '"
- + lastPathComponent
- + "' for entity '"
- + currentEntity.getName()
- + "'");
+ throw new EJBQLException("Unknown relationship '" + lastPathComponent + "' for entity '"
+ + currentEntity.getName() + "'");
}
this.currentEntity = (DbEntity) relationship.getTargetEntity();
@@ -161,16 +144,14 @@ public abstract class EJBQLDbPathTransla
private void processLastPathComponent() {
- DbAttribute attribute = (DbAttribute) currentEntity
- .getAttribute(lastPathComponent);
+ DbAttribute attribute = (DbAttribute) currentEntity.getAttribute(lastPathComponent);
if (attribute != null) {
processTerminatingAttribute(attribute);
return;
}
- DbRelationship relationship = (DbRelationship) currentEntity
- .getRelationship(lastPathComponent);
+ DbRelationship relationship = (DbRelationship) currentEntity.getRelationship(lastPathComponent);
if (relationship != null) {
processTerminatingRelationship(relationship);
return;
@@ -184,14 +165,11 @@ public abstract class EJBQLDbPathTransla
DbEntity table = (DbEntity) attribute.getEntity();
if (isUsingAliases()) {
- String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(
- idPath,
- context.getQuotingSupport().generateTableName(table));
- context.append(' ').append(alias).append('.')
- .append(context.getQuotingSupport().generateColumnName(attribute));
- }
- else {
- context.append(' ').append(context.getQuotingSupport().generateColumnName(attribute));
+ String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context
+ .getQuotingStrategy().quotedFullyQualifiedName(table));
+ context.append(' ').append(alias).append('.').append(context.getQuotingStrategy().quotedName(attribute));
+ } else {
+ context.append(' ').append(context.getQuotingStrategy().quotedName(attribute));
}
}
@@ -204,9 +182,8 @@ public abstract class EJBQLDbPathTransla
DbEntity table = (DbEntity) relationship.getTargetEntity();
- String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(
- idPath,
- context.getQuotingSupport().generateTableName(table));
+ String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context
+ .getQuotingStrategy().quotedFullyQualifiedName(table));
Collection<DbAttribute> pks = table.getPrimaryKeys();
@@ -216,21 +193,17 @@ public abstract class EJBQLDbPathTransla
if (isUsingAliases()) {
context.append(alias).append('.');
}
- context.append(context.getQuotingSupport().generateColumnName(pk));
+ context.append(context.getQuotingStrategy().quotedName(pk));
+ } else {
+ throw new EJBQLException("Multi-column PK to-many matches are not yet supported.");
}
- else {
- throw new EJBQLException(
- "Multi-column PK to-many matches are not yet supported.");
- }
- }
- else {
+ } else {
// match FK against the target object
DbEntity table = (DbEntity) relationship.getSourceEntity();
- String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(
- idPath,
- context.getQuotingSupport().generateTableName(table));
+ String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context
+ .getQuotingStrategy().quotedFullyQualifiedName(table));
List<DbJoin> joins = relationship.getJoins();
@@ -240,23 +213,17 @@ public abstract class EJBQLDbPathTransla
if (isUsingAliases()) {
context.append(alias).append('.');
}
- context.append(context.getQuotingSupport().generateColumnName(join.getSource()));
- }
- else {
- Map<String, String> multiColumnMatch = new HashMap<String, String>(joins
- .size() + 2);
+ context.append(context.getQuotingStrategy().quotedName(join.getSource()));
+ } else {
+ Map<String, String> multiColumnMatch = new HashMap<String, String>(joins.size() + 2);
for (DbJoin join : joins) {
- String column = isUsingAliases()
- ? alias + "." + join.getSourceName()
- : join.getSourceName();
+ String column = isUsingAliases() ? alias + "." + join.getSourceName() : join.getSourceName();
multiColumnMatch.put(join.getTargetName(), column);
}
- appendMultiColumnPath(EJBQLMultiColumnOperand.getPathOperand(
- context,
- multiColumnMatch));
+ appendMultiColumnPath(EJBQLMultiColumnOperand.getPathOperand(context, multiColumnMatch));
}
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java Sun Feb 24 13:05:14 2013
@@ -49,9 +49,8 @@ class EJBQLGroupByTranslator extends EJB
if (itemCount++ > 0) {
context.append(',');
}
-
- expression.visit(context.getTranslatorFactory().getIdentifierColumnsTranslator(
- context));
+
+ expression.visit(context.getTranslatorFactory().getIdentifierColumnsTranslator(context));
return false;
}
@@ -66,41 +65,38 @@ class EJBQLGroupByTranslator extends EJB
@Override
protected void appendMultiColumnPath(EJBQLMultiColumnOperand operand) {
- throw new EJBQLException(
- "Can't GROUP BY on multi-column paths or objects");
+ throw new EJBQLException("Can't GROUP BY on multi-column paths or objects");
}
-
+
@Override
public boolean visitIdentificationVariable(EJBQLExpression expression) {
String idVariableAbsolutePath = fullPath + "." + expression.getText();
ClassDescriptor descriptor = context.getEntityDescriptor(idVariableAbsolutePath);
if (descriptor != null) {
- this.lastAlias = context.getTableAlias(idVariableAbsolutePath,
- context.getQuotingSupport().generateTableName(descriptor.getEntity().getDbEntity()));
+ this.lastAlias = context.getTableAlias(idVariableAbsolutePath, context.getQuotingStrategy()
+ .quotedFullyQualifiedName(descriptor.getEntity().getDbEntity()));
}
this.lastPathComponent = expression.getText();
this.fullPath = fullPath + '.' + lastPathComponent;
-
+
return true;
}
-
-
+
@Override
protected void processTerminatingRelationship(ObjRelationship relationship) {
- Collection<DbAttribute> dbAttr = ((ObjEntity) relationship
- .getTargetEntity()).getDbEntity().getAttributes();
+ Collection<DbAttribute> dbAttr = ((ObjEntity) relationship.getTargetEntity()).getDbEntity()
+ .getAttributes();
DbRelationship dbRelationship = relationship.getDbRelationships().get(0);
DbEntity table = (DbEntity) dbRelationship.getTargetEntity();
Iterator<DbAttribute> it = dbAttr.iterator();
-
- String alias = this.lastAlias != null ? lastAlias : context
- .getTableAlias(idPath, context.getQuotingSupport().generateTableName(table));
+ String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context
+ .getQuotingStrategy().quotedFullyQualifiedName(table));
boolean first = true;
while (it.hasNext()) {
@@ -108,17 +104,17 @@ class EJBQLGroupByTranslator extends EJB
context.append(!first ? ", " : " ");
DbAttribute dbAttribute = it.next();
- context.append(alias).append('.').append(context.getQuotingSupport().generateColumnName(dbAttribute));
+ context.append(alias).append('.').append(context.getQuotingStrategy().quotedName(dbAttribute));
first = false;
}
}
-
+
};
-
+
expression.visit(childVisitor);
-
+
return false;
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLIdentifierColumnsTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLIdentifierColumnsTranslator.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLIdentifierColumnsTranslator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLIdentifierColumnsTranslator.java Sun Feb 24 13:05:14 2013
@@ -64,15 +64,19 @@ class EJBQLIdentifierColumnsTranslator e
xfields = context.nextEntityResult().getFields();
}
- // assign whatever we have to a final ivar so that it can be accessed within
+ // assign whatever we have to a final ivar so that it can be accessed
+ // within
// the inner class
final Map<String, String> fields = xfields;
final String idVar = expression.getText();
// append all table columns ... the trick is to follow the algorithm for
- // describing the fields in the expression compiler, so that we could assign
- // columns labels from FieldResults in the order we encounter them here...
- // TODO: andrus 2008/02/17 - this is a bit of a hack, think of a better solution
+ // describing the fields in the expression compiler, so that we could
+ // assign
+ // columns labels from FieldResults in the order we encounter them
+ // here...
+ // TODO: andrus 2008/02/17 - this is a bit of a hack, think of a better
+ // solution
ClassDescriptor descriptor = context.getEntityDescriptor(idVar);
@@ -90,16 +94,12 @@ class EJBQLIdentifierColumnsTranslator e
Object pathPart = dbPathIterator.next();
if (pathPart == null) {
- throw new CayenneRuntimeException(
- "ObjAttribute has no component: " + oa.getName());
- }
- else if (pathPart instanceof DbRelationship) {
+ throw new CayenneRuntimeException("ObjAttribute has no component: " + oa.getName());
+ } else if (pathPart instanceof DbRelationship) {
if (marker == null) {
marker = EJBQLJoinAppender.makeJoinTailMarker(idVar);
- joinAppender = context
- .getTranslatorFactory()
- .getJoinAppender(context);
+ joinAppender = context.getTranslatorFactory().getJoinAppender(context);
}
DbRelationship dr = (DbRelationship) pathPart;
@@ -107,10 +107,8 @@ class EJBQLIdentifierColumnsTranslator e
EJBQLTableId rhsId = new EJBQLTableId(lhsId, dr.getName());
joinAppender.appendOuterJoin(marker, lhsId, rhsId);
lhsId = rhsId;
- }
- else if (pathPart instanceof DbAttribute) {
- appendColumn(idVar, oa, (DbAttribute) pathPart, fields, oa
- .getType());
+ } else if (pathPart instanceof DbAttribute) {
+ appendColumn(idVar, oa, (DbAttribute) pathPart, fields, oa.getType());
}
}
return true;
@@ -137,11 +135,13 @@ class EJBQLIdentifierColumnsTranslator e
}
};
- // EJBQL queries are polymorphic by definition - there is no distinction between
+ // EJBQL queries are polymorphic by definition - there is no distinction
+ // between
// inheritance/no-inheritance fetch
descriptor.visitAllProperties(visitor);
- // append id columns ... (some may have been appended already via relationships)
+ // append id columns ... (some may have been appended already via
+ // relationships)
DbEntity table = descriptor.getEntity().getDbEntity();
for (DbAttribute pk : table.getPrimaryKeys()) {
appendColumn(idVar, null, pk, fields);
@@ -161,8 +161,7 @@ class EJBQLIdentifierColumnsTranslator e
PrefetchTreeNode prefetchTree = context.getCompiledExpression().getPrefetchTree();
if (prefetchTree != null) {
for (PrefetchTreeNode prefetch : prefetchTree.adjacentJointNodes()) {
- ClassDescriptor descriptor = context.getEntityDescriptor(prefetch
- .getEjbqlPathEntityId());
+ ClassDescriptor descriptor = context.getEntityDescriptor(prefetch.getEjbqlPathEntityId());
if (visitedIdentifier.equals(prefetch.getEjbqlPathEntityId())) {
DbEntity table = descriptor.getRootDbEntities().iterator().next();
ObjEntity objectEntity = descriptor.getEntity();
@@ -171,32 +170,23 @@ class EJBQLIdentifierColumnsTranslator e
Expression dbPrefetch = objectEntity.translateToDbPath(prefetchExp);
DbRelationship r = null;
- for (PathComponent<DbAttribute, DbRelationship> component : table
- .resolvePath(dbPrefetch, context
- .getMetadata()
- .getPathSplitAliases())) {
+ for (PathComponent<DbAttribute, DbRelationship> component : table.resolvePath(dbPrefetch, context
+ .getMetadata().getPathSplitAliases())) {
r = component.getRelationship();
}
if (r == null) {
- throw new CayenneRuntimeException("Invalid joint prefetch '"
- + prefetch
- + "' for entity: "
+ throw new CayenneRuntimeException("Invalid joint prefetch '" + prefetch + "' for entity: "
+ objectEntity.getName());
}
- Iterator<DbAttribute> targetAttributes = (Iterator<DbAttribute>) r
- .getTargetEntity()
- .getAttributes()
- .iterator();
+ Iterator<DbAttribute> targetAttributes = (Iterator<DbAttribute>) r.getTargetEntity()
+ .getAttributes().iterator();
while (targetAttributes.hasNext()) {
DbAttribute attribute = targetAttributes.next();
- appendColumn(prefetch.getEjbqlPathEntityId()
- + "."
- + prefetch.getPath(), attribute, "", prefetch.getPath()
- + "."
- + attribute.getName(), null);
+ appendColumn(prefetch.getEjbqlPathEntityId() + "." + prefetch.getPath(), attribute, "",
+ prefetch.getPath() + "." + attribute.getName(), null);
}
}
@@ -204,39 +194,25 @@ class EJBQLIdentifierColumnsTranslator e
}
}
- public void appendColumn(
- String identifier,
- ObjAttribute property,
- DbAttribute column,
- Map<String, String> fields) {
+ public void appendColumn(String identifier, ObjAttribute property, DbAttribute column, Map<String, String> fields) {
appendColumn(identifier, property, column, fields, null);
}
- public void appendColumn(
- String identifier,
- ObjAttribute property,
- DbAttribute column,
- Map<String, String> fields,
+ public void appendColumn(String identifier, ObjAttribute property, DbAttribute column, Map<String, String> fields,
String javaType) {
String columnLabel = "";
if (context.isAppendingResultColumns()) {
- columnLabel = fields.get(property != null
- ? property.getDbAttributePath()
- : column.getName());
+ columnLabel = fields.get(property != null ? property.getDbAttributePath() : column.getName());
}
appendColumn(identifier, column, columnLabel, columnLabel, javaType);
}
- public void appendColumn(
- String identifier,
- DbAttribute column,
- String columnAlias,
- String dataRowKey,
+ public void appendColumn(String identifier, DbAttribute column, String columnAlias, String dataRowKey,
String javaType) {
DbEntity table = (DbEntity) column.getEntity();
- String alias = context.getTableAlias(identifier, context.getQuotingSupport().generateTableName(table));
- String columnName = alias + "." + context.getQuotingSupport().generateColumnName(column);
+ String alias = context.getTableAlias(identifier, context.getQuotingStrategy().quotedFullyQualifiedName(table));
+ String columnName = alias + "." + context.getQuotingStrategy().quotedName(column);
Set<String> columns = getColumns();
@@ -255,17 +231,11 @@ class EJBQLIdentifierColumnsTranslator e
javaType = TypesMapping.getJavaBySqlType(column.getType());
}
- // TODO: andrus 6/27/2007 - the last parameter is an unofficial "jdbcType"
+ // TODO: andrus 6/27/2007 - the last parameter is an unofficial
+ // "jdbcType"
// pending CAY-813 implementation, switch to #column directive
- context
- .append("' '")
- .append(javaType)
- .append("' '")
- .append(columnAlias)
- .append("' '")
- .append(dataRowKey)
- .append("' " + column.getType())
- .append(")");
+ context.append("' '").append(javaType).append("' '").append(columnAlias).append("' '")
+ .append(dataRowKey).append("' " + column.getType()).append(")");
}
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java Sun Feb 24 13:05:14 2013
@@ -24,7 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.cayenne.dba.QuotingSupport;
+import org.apache.cayenne.dba.QuotingStrategy;
import org.apache.cayenne.ejbql.EJBQLBaseVisitor;
import org.apache.cayenne.ejbql.EJBQLException;
import org.apache.cayenne.ejbql.EJBQLExpression;
@@ -103,6 +103,7 @@ public class EJBQLJoinAppender {
throw new EJBQLException("No join configured for id " + rhsId);
}
+ QuotingStrategy quoter = context.getQuotingStrategy();
DbRelationship incomingDB = joinRelationships.get(0);
// TODO: andrus, 1/6/2008 - move reusable join check here...
@@ -111,7 +112,7 @@ public class EJBQLJoinAppender {
String tableName;
if (sourceEntity instanceof DbEntity) {
- tableName = context.getQuotingSupport().generateTableName((DbEntity) sourceEntity);
+ tableName = quoter.quotedFullyQualifiedName((DbEntity) sourceEntity);
}
else {
tableName = sourceEntity.getName();
@@ -135,13 +136,13 @@ public class EJBQLJoinAppender {
for (int i = 1; i < joinRelationships.size(); i++) {
DbRelationship dbRelationship = joinRelationships.get(i);
- String subquerySourceTableName = context.getQuotingSupport().generateTableName((DbEntity) dbRelationship
+ String subquerySourceTableName = quoter.quotedFullyQualifiedName((DbEntity) dbRelationship
.getSourceEntity());
String subquerySourceAlias = context.getTableAlias(
subquerySourceTableName,
subquerySourceTableName);
- String subqueryTargetTableName = context.getQuotingSupport().generateTableName(
+ String subqueryTargetTableName = quoter.quotedFullyQualifiedName(
(DbEntity) dbRelationship.getTargetEntity());
String subqueryTargetAlias = "";
@@ -196,7 +197,7 @@ public class EJBQLJoinAppender {
String sourceAlias,
String targetAlias) {
context.append(" ON (");
- QuotingSupport quotingSupport = context.getQuotingSupport();
+ QuotingStrategy quoter = context.getQuotingStrategy();
Iterator<DbJoin> it = incomingDB.getJoins().iterator();
if (it.hasNext()) {
@@ -204,11 +205,11 @@ public class EJBQLJoinAppender {
context
.append(sourceAlias)
.append('.')
- .append(quotingSupport.generateColumnName(dbJoin.getSource()))
+ .append(quoter.quotedSourceName(dbJoin))
.append(" = ")
.append(targetAlias)
.append('.')
- .append(quotingSupport.generateColumnName(dbJoin.getTarget()));
+ .append(quoter.quotedTargetName(dbJoin));
}
while (it.hasNext()) {
@@ -217,11 +218,11 @@ public class EJBQLJoinAppender {
context
.append(sourceAlias)
.append('.')
- .append(quotingSupport.generateColumnName(dbJoin.getSource()))
+ .append(quoter.quotedSourceName(dbJoin))
.append(" = ")
.append(targetAlias)
.append('.')
- .append(quotingSupport.generateColumnName(dbJoin.getTarget()));
+ .append(quoter.quotedTargetName(dbJoin));
}
context.append(")");
@@ -231,7 +232,7 @@ public class EJBQLJoinAppender {
DbEntity dbEntity = id.getDbEntity(context);
- String tableName = context.getQuotingSupport().generateTableName(dbEntity);
+ String tableName = context.getQuotingStrategy().quotedFullyQualifiedName(dbEntity);
String alias;
@@ -317,6 +318,10 @@ public class EJBQLJoinAppender {
}
if (!isProcessingOmitted) {
+
+ QuotingStrategy quoter = context.getQuotingStrategy();
+
+
Collection<ObjAttribute> attributes = context.getEntityDescriptor(
id.getEntityId()).getEntity().getAttributes();
for (ObjAttribute objAttribute : attributes) {
@@ -332,15 +337,13 @@ public class EJBQLJoinAppender {
if (next instanceof DbRelationship) {
DbRelationship rel = (DbRelationship) next;
context.append(" LEFT OUTER JOIN ");
- String targetEntityName = context.getQuotingSupport().generateTableName(
- (DbEntity) rel.getTargetEntity());
- String subqueryTargetAlias = context.getTableAlias(id
- .getEntityId(), targetEntityName);
- context.append(targetEntityName).append(' ').append(
- subqueryTargetAlias);
- generateJoiningExpression(rel, context.getTableAlias(id
- .getEntityId(),
- context.getQuotingSupport().generateTableName((DbEntity) rel.getSourceEntity())),
+ String targetEntityName = quoter.quotedFullyQualifiedName((DbEntity) 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())),
subqueryTargetAlias);
}