1 16 package org.outerj.daisy.query.model; 17 18 import org.outerj.daisy.query.QueryContext; 19 import org.outerj.daisy.repository.query.QueryException; 20 import org.outerj.daisy.repository.query.EvaluationContext; 21 import org.outerj.daisy.repository.Document; 22 import org.outerj.daisy.repository.Version; 23 24 import java.sql.PreparedStatement ; 25 import java.sql.SQLException ; 26 27 public class IsNotNull extends AbstractPredicateExpr { 28 private final Identifier identifier; 29 30 public IsNotNull(Identifier identifier) { 31 this.identifier = identifier; 32 } 33 34 public void prepare(QueryContext context) throws QueryException { 35 identifier.prepare(context); 36 } 37 38 public boolean evaluate(Document document, Version version, EvaluationContext evaluationContext) throws QueryException { 39 Object value = identifier.evaluate(null, document, version, evaluationContext); 40 return evaluate(value); 41 } 42 43 public boolean evaluate(Object value) { 44 return value != null; 45 } 46 47 public void generateSql(StringBuffer sql, SqlGenerationContext context) throws QueryException { 48 sql.append(" ("); 49 String preCond = identifier.getSqlPreConditions(context); 50 if (preCond != null) 51 sql.append(preCond).append(" and "); 52 identifier.generateSqlValueExpr(sql, context); 53 sql.append(" IS NOT NULL)"); 54 } 55 56 public int bindSql(PreparedStatement stmt, int bindPos, EvaluationContext evaluationContext) throws SQLException , QueryException { 57 bindPos = identifier.bindPreConditions(stmt, bindPos); 58 bindPos = identifier.bindValueExpr(stmt, bindPos, null, evaluationContext); 59 return bindPos; 60 } 61 62 public AclConditionViolation isAclAllowed() { 63 return identifier.isAclAllowed(); 64 } 65 66 public Tristate appliesTo(Document document) throws QueryException { 67 if (identifier.canTestAppliesTo()) { 68 boolean result = evaluate(identifier.evaluate(null, document, null, new EvaluationContext())); 69 return result ? Tristate.YES : Tristate.NO; 70 } else { 71 return Tristate.MAYBE; 72 } 73 } 74 } 75 | Popular Tags |