1 17 package org.apache.ws.jaxme.sqls.impl; 18 19 import org.apache.ws.jaxme.sqls.BooleanConstraint; 20 import org.apache.ws.jaxme.sqls.CombinedConstraint; 21 import org.apache.ws.jaxme.sqls.ConstrainedStatement; 22 23 24 27 public class BooleanConstraintImpl extends PartsImpl implements BooleanConstraint { 28 30 public static class TypeImpl extends SQLFactoryImpl.IdentImpl implements BooleanConstraint.Type { 31 private static final long serialVersionUID = 3762254145096135991L; 32 34 public TypeImpl(String pName) { 35 super(pName); 36 } 37 } 38 39 private BooleanConstraint.Type type; 40 41 protected BooleanConstraintImpl(CombinedConstraint pCombinedConstraint, 42 BooleanConstraint.Type pType) { 43 super(pCombinedConstraint.getConstrainedStatement()); 44 if (pType == null) { 45 throw new NullPointerException ("The type must not be null."); 46 } 47 type = pType; 48 } 49 50 public BooleanConstraint.Type getType() { 51 return type; 52 } 53 54 protected void add(Object pPart) { 55 Type type = getType(); 56 if (BooleanConstraint.Type.IN.equals(type)) { 57 } else if (BooleanConstraint.Type.ISNULL.equals(type)) { 59 if (getNumParts() == 1) { 61 throw new IllegalStateException ("An IS NULL clause cannot have more than one part."); 62 } 63 } else if (BooleanConstraint.Type.BETWEEN.equals(type)) { 64 if (getNumParts() == 3) { 66 throw new IllegalStateException ("A BETWEEN clause cannot have more than three parts."); 67 } 68 } else { 69 if (getNumParts() == 2) { 71 throw new IllegalStateException ("An " + getType() + " clause cannot have more than two parts."); 72 } 73 } 74 super.add(pPart); 75 } 76 77 public ConstrainedStatement getConstrainedStatement() { 78 return (ConstrainedStatement) getStatement(); 79 } 80 81 public int getMinimumParts() { return 1; } 82 83 public int getMaximumParts() { 84 if (BooleanConstraint.Type.IN.equals(type)) { 85 return 0; 86 } else if (BooleanConstraint.Type.EXISTS.equals(type) 87 || BooleanConstraint.Type.ISNULL.equals(type)) { 88 return 1; 89 } else if (BooleanConstraint.Type.BETWEEN.equals(type)) { 90 return 3; 91 } else if (BooleanConstraint.Type.EQ.equals(type) 92 || BooleanConstraint.Type.NE.equals(type) 93 || BooleanConstraint.Type.GT.equals(type) 94 || BooleanConstraint.Type.LT.equals(type) 95 || BooleanConstraint.Type.GE.equals(type) 96 || BooleanConstraint.Type.LE.equals(type) 97 || BooleanConstraint.Type.LIKE.equals(type)) { 98 return 2; 99 } else { 100 throw new IllegalStateException ("Invalid type: " + type); 101 } 102 } 103 } 104 | Popular Tags |