You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ev...@apache.org on 2010/05/21 22:31:59 UTC
svn commit: r947164 - 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: evgeny
Date: Fri May 21 20:31:59 2010
New Revision: 947164
URL: http://svn.apache.org/viewvc?rev=947164&view=rev
Log:
CAY-1433 Change #chunk behaviour to skipe only null arguments (don't skip 0 or false)
Now chunk and chain are both checking only if value != null. Add test coverage for this cases.
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChainDirective.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChunkDirective.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateProcessorChainTest.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChainDirective.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChainDirective.java?rev=947164&r1=947163&r2=947164&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChainDirective.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChainDirective.java Fri May 21 20:31:59 2010
@@ -88,7 +88,7 @@ public class ChainDirective extends Dire
&& "chunk".equals(((ASTDirective) child).getDirectiveName())) {
if (child.jjtGetNumChildren() < 2
- || child.jjtGetChild(0).evaluate(context)) {
+ || child.jjtGetChild(0).value(context) != null) {
if (includedChunks > 0) {
childWriter.write(join);
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChunkDirective.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChunkDirective.java?rev=947164&r1=947163&r2=947164&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChunkDirective.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ChunkDirective.java Fri May 21 20:31:59 2010
@@ -35,12 +35,12 @@ import org.apache.velocity.runtime.parse
*
* <pre>
* #chunk()...#end - e.g. #chunk()A = 5#end
- * #chunk(condition)...#end - e.g. #chunk($a)A = $a#end</pre>
- *
- * <p>If condition is evaluated to false, chunk is not included in the chain,
- * if it is true, chunk is included, and if it is not the first chunk, it is
- * prefixed with chain join.
- *
+ * #chunk($paramKey)...#end - e.g. #chunk($a)A = $a#end
+ * </pre>
+ * <p>
+ * If context contains paramKey and it's value isn't null, chunk is included in the
+ * chain, and if it is not the first chunk, it is prefixed with chain join (OR/AND).
+ * If context doesn't contain paramKey or it's value is null, chunk is skipped.
* @since 1.1
*/
public class ChunkDirective extends Directive {
@@ -57,15 +57,12 @@ public class ChunkDirective extends Dire
@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node)
- throws
- IOException,
- ResourceNotFoundException,
- ParseErrorException,
+ throws IOException, ResourceNotFoundException, ParseErrorException,
MethodInvocationException {
// first child is an expression, second is BLOCK
- if (node.jjtGetNumChildren() > 1 && !node.jjtGetChild(0).evaluate(context)) {
- // return value is really meaningless in Velocity...whatever
+ if (node.jjtGetNumChildren() > 1 && node.jjtGetChild(0).value(context) == null) {
+ // skip this chunk
return false;
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateProcessorChainTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateProcessorChainTest.java?rev=947164&r1=947163&r2=947164&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateProcessorChainTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateProcessorChainTest.java Fri May 21 20:31:59 2010
@@ -173,4 +173,34 @@ public class SQLTemplateProcessorChainTe
assertEquals("", compiled.getSql());
}
+ public void testProcessTemplateWithFalseOrZero1() throws Exception {
+ String template = "#chain(' OR ' 'WHERE ')"
+ + "#chunk($a)[A]#end"
+ + "#chunk($b)[B]#end"
+ + "#chunk($c)$c#end"
+ + "#end";
+
+ Map map = new HashMap();
+ map.put("a", false);
+ map.put("b", 0);
+
+ SQLStatement compiled = new SQLTemplateProcessor().processTemplate(template, map);
+ assertEquals("WHERE [A] OR [B]", compiled.getSql());
+ }
+
+ public void testProcessTemplateWithFalseOrZero2() throws Exception {
+ String template = "#chain(' OR ' 'WHERE ')"
+ + "#chunk($a)$a#end"
+ + "#chunk($b)$b#end"
+ + "#chunk($c)$c#end"
+ + "#end";
+
+ Map map = new HashMap();
+ map.put("a", false);
+ map.put("b", 0);
+
+ SQLStatement compiled = new SQLTemplateProcessor().processTemplate(template, map);
+ assertEquals("WHERE false OR 0", compiled.getSql());
+ }
+
}