Changeset 5401
- Timestamp:
- Sep 3, 2010, 1:58:11 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/jep/convert/EqualsConverter.java
r5385 r5401 22 22 package net.sf.basedb.util.jep.convert; 23 23 24 import net.sf.basedb.core.query.Expression; 24 25 import net.sf.basedb.core.query.Restriction; 25 26 import net.sf.basedb.core.query.Restrictions; 26 27 import net.sf.basedb.util.jep.Jep; 27 28 29 import org.nfunk.jep.ASTConstant; 28 30 import org.nfunk.jep.Node; 29 31 … … 66 68 } 67 69 /** 68 Convert to restriction by calling {@link Restrictions#eq(net.sf.basedb.core.query.Expression, net.sf.basedb.core.query.Expression)}. 70 Convert to restriction by calling {@link Restrictions#eq(Expression, Expression)}. 71 If the right-hand node is string constant containing '%' 72 {@link Restrictions#like(Expression, Expression)} is used instead (since 2.16). 69 73 */ 70 74 @Override 71 75 public Restriction toRestriction(Node node) 72 76 { 73 return Restrictions.eq( 74 Jep.nodeToExpression(node.jjtGetChild(0)), 75 Jep.nodeToExpression(node.jjtGetChild(1)) 76 ); 77 Node lNode = node.jjtGetChild(0); 78 Node rNode = node.jjtGetChild(1); 79 Expression left = Jep.nodeToExpression(lNode); 80 Expression right = Jep.nodeToExpression(rNode); 81 boolean useLike = false; 82 if (rNode instanceof ASTConstant) 83 { 84 ASTConstant constNode = (ASTConstant)rNode; 85 Object constValue = constNode.getValue(); 86 if (constValue instanceof String) 87 { 88 useLike = ((String)constValue).contains("%"); 89 } 90 } 91 return useLike ? Restrictions.like(left, right) : Restrictions.eq(left, right); 77 92 } 78 93 // -------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.