Coverage Report - org.israfil.sqlelements.AbstractParameterizedCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractParameterizedCommand
75% 
86% 
0
 
 1  
 /*
 2  
  * SQLElements object-oriented SQL parsing and generation library
 3  
  * 
 4  
  * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
 5  
  * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
 6  
  * All Rights Reserved
 7  
  * 
 8  
  *  This library is free software; you can redistribute it and/or modify 
 9  
  *  it under the terms of the GNU Lesser General Public License as published 
 10  
  *  by the Free Software Foundation; either version 2.1 of the License, or 
 11  
  *  (at your option) any later version.
 12  
  *
 13  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 14  
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 15  
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 16  
  * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 17  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 18  
  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 19  
  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 20  
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 21  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 22  
  * OF SUCH DAMAGE.
 23  
  *
 24  
  *  You should have received a copy of the GNU Lesser General Public License 
 25  
  *  along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
 26  
  *
 27  
  * $Id: AbstractParameterizedCommand.java 27 2006-01-14 07:50:08 -0500 (Sat, 14 Jan 2006) cgruber $
 28  
  */
 29  
 package org.israfil.sqlelements;
 30  
 
 31  
 import java.util.Set;
 32  
 
 33  
 import net.israfil.foundation.collections.ArraySet;
 34  
 
 35  
 import org.israfil.sqlelements.constraints.Constraint;
 36  
 
 37  
 /**
 38  
  * 
 39  
  * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
 40  
  * @author Latest: $Author: cgruber $
 41  
  * @version $Revision: 27 $
 42  
  */
 43  
 public abstract class AbstractParameterizedCommand extends AbstractCommand implements ParameterizedCommand {
 44  
 
 45  5
     protected Set<SQLParameter> parameters = new ArraySet<SQLParameter>();
 46  0
     public Set<SQLParameter> getParameters() { return parameters; }
 47  
 
 48  
     protected AbstractParameterizedCommand() {
 49  3
             super();
 50  3
     }
 51  
 
 52  
     public AbstractParameterizedCommand (Constraint constraint, SQLParameter ... parameters) {
 53  2
         super(constraint);
 54  2
         setParameters(parameters);  
 55  2
     }
 56  
 
 57  
     public void setParameters(SQLParameter ... parameters) 
 58  
     {
 59  2
         for (SQLParameter p : parameters) setParameter(p);
 60  2
     }
 61  
 
 62  
     public void setParameter(SQLParameter parameter) 
 63  
     {
 64  3
         if (parameter.column.getTable() == null) throw new IllegalArgumentException("Must supply column in parameters that contain a table.");
 65  3
         if (table == null) table = parameter.column.getTable();
 66  3
         if (!table.equals(parameter.column.getTable())) throw new IllegalArgumentException("Must supply columns only from the same table.");
 67  3
         for (SQLParameter current : parameters)
 68  0
             if (current.column == parameter.column) parameters.remove(current);
 69  3
         parameters.add(parameter);
 70  3
     }
 71  
 
 72  
     public void setParameter(Column c,Object v) {
 73  0
         setParameter(new SQLParameter(c,v));
 74  0
     }
 75  
 
 76  
     public Object getParameterValue(Column c) {
 77  1
         for (SQLParameter p : parameters) if (p.column == c) return p.value;
 78  0
         return null;
 79  
     }    
 80  
 }