package org.litesoft.orsup.selection; import org.litesoft.util.IllegalArgument; // Copyright Status: // // All Software available from LiteSoft.org (including this file) is // hereby released into the public domain. // // It is free! As in, you may use it freely in both commercial and // non-commercial applications, bundle it with your software // distribution, include it on a CD-ROM, list the source code in a book, // mirror the documentation at your own web site, or use it in any other // way you see fit. // // NO Warranty! // // All software is provided "as is". // // There is ABSOLUTELY NO WARRANTY OF ANY KIND: not for the design, fitness // (for a particular purpose), level of errors (or lack thereof), or // applicability of this software. The entire risk as to the quality // and performance of this software is with you. Should this software // prove defective, you assume the cost of all necessary servicing, repair // or correction. // // In no event unless required by applicable law or agreed to in writing // will any party who created or may modify and/or redistribute this // software, be liable to you for damages, including any general, // special, incidental or consequential damages arising out of the use or // inability to use this software (including but not limited to loss of // data or data being rendered inaccurate or losses sustained by you or // third parties or a failure of this software to operate with any // other programs), even if such holder or other party has been advised // of the possibility of such damages. // // NOTE: Should you discover a bug, have a recogmendation for a change, wish // to submit modifications, or wish to add new classes/functionality, // please email them to: // // changes44@litesoft.org // /** * A class that can represent a SQL Single Column Select statement.
* * This form of SQL Select statement exists primarily to support the SQL IN * WhereClause.
*
* See AbstractWhereClauseColumnIsIn
* See WhereClause
* See WhereClauseFactory
* * Exceptions: All problems caught when the parameter(s) are checked (as * indicated/implied in the @param tags) will generate an IllegalArgumentException, * and means the API user has a problem. If a NullPointerException (or some * others, like: ClassCastException or ArrayIndexOutOfBoundsException) is thrown, * it means the API developer has a problem. Any Exception that is explicitly * thrown in the API, but unrelated to a parameter, will be listed in the throws * clause (and hopefully in the tag @throws). These may (but probably won't) be * checked Exceptions. * * @author George Smith * @version 1.03 02/07/02 Exception Policy, Use of IllegalArgument class. * @version 1.02 11/05/01 Completed? JavaDocs * @version 1.01 10/10/01 * @version 1.0 10/07/01 */ public class SingleColumnSelect { private SimpleColumnDefinition zColumnDefinition; private String zTableName; private WhereClause zWhereClause; /** * Constructor that supports the generation of a SQL Select statment that * selects a single column for all rows.
* * @param pColumnDefinition Column Definition (!null). * @param pFromTable Table Identifier (supports getTableName()) (!null). */ public SingleColumnSelect( SimpleColumnDefinition pColumnDefinition , SimpleTableIdentifier pFromTable ) { this( pColumnDefinition , pFromTable , null ); } /** * Constructor that supports the generation of a SQL Select statment that * selects a single column for the specified rows.
* * @param pColumnDefinition Column Definition (!null). * @param pFromTable Table Identifier (supports getTableName()) (!null). * @param pWhereClause A Where Clause to select the appropriate rows (null ok). */ public SingleColumnSelect( SimpleColumnDefinition pColumnDefinition , SimpleTableIdentifier pFromTable , WhereClause pWhereClause ) { IllegalArgument.ifNull( "ColumnDefinition" , zColumnDefinition = pColumnDefinition); IllegalArgument.ifNull( "TableIdentifier" , pFromTable ); IllegalArgument.ifNull( "TableName" , zTableName = pFromTable.getTableName()); zWhereClause = pWhereClause; // Null OK! } /** * Accessor for the Column Definition of the selected column.
* * @return The selected Column Definition (!null). */ public final SimpleColumnDefinition getColumnDefinition() { return zColumnDefinition; } /** * Accessor for the Table Name.
* * @return The Table Name (!null). */ public final String getTableName() { return zTableName; } /** * Accessor for the WhereClause to limit the select the rows.
* * @return Select's WhereClause (null == all rows). */ public final WhereClause getWhereClause() { return zWhereClause; } /** * Generate a Debug friendly representation.
* * @return a String for Debuging. */ public final String toString() { StringBuffer sb = new StringBuffer( "Select " ); sb.append( zColumnDefinition.getName() ); sb.append( " From " ); sb.append( zTableName ); if ( zWhereClause != null ) { sb.append( ' ' ); sb.append( zWhereClause.toString() ); } return sb.toString(); } /** * Generate a String that may be used as a SQL statement that selects a * single column.
* * Note: This String can get quite large.
* * @return a single column SQL SELECT statement. */ public final String toSQL() { StringBuffer sb = new StringBuffer( "SELECT " ); sb.append( zColumnDefinition.getColumnName() ); sb.append( " FROM " ); sb.append( zTableName ); if ( zWhereClause != null ) { sb.append( ' ' ); sb.append( zWhereClause.toSQL() ); } return sb.toString(); } }