001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package core.tut.pori.dao.clause;
017
018import java.sql.Types;
019
020/**
021 * The interface for implementing SQL Clauses.
022 *
023 */
024public interface SQLClause {
025  /**
026   * Supported SQL types for the clause
027   */
028  public enum SQLType{
029    /** signed integer */
030    INTEGER(Types.INTEGER),
031    /** signed long integer */
032    LONG(Types.BIGINT),
033    /** double */
034    DOUBLE(Types.DOUBLE),
035    /** text string */
036    STRING(Types.VARCHAR),
037    /** boolean */
038    BOOLEAN(Types.BOOLEAN),
039    /** date/timestamp */
040    TIMESTAMP(Types.TIMESTAMP);
041    
042    private int _value;
043    
044    private SQLType(int value){
045      _value = value;
046    }
047    
048    /**
049     * 
050     * @return this SQLType as java.sql.Types.*
051     */
052    public int toInt(){
053      return _value;
054    }
055  } // enum SQLType
056  
057  /**
058   * 
059   * @return value types
060   */
061  public SQLType[] getValueTypes();
062  
063  /**
064   * Note: null value is accepted IF NULL is also set on the valueType map, otherwise behavior is undefined
065   * 
066   * The values will be added in-order in places designated by ? in the sql string
067   * 
068   * @return values
069   */
070  public Object[] getValues();
071  
072  /**
073   * print this clause the the given builder, the output should NOT include AND or OR keyword, this will be automatically added when needed
074   * @param sql
075   */
076  public void toSQLString(StringBuilder sql);
077}