01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.storage.search.implementation.database.functions;
11:
12: import org.mmbase.storage.search.*;
13: import org.mmbase.storage.search.implementation.database.*;
14:
15: /**
16: * An SQL handle also recognizing 'FunctionValueConstraint's.
17: *
18: * @author Marcel Maatkamp
19: * @version $Id: FunctionSqlHandler.java,v 1.7 2007/06/22 15:02:45 michiel Exp $
20: * @since MMBase-1.8.5
21: */
22: // TODO RvM: (later) add javadoc, elaborate on overwritten methods.
23: public class FunctionSqlHandler extends ChainedSqlHandler implements
24: SqlHandler {
25:
26: //public InformixSqlHandler(Map disallowedValues) {
27: // super(disallowedValues);
28: // mmbase = MMBase.getMMBase();
29: //}
30:
31: public FunctionSqlHandler(SqlHandler successor) {
32: super (successor);
33: // log.fatal("MARCEL: FunctionSqlHandler: Instantiated");
34:
35: }
36:
37: // javadoc is inherited
38: public void appendConstraintToSql(StringBuilder sb,
39: Constraint constraint, SearchQuery query, boolean inverse,
40: boolean inComposite) throws SearchQueryException {
41: // Net effect of inverse setting with constraint inverse property.
42: boolean overallInverse = inverse ^ constraint.isInverse();
43:
44: if (constraint instanceof FunctionValueConstraint) {
45: FunctionValueConstraint functionValueConstraint = (FunctionValueConstraint) constraint;
46:
47: //StringSearchConstraint stringSearchConstraint
48: // = (StringSearchConstraint) constraint;
49: StepField field = functionValueConstraint.getField();
50: // Map parameters = fieldValueConstraint.getParameters();
51:
52: if (overallInverse) {
53: sb.append("NOT ");
54: }
55:
56: // log.fatal("sb("+sb.toString()+"), constraint("+constraint+"), query("+query+"), inverse("+inverse+"), inComposite("+inComposite+"), overallInverse("+overallInverse+")");
57: // log.fatal("functionValueConstraint.getFunction("+functionValueConstraint.getFunction()+"), field.getStep().getAlias("+field.getStep().getAlias()+"), field.getStep().getAlias("+field.getStep().getAlias()+"), field.getFieldName("+field.getFieldName()+"), functionValueConstraint.getValue("+functionValueConstraint.getValue()+")");
58:
59: sb.append(functionValueConstraint.getFunction())
60: .append('(');
61:
62: // append 'users.email' or just 'email'?
63: if (field.getStep().getAlias() != null)
64: sb.append(getAllowedValue(field.getStep().getAlias()))
65: .append('.');
66:
67: sb.append(getAllowedValue(field.getFieldName()))
68: .append(')').append("='").append(
69: functionValueConstraint.getValue()).append(
70: '\'');
71: } else {
72: getSuccessor().appendConstraintToSql(sb, constraint, query,
73: inverse, inComposite);
74: }
75: }
76:
77: }
|