Coverage Report - org.melati.poem.SQLType
 
Classes in this File Line Coverage Branch Coverage Complexity
SQLType
N/A
N/A
1
 
 1  
 /*
 2  
  * $Source$
 3  
  * $Revision$
 4  
  *
 5  
  * Copyright (C) 2000 William Chesters
 6  
  *
 7  
  * Part of Melati (http://melati.org), a framework for the rapid
 8  
  * development of clean, maintainable web applications.
 9  
  *
 10  
  * Melati is free software; Permission is granted to copy, distribute
 11  
  * and/or modify this software under the terms either:
 12  
  *
 13  
  * a) the GNU General Public License as published by the Free Software
 14  
  *    Foundation; either version 2 of the License, or (at your option)
 15  
  *    any later version,
 16  
  *
 17  
  *    or
 18  
  *
 19  
  * b) any version of the Melati Software License, as published
 20  
  *    at http://melati.org
 21  
  *
 22  
  * You should have received a copy of the GNU General Public License and
 23  
  * the Melati Software License along with this program;
 24  
  * if not, write to the Free Software Foundation, Inc.,
 25  
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
 26  
  * GNU General Public License and visit http://melati.org to obtain the
 27  
  * Melati Software License.
 28  
  *
 29  
  * Feel free to contact the Developers of Melati (http://melati.org),
 30  
  * if you would like to work out a different arrangement than the options
 31  
  * outlined here.  It is our intention to allow Melati to be used by as
 32  
  * wide an audience as possible.
 33  
  *
 34  
  * This program is distributed in the hope that it will be useful,
 35  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 36  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 37  
  * GNU General Public License for more details.
 38  
  *
 39  
  * Contact details for copyright holder:
 40  
  *
 41  
  *     William Chesters <williamc At paneris.org>
 42  
  *     http://paneris.org/~williamc
 43  
  *     Obrechtstraat 114, 2517VX Den Haag, The Netherlands
 44  
  */
 45  
 
 46  
 package org.melati.poem;
 47  
 
 48  
 import java.sql.ResultSet;
 49  
 import java.sql.PreparedStatement;
 50  
 import org.melati.poem.dbms.Dbms;
 51  
 
 52  
 /**
 53  
  * A native SQL {@link Field} datatype.
 54  
  *
 55  
  * @author WilliamC At paneris.org
 56  
  *
 57  
  */
 58  
 public interface SQLType<T> {
 59  
   
 60  
   /**
 61  
    * @return The SQL92 ANSI code for this type.
 62  
    */
 63  
   int sqlTypeCode();
 64  
   
 65  
   
 66  
   /**
 67  
    * SQL type definition with nullability.
 68  
    * eg:
 69  
    * <code>
 70  
    * STRING NOT NULL
 71  
    * </code>
 72  
    * @param dbms the DBMS 
 73  
    * @return the DBMS specific SQL snippet
 74  
    */
 75  
   String sqlDefinition(Dbms dbms);
 76  
 
 77  
   /**
 78  
    * Used to set a not null value when 
 79  
    * creating a non nullable column.
 80  
    * @param dbms the dbms the value is suitable for 
 81  
    * @return a String suitable for substitution in UPDATE table SET field = ?
 82  
    */
 83  
   String sqlDefaultValue(Dbms dbms);
 84  
   
 85  
   /**
 86  
    * SQL type definition without nullability.
 87  
    * eg:
 88  
    * <code>
 89  
    * STRING
 90  
    * </code>
 91  
    * @param dbms the DBMS 
 92  
    * @return the DBMS specific SQL snippet
 93  
    */
 94  
   String sqlTypeDefinition(Dbms dbms);  
 95  
   /**
 96  
    * Quoting a raw value, if appropriate, for the Dbms.
 97  
    * <p>
 98  
    * numbers and booleans are not quoted for most dbms'.
 99  
    * @param raw sql value
 100  
    * @return the raw value with quotes if appropriate for the dbms
 101  
    */
 102  
   String quotedRaw(Object raw);
 103  
 
 104  
   /**
 105  
    * Return an object as delivered by the database.
 106  
    * 
 107  
    * @param rs the Resultset containing the value
 108  
    * @param col the column withing the ResultSet to read
 109  
    * @return the value as an Object
 110  
    */
 111  
   Object getRaw(ResultSet rs, int col)
 112  
       throws TypeMismatchPoemException, ValidationPoemException,
 113  
              ParsingPoemException;
 114  
 
 115  
   /**
 116  
    * Set a column of a PreparedStatement to the passed in value.
 117  
    * 
 118  
    * @param ps the Prepared Statement to modify
 119  
    * @param col the column within the PreparedStatement
 120  
    * @param cooked the value to set
 121  
    */
 122  
   void setRaw(PreparedStatement ps, int col, Object cooked)
 123  
       throws TypeMismatchPoemException;
 124  
 }