You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2003/12/17 13:36:27 UTC

cvs commit: ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl FunctionImpl.java PartsImpl.java ObjectFactoryImpl.java UpdateStatementImpl.java BooleanConstraintImpl.java StatementImpl.java SQLGeneratorImpl.java

jochen      2003/12/17 04:36:27

  Modified:    src/js/org/apache/ws/jaxme/sqls ObjectFactory.java
                        BooleanConstraint.java Statement.java
               src/js/org/apache/ws/jaxme/sqls/impl ObjectFactoryImpl.java
                        UpdateStatementImpl.java BooleanConstraintImpl.java
                        StatementImpl.java SQLGeneratorImpl.java
  Added:       src/js/org/apache/ws/jaxme/sqls Parts.java Function.java
               src/js/org/apache/ws/jaxme/sqls/impl FunctionImpl.java
                        PartsImpl.java
  Log:
  Added support for SQL functions.
  
  Revision  Changes    Path
  1.3       +4 -0      ws-jaxme/src/js/org/apache/ws/jaxme/sqls/ObjectFactory.java
  
  Index: ObjectFactory.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/ObjectFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectFactory.java	5 Dec 2003 09:45:20 -0000	1.2
  +++ ObjectFactory.java	17 Dec 2003 12:36:27 -0000	1.3
  @@ -64,4 +64,8 @@
     public JoinReference newJoinReference(SelectTableReference pSelectTableReference,
                                            Table pTable,
                                            boolean pIsLeftOuterJoin);
  +
  +  /** <p>Returns an instance of {@link Function}.</p>
  +   */
  +  public Function newFunction(Statement pStatement, String pName);
   }
  
  
  
  1.4       +1 -73     ws-jaxme/src/js/org/apache/ws/jaxme/sqls/BooleanConstraint.java
  
  Index: BooleanConstraint.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/BooleanConstraint.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BooleanConstraint.java	24 Nov 2003 08:40:08 -0000	1.3
  +++ BooleanConstraint.java	17 Dec 2003 12:36:27 -0000	1.4
  @@ -48,14 +48,12 @@
    */
   package org.apache.ws.jaxme.sqls;
   
  -import java.util.Iterator;
  -
   import org.apache.ws.jaxme.sqls.impl.BooleanConstraintImpl;
   
   /**
    * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
    */
  -public interface BooleanConstraint extends Constraint {
  +public interface BooleanConstraint extends Constraint, Parts {
     /** <p>The type of a boolean constraint.</p>
      */
     public interface Type {
  @@ -74,74 +72,4 @@
     /** <p>Returns the boolean constraints type.</p>
      */
     public BooleanConstraint.Type getType();
  -
  -  /** <p>Inserts a constant value.</p>
  -   */
  -  public void addPart(Value pValue);
  -
  -  /** <p>Inserts a column reference.</p>
  -   */
  -  public void addPart(ColumnReference pColumn);
  -
  -  /** <p>Inserts a set of column references.</p>
  -   */
  -  public void addPart(ColumnReference[] pPart);
  -  
  -  /** <p>Inserts a subselect.</p>
  -   */
  -  public void addPart(SelectStatement pPart);
  -  
  -  /** <p>Inserts a String. The String will be properly escaped.</p>
  -   * @throws NullPointerException The paremeter <code>pString</code> is null.
  -   */
  -  public void addPart(String pString);
  -  
  -  /** <p>Inserts a NULL value.</p>
  -   */
  -  public void addPart();
  -  
  -  /** <p>Inserts a byte value, which will be inserted without quotes.</p>
  -   */
  -  public void addPart(byte pByte);
  -  
  -  /** <p>Inserts an int value, which will be inserted without quotes.</p>
  -   */
  -  public void addPart(int pInt);
  -  
  -  /** <p>Inserts a long value, which will be inserted without quotes.</p>
  -   */
  -  public void addPart(long pLong);
  -  
  -  /** <p>Inserts a short value, which will be inserted without quotes.</p>
  -   */
  -  public void addPart(short pShort);
  -  
  -  /** <p>Inserts a float value, which will be inserted without quotes.</p>
  -   */
  -  public void addPart(float pFloat);
  -  
  -  /** <p>Inserts a double value, which will be inserted without quotes.</p>
  -   */
  -  public void addPart(double pDouble);
  -  
  -  /** <p>Inserts a boolean value, which will be inserted as the word
  -   * <code>TRUE</code>, or <code>FALSE</code>, respectively.</p>
  -   */
  -  public void addPart(boolean pBoolean);
  -  
  -  /** <p>Inserts raw SQL code.</p>
  -   */ 
  -  public void addRawSQLPart(String pRawSQL);
  -  
  -  /** <p>Inserts a placeholder.</p>
  -   */
  -  public void addPlaceholder();
  -  
  -  /** <p>Returns the number of parts.</p>
  -   */
  -  public int getNumParts();
  -  
  -  /** <p>Returns an Iterator to the parts that have been added.</p>
  -   */
  -  public Iterator getParts();
   }
  
  
  
  1.2       +5 -0      ws-jaxme/src/js/org/apache/ws/jaxme/sqls/Statement.java
  
  Index: Statement.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/Statement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Statement.java	23 Sep 2003 12:33:42 -0000	1.1
  +++ Statement.java	17 Dec 2003 12:36:27 -0000	1.2
  @@ -65,4 +65,9 @@
      /** <p>Returns the table reference, for which the statement applies.</p>
       */
      public TableReference getTableReference();
  +
  +   /** <p>Creates a new function, which may be added to a
  +    * {@link org.apache.ws.jaxme.sqls.BooleanConstraint}.</p>
  +    */
  +   public Function createFunction(String pName);
   }
  
  
  
  1.1                  ws-jaxme/src/js/org/apache/ws/jaxme/sqls/Parts.java
  
  Index: Parts.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   */
  package org.apache.ws.jaxme.sqls;
  
  import java.util.Iterator;
  
  /**
   * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
   */
  public interface Parts {
    /** <p>Inserts a constant value.</p>
     */
    public void addPart(Value pValue);
  
    /** <p>Inserts a column reference.</p>
     */
    public void addPart(ColumnReference pColumn);
  
    /** <p>Inserts a set of column references.</p>
     */
    public void addPart(ColumnReference[] pPart);
    
    /** <p>Inserts a subselect.</p>
     */
    public void addPart(SelectStatement pPart);
    
    /** <p>Inserts a String. The String will be properly escaped.</p>
     * @throws NullPointerException The paremeter <code>pString</code> is null.
     */
    public void addPart(String pString);
    
    /** <p>Inserts a NULL value.</p>
     */
    public void addPart();
    
    /** <p>Inserts a byte value, which will be inserted without quotes.</p>
     */
    public void addPart(byte pByte);
    
    /** <p>Inserts an int value, which will be inserted without quotes.</p>
     */
    public void addPart(int pInt);
    
    /** <p>Inserts a long value, which will be inserted without quotes.</p>
     */
    public void addPart(long pLong);
    
    /** <p>Inserts a short value, which will be inserted without quotes.</p>
     */
    public void addPart(short pShort);
    
    /** <p>Inserts a float value, which will be inserted without quotes.</p>
     */
    public void addPart(float pFloat);
    
    /** <p>Inserts a double value, which will be inserted without quotes.</p>
     */
    public void addPart(double pDouble);
    
    /** <p>Inserts a boolean value, which will be inserted as the word
     * <code>TRUE</code>, or <code>FALSE</code>, respectively.</p>
     */
    public void addPart(boolean pBoolean);
  
    /** <p>Inserts a function.</p>
     */
    public void addPart(Function pFunction);
  
    /** <p>Inserts raw SQL code.</p>
     */ 
    public void addRawSQLPart(String pRawSQL);
    
    /** <p>Inserts a placeholder.</p>
     */
    public void addPlaceholder();
    
    /** <p>Returns the number of parts.</p>
     */
    public int getNumParts();
    
    /** <p>Returns an Iterator to the parts that have been added.</p>
     */
    public Iterator getParts();
  }
  
  
  
  1.1                  ws-jaxme/src/js/org/apache/ws/jaxme/sqls/Function.java
  
  Index: Function.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   */
  package org.apache.ws.jaxme.sqls;
  
  /**
   * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
   */
  public interface Function extends Parts {
    /** <p>Returns the functions name.</p>
     */
    public String getName();
  }
  
  
  
  1.3       +6 -0      ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/ObjectFactoryImpl.java
  
  Index: ObjectFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/ObjectFactoryImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectFactoryImpl.java	5 Dec 2003 09:45:20 -0000	1.2
  +++ ObjectFactoryImpl.java	17 Dec 2003 12:36:27 -0000	1.3
  @@ -48,10 +48,12 @@
    */
   package org.apache.ws.jaxme.sqls.impl;
   
  +import org.apache.ws.jaxme.sqls.Function;
   import org.apache.ws.jaxme.sqls.JoinReference;
   import org.apache.ws.jaxme.sqls.ObjectFactory;
   import org.apache.ws.jaxme.sqls.RawSQLCode;
   import org.apache.ws.jaxme.sqls.SelectTableReference;
  +import org.apache.ws.jaxme.sqls.Statement;
   import org.apache.ws.jaxme.sqls.Table;
   
   
  @@ -71,5 +73,9 @@
                                            Table pTable,
                                            boolean pIsLeftOuterJoin) {
       return new JoinReferenceImpl(pSelectTableReference, pTable, pIsLeftOuterJoin);
  +  }
  +
  +  public Function newFunction(Statement pStatement, String pName) {
  +    return new FunctionImpl(pStatement, pName);
     }
   }
  
  
  
  1.2       +1 -0      ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/UpdateStatementImpl.java
  
  Index: UpdateStatementImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/UpdateStatementImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UpdateStatementImpl.java	23 Sep 2003 12:33:40 -0000	1.1
  +++ UpdateStatementImpl.java	17 Dec 2003 12:36:27 -0000	1.2
  @@ -49,6 +49,7 @@
   package org.apache.ws.jaxme.sqls.impl;
   
   import org.apache.ws.jaxme.sqls.CombinedConstraint;
  +import org.apache.ws.jaxme.sqls.Function;
   import org.apache.ws.jaxme.sqls.SQLFactory;
   import org.apache.ws.jaxme.sqls.UpdateStatement;
   
  
  
  
  1.3       +8 -99     ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/BooleanConstraintImpl.java
  
  Index: BooleanConstraintImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/BooleanConstraintImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BooleanConstraintImpl.java	19 Nov 2003 11:10:51 -0000	1.2
  +++ BooleanConstraintImpl.java	17 Dec 2003 12:36:27 -0000	1.3
  @@ -48,21 +48,15 @@
    */
   package org.apache.ws.jaxme.sqls.impl;
   
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import java.util.List;
  -
   import org.apache.ws.jaxme.sqls.BooleanConstraint;
  -import org.apache.ws.jaxme.sqls.ColumnReference;
   import org.apache.ws.jaxme.sqls.CombinedConstraint;
  -import org.apache.ws.jaxme.sqls.SelectStatement;
  -import org.apache.ws.jaxme.sqls.Value;
  +import org.apache.ws.jaxme.sqls.ConstrainedStatement;
   
   
   /**
    * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
    */
  -public class BooleanConstraintImpl extends ConstraintImpl implements BooleanConstraint {
  +public class BooleanConstraintImpl extends PartsImpl implements BooleanConstraint {
     public static class TypeImpl extends SQLFactoryImpl.IdentImpl implements BooleanConstraint.Type {
       public TypeImpl(String pName) {
         super(pName);
  @@ -84,109 +78,24 @@
         return type;
   	}
   
  -  private List parts = new ArrayList();
  -
  -  private void add(Object o) {
  +	protected void add(Object pPart) {
       if (getType().equals(BooleanConstraint.Type.IN)) {
         // Arbitrary number of parts
       } else if (getType().equals(BooleanConstraint.Type.ISNULL)) {
         // Exactly one part
  -      if (parts.size() == 1) {
  +      if (getNumParts() == 1) {
           throw new IllegalStateException("An IS NULL clause cannot have more than one part.");
         }
       } else {
         // Exactly two parts
  -      if (parts.size() == 2) {
  +      if (getNumParts() == 2) {
           throw new IllegalStateException("An " + getType() + " clause cannot have more than two parts.");
         }
       }
  -    parts.add(o);
  -  }
  -
  -  public void addPart(Value pValue) {
  -    if (pValue == null) {
  -      throw new NullPointerException("A constant value must not be null.");
  -    }
  -    parts.add(pValue);
  -  }
  -
  -	public void addPart(ColumnReference pColumn) {
  -    if (pColumn == null) {
  -      throw new NullPointerException("Referenced column must not be null.");
  -    }
  -    add(pColumn);
  -	}
  -
  -  public void addPart(ColumnReference[] pColumns) {
  -    if (pColumns == null) {
  -      throw new NullPointerException("The array of referenced columns must not be null.");
  -    }
  -    for (int i = 0;  i < pColumns.length;  i++) {
  -      if (pColumns[i] == null) {
  -        throw new NullPointerException("The referenced column with number " + i + " must not be null.");
  -      }
  -    }
  -    add(pColumns);
  -  }
  -
  -  public void addPart(SelectStatement pStatement) {
  -    if (pStatement == null) {
  -      throw new NullPointerException("The subselect statement must not be null.");
  -    }
  -    add(pStatement);
  -  }
  -
  -	public void addPart(String pString) {
  -      add(new ValueImpl(Value.Type.STRING, pString));
  -	}
  -
  -	public void addPart() {
  -      add(new ValueImpl(Value.Type.NULL, null));
  -	}
  -
  -	public void addPart(byte pByte) {
  -      add(new ValueImpl(Value.Type.BYTE, new Byte(pByte)));
  -	}
  -
  -	public void addPart(int pInt) {
  -      add(new ValueImpl(Value.Type.INT, new Integer(pInt)));
  -	}
  -
  -	public void addPart(long pLong) {
  -      add(new ValueImpl(Value.Type.LONG, new Long(pLong)));
  -	}
  -
  -	public void addPart(short pShort) {
  -      add(new ValueImpl(Value.Type.SHORT, new Short(pShort)));
  -	}
  -
  -	public void addPart(float pFloat) {
  -      add(new ValueImpl(Value.Type.FLOAT, new Float(pFloat)));
  -	}
  -
  -	public void addPart(double pDouble) {
  -      add(new ValueImpl(Value.Type.DOUBLE, new Double(pDouble)));
  -	}
  -
  -	public void addPart(boolean pBoolean) {
  -      add(new ValueImpl(Value.Type.BOOLEAN, pBoolean ? Boolean.TRUE : Boolean.FALSE));
  -	}
  -
  -  public void addPlaceholder() {
  -    add(new ValueImpl(Value.Type.PLACEHOLDER, null));
  -  }
  -
  -  /** <p>Inserts raw SQL code.</p>
  -   */ 
  -  public void addRawSQLPart(String pRawSQL) {
  -    add(getConstrainedStatement().getSQLFactory().getObjectFactory().newRawSQL(pRawSQL));
  -  }
  -
  -  public int getNumParts() {
  -    return parts.size();
  +    super.add(pPart);
     }
   
  -  public Iterator getParts() {
  -    return parts.iterator();
  +  public ConstrainedStatement getConstrainedStatement() {
  +    return (ConstrainedStatement) getStatement();
     }
   }
  
  
  
  1.2       +34 -29    ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/StatementImpl.java
  
  Index: StatementImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/StatementImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StatementImpl.java	23 Sep 2003 12:33:40 -0000	1.1
  +++ StatementImpl.java	17 Dec 2003 12:36:27 -0000	1.2
  @@ -48,6 +48,7 @@
    */
   package org.apache.ws.jaxme.sqls.impl;
   
  +import org.apache.ws.jaxme.sqls.Function;
   import org.apache.ws.jaxme.sqls.SQLFactory;
   import org.apache.ws.jaxme.sqls.Statement;
   import org.apache.ws.jaxme.sqls.Table;
  @@ -62,33 +63,37 @@
    * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
    */
   public abstract class StatementImpl implements Statement {
  -   private SQLFactory factory;
  -   private TableReference tableReference;
  -
  -   protected StatementImpl(SQLFactory pFactory) {
  -      factory = pFactory;
  -   }
  -
  -   public SQLFactory getSQLFactory() {
  -      return factory;
  -   }
  -
  -   protected TableReference newTableReference(Table pTable) {
  -      return new TableReferenceImpl(this, pTable);
  -   }
  -
  -   public TableReference setTable(Table pTable) {
  -      if (pTable == null) {
  -         throw new NullPointerException("The table on which the statement operates must not be null.");
  -      }
  -      if (tableReference != null) {
  -         throw new IllegalStateException("The table on which the statement operates was already set.");
  -      }
  -      tableReference = newTableReference(pTable);
  -      return tableReference;
  -   }
  -
  -   public TableReference getTableReference() {
  -      return tableReference;
  -   }
  +  private SQLFactory factory;
  +  private TableReference tableReference;
  +  
  +  protected StatementImpl(SQLFactory pFactory) {
  +    factory = pFactory;
  +  }
  +  
  +  public SQLFactory getSQLFactory() {
  +    return factory;
  +  }
  +  
  +  protected TableReference newTableReference(Table pTable) {
  +    return new TableReferenceImpl(this, pTable);
  +  }
  +  
  +  public TableReference setTable(Table pTable) {
  +    if (pTable == null) {
  +      throw new NullPointerException("The table on which the statement operates must not be null.");
  +    }
  +    if (tableReference != null) {
  +      throw new IllegalStateException("The table on which the statement operates was already set.");
  +    }
  +    tableReference = newTableReference(pTable);
  +    return tableReference;
  +  }
  +  
  +  public TableReference getTableReference() {
  +    return tableReference;
  +  }
  +  
  +  public Function createFunction(String pName) {
  +    return getSQLFactory().getObjectFactory().newFunction(this, pName);
  +  }
   }
  
  
  
  1.8       +21 -14    ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/SQLGeneratorImpl.java
  
  Index: SQLGeneratorImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/SQLGeneratorImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SQLGeneratorImpl.java	5 Dec 2003 09:45:20 -0000	1.7
  +++ SQLGeneratorImpl.java	17 Dec 2003 12:36:27 -0000	1.8
  @@ -64,7 +64,9 @@
   import org.apache.ws.jaxme.sqls.Constraint;
   import org.apache.ws.jaxme.sqls.DeleteStatement;
   import org.apache.ws.jaxme.sqls.ForeignKey;
  +import org.apache.ws.jaxme.sqls.Function;
   import org.apache.ws.jaxme.sqls.Index;
  +import org.apache.ws.jaxme.sqls.Parts;
   import org.apache.ws.jaxme.sqls.RawSQLCode;
   import org.apache.ws.jaxme.sqls.SQLGenerator;
   import org.apache.ws.jaxme.sqls.InsertStatement;
  @@ -576,6 +578,17 @@
       return "'" + s + "'";
     }
   
  +  protected String getParts(SelectStatementMetaData pData, Parts pParts) {
  +    StringBuffer sb = new StringBuffer();
  +    for (Iterator iter = pParts.getParts();  iter.hasNext();  ) {
  +      if (sb.length() > 0) {
  +        sb.append(", ");
  +      }
  +      sb.append(getBooleanConstraintPart(pData, iter.next()));
  +    }
  +    return sb.toString();
  +  }
  +
     protected String getBooleanConstraintPart(SelectStatementMetaData pData, Object o) {
       if (o instanceof Value) {
         return getValue((Value) o);
  @@ -584,9 +597,12 @@
       } else if (o instanceof ColumnReference[]) {
         return getColumnAlias(pData, (ColumnReference[]) o);
       } else if (o instanceof SelectStatement) {
  -      return getQuery((SelectStatement) o);
  +      return '(' + getQuery((SelectStatement) o) + ')';
       } else if (o instanceof RawSQLCode) {
         return ((RawSQLCode) o).getRawSQL();
  +    } else if (o instanceof Function) {
  +      Function f = (Function) o;
  +      return f.getName() + '(' + getParts(pData, f) + ')';
       } else {
         throw new IllegalArgumentException("Invalid part of a boolean constraint: " + o.getClass().getName());
       }
  @@ -614,13 +630,16 @@
   
     protected String getBooleanConstraint(SelectStatementMetaData pData,
                                            BooleanConstraint pConstraint) {
  +    BooleanConstraint.Type type = pConstraint.getType();
  +    if (BooleanConstraint.Type.IN.equals(type)) {
  +      return "IN (" + getParts(pData, pConstraint) + ')';
  +    }
       StringBuffer result = new StringBuffer();
       Iterator parts = pConstraint.getParts();
       if (!parts.hasNext()) {
         throw new NullPointerException("A boolean constraint must have its parts set.");
       }
       int expected;
  -    BooleanConstraint.Type type = pConstraint.getType();
       if (BooleanConstraint.Type.EXISTS.equals(type)) {
         SelectStatement selectStatement = (SelectStatement) parts.next();
         result.append("EXISTS(");
  @@ -646,18 +665,6 @@
         } else if (BooleanConstraint.Type.ISNULL.equals(type)) {
           expected = 1;
           result.append(" IS NULL");
  -      } else if (BooleanConstraint.Type.IN.equals(type)) {
  -        expected = 0;
  -        String add = "(";
  -        result.append(" IN ");
  -        while (parts.hasNext()) {
  -          result.append(add);
  -          add = ",";
  -          result.append(getBooleanConstraintPart(pData, parts.next()));
  -        }
  -        if (",".equals(add)) {
  -          result.append(")");
  -        }
         } else {
           throw new IllegalArgumentException("Invalid boolean constraint type: " + type);
         }
  
  
  
  1.1                  ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/FunctionImpl.java
  
  Index: FunctionImpl.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   */
  package org.apache.ws.jaxme.sqls.impl;
  
  import org.apache.ws.jaxme.sqls.Function;
  import org.apache.ws.jaxme.sqls.Statement;
  
  /**
   * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
   */
  public class FunctionImpl extends PartsImpl implements Function {
    final String name;
  
    /** <p>Creates a new instance of FunctionImpl.java.</p>
     */
    protected FunctionImpl(Statement pStatement, String pName) {
      super(pStatement);
      name = pName;
    }
  
    public String getName() { return name; }
  }
  
  
  
  1.1                  ws-jaxme/src/js/org/apache/ws/jaxme/sqls/impl/PartsImpl.java
  
  Index: PartsImpl.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   */
  package org.apache.ws.jaxme.sqls.impl;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.ws.jaxme.sqls.ColumnReference;
  import org.apache.ws.jaxme.sqls.Function;
  import org.apache.ws.jaxme.sqls.SelectStatement;
  import org.apache.ws.jaxme.sqls.Statement;
  import org.apache.ws.jaxme.sqls.Value;
  
  /**
   * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
   */
  public abstract class PartsImpl {
    private final Statement statement;
    private final List parts = new ArrayList();
  
    protected PartsImpl(Statement pStatement) {
      statement = pStatement;
    }
  
    protected void add(Object o) {
      parts.add(o);
    }
  
    public Statement getStatement() {
      return statement;
    }
  
    public void addPart(Value pValue) {
      if (pValue == null) {
        throw new NullPointerException("A constant value must not be null.");
      }
      parts.add(pValue);
    }
  
    public void addPart(ColumnReference pColumn) {
      if (pColumn == null) {
        throw new NullPointerException("Referenced column must not be null.");
      }
      add(pColumn);
    }
  
    public void addPart(ColumnReference[] pColumns) {
      if (pColumns == null) {
        throw new NullPointerException("The array of referenced columns must not be null.");
      }
      for (int i = 0;  i < pColumns.length;  i++) {
        if (pColumns[i] == null) {
          throw new NullPointerException("The referenced column with number " + i + " must not be null.");
        }
      }
      add(pColumns);
    }
  
    public void addPart(SelectStatement pStatement) {
      if (pStatement == null) {
        throw new NullPointerException("The subselect statement must not be null.");
      }
      add(pStatement);
    }
  
    public void addPart(String pString) {
      add(new ValueImpl(Value.Type.STRING, pString));
    }
  
    public void addPart() {
      add(new ValueImpl(Value.Type.NULL, null));
    }
  
    public void addPart(byte pByte) {
      add(new ValueImpl(Value.Type.BYTE, new Byte(pByte)));
    }
  
    public void addPart(int pInt) {
      add(new ValueImpl(Value.Type.INT, new Integer(pInt)));
    }
  
    public void addPart(long pLong) {
      add(new ValueImpl(Value.Type.LONG, new Long(pLong)));
    }
  
    public void addPart(short pShort) {
      add(new ValueImpl(Value.Type.SHORT, new Short(pShort)));
    }
  
    public void addPart(float pFloat) {
      add(new ValueImpl(Value.Type.FLOAT, new Float(pFloat)));
    }
  
    public void addPart(double pDouble) {
      add(new ValueImpl(Value.Type.DOUBLE, new Double(pDouble)));
    }
  
    public void addPart(boolean pBoolean) {
      add(new ValueImpl(Value.Type.BOOLEAN, pBoolean ? Boolean.TRUE : Boolean.FALSE));
    }
  
    public void addPart(Function pFunction) {
      add(pFunction);
    }
  
    public void addPlaceholder() {
      add(new ValueImpl(Value.Type.PLACEHOLDER, null));
    }
  
    /** <p>Inserts raw SQL code.</p>
     */ 
    public void addRawSQLPart(String pRawSQL) {
      add(getStatement().getSQLFactory().getObjectFactory().newRawSQL(pRawSQL));
    }
  
    public int getNumParts() {
      return parts.size();
    }
  
    public Iterator getParts() {
      return parts.iterator();
    }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org