| 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 IsLinked extends AbstractPredicateExpr { 28 private final boolean linked; 29 30 public IsLinked(boolean linked) { 31 this.linked = linked; 32 } 33 34 public void prepare(QueryContext context) throws QueryException { 35 } 37 38 public boolean evaluate(Document document, Version version, EvaluationContext evaluationContext) throws QueryException { 39 throw new RuntimeException ("IsLinked/IsNotLinked cannot be dynamically evaluated."); 40 } 41 42 public void generateSql(StringBuffer sql, SqlGenerationContext context) throws QueryException { 43 context.needsJoinWithTable(SqlGenerationContext.EXTRACTED_LINKS_TABLE_INVERSE); 44 sql.append(" ("); 45 sql.append(SqlGenerationContext.EXTRACTED_LINKS_TABLE.getName()); 46 sql.append("."); 47 sql.append(SqlGenerationContext.ExtractedLinksTable.TARGET_DOC_ID); 48 49 if (linked) { 50 sql.append(" is not null "); 51 } else { 52 sql.append(" is null "); 53 } 54 55 sql.append(") "); 56 } 57 58 public int bindSql(PreparedStatement stmt, int bindPos, EvaluationContext evaluationContext) throws SQLException { 59 return bindPos; 60 } 61 62 public AclConditionViolation isAclAllowed() { 63 return new AclConditionViolation("IsLinked/IsNotLinked is not allowed in ACL conditions"); 64 } 65 66 public Tristate appliesTo(Document document) { 67 throw new IllegalStateException (); 68 } 69 } 70 | Popular Tags |