com.partnersoft.sql
Class GenericSqlDialect

java.lang.Object
  extended by com.partnersoft.sql.GenericSqlDialect
All Implemented Interfaces:
Lib, SqlDialect
Direct Known Subclasses:
DerbyDialect, HsqlDialect, MySqlDialect

public class GenericSqlDialect
extends java.lang.Object
implements SqlDialect

Generic SqlDialect. Ignores any operation that is type specific.

Any type specific behavior should be put in a database specific Dialect class, and added to SqlType for the correct type's getDialect().

Copyright 2009 Partner Software, Inc.

Version:
$Id$
Author:
Rich Stepanski

Constructor Summary
GenericSqlDialect()
           
 
Method Summary
 java.lang.String addColumn(java.lang.String tableName, CogStructureField newField, CogType newFieldType)
          Returns complete Sql to add a column.
 java.lang.String alterColumn(java.lang.String tableName, CogStructureField newField, CogType newFieldType)
          Returns complete Sql to alter a column.
 java.lang.String cogTypeToSqlType(CogType type)
          Helper for converting from a CogType to a Sql flavor specific data type.
protected  java.lang.String constantToSql(java.lang.String fieldValueType, java.lang.Object value)
          Helper for controlling how constant values of where clauses are writing in Sql.
 java.lang.String createTable(CogSchema schema, CogStructureType tableType)
          Returns complete Sql create table statement.
 java.lang.String dropColumn(java.lang.String tableName, java.lang.String fieldName)
          Returns complete Sql to drop a column.
protected  java.lang.String handleSorts(java.util.List<DataFilterSort> sorts)
          Helper method.
protected  java.lang.String listFields(java.util.List<java.lang.String> fields)
          Helper method.
protected  java.lang.String parseFilter(DataFilterExpression filter, CogStructureType type)
          Recursive helper for parsing DataFilterExpressions into sql.
 java.lang.String selectSql(DataRecordQuery query, CogStructureType tableType)
          Returns complete Sql select statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericSqlDialect

public GenericSqlDialect()
Method Detail

parseFilter

protected java.lang.String parseFilter(DataFilterExpression filter,
                                       CogStructureType type)
Recursive helper for parsing DataFilterExpressions into sql. This is protected so specific sql types can handle parsing in their own way.

Parameters:
filter - - DataFilterExpression to parse for Sql.
type - - CogStructureType defining the fields in filter.
Returns:
Sql equivalent of passed filter. (ie, all text after a 'where' in a Sql Where clause.

constantToSql

protected java.lang.String constantToSql(java.lang.String fieldValueType,
                                         java.lang.Object value)
Helper for controlling how constant values of where clauses are writing in Sql. By default, returns SqlLib.convertToStringAndQuote()

Parameters:
fieldValueType - - CogStructureField's value type for this field.
value - - Value to covert to String for Sql.
Returns:
String value of passed Object value to embed in Sql.

cogTypeToSqlType

public java.lang.String cogTypeToSqlType(CogType type)
Description copied from interface: SqlDialect
Helper for converting from a CogType to a Sql flavor specific data type. Default returns the CogPrimitiveType's sqlType, or VARCHAR(255)

Specified by:
cogTypeToSqlType in interface SqlDialect
Parameters:
type - - CogType to convert to Sql type.
Returns:
Sql flavor specific data type for the passed cog type.

listFields

protected java.lang.String listFields(java.util.List<java.lang.String> fields)
Helper method. Returns comma separated String containing passed list. ex. "fields[0],fields[1],...,fields[n]"

Parameters:
fields -
Returns:
Comma separated list of passed fields.

handleSorts

protected java.lang.String handleSorts(java.util.List<DataFilterSort> sorts)
Helper method. Returns complete ORDER BY clause. ex. " ORDER BY sorts[0].fieldName ASC, sorts[1].fieldName DESC"

Parameters:
sorts -
Returns:

selectSql

public java.lang.String selectSql(DataRecordQuery query,
                                  CogStructureType tableType)
Description copied from interface: SqlDialect
Returns complete Sql select statement.

Specified by:
selectSql in interface SqlDialect
Parameters:
query - - Query describing select statement.
tableType - - CogStructureType defining table. Type name is assumed to be table name.
Returns:
Sql select statement for passed query.

createTable

public java.lang.String createTable(CogSchema schema,
                                    CogStructureType tableType)
Description copied from interface: SqlDialect
Returns complete Sql create table statement.

Specified by:
createTable in interface SqlDialect
Parameters:
schema - - Schema defining column types.
tableType - - CogStructureType defining table. Type name is assumed to be table name.
Returns:
Sql create table statement for passed schema and cog type.

addColumn

public java.lang.String addColumn(java.lang.String tableName,
                                  CogStructureField newField,
                                  CogType newFieldType)
Description copied from interface: SqlDialect
Returns complete Sql to add a column.

Specified by:
addColumn in interface SqlDialect
Parameters:
tableName - - Name of table to add a column to.
newField - - Field to add.
newFieldType - - CogType of field to add.
Returns:
Sql to add a column.

alterColumn

public java.lang.String alterColumn(java.lang.String tableName,
                                    CogStructureField newField,
                                    CogType newFieldType)
Description copied from interface: SqlDialect
Returns complete Sql to alter a column.

Specified by:
alterColumn in interface SqlDialect
Parameters:
tableName - - Name of table to alter column in.
newField - - Field to change.
newFieldType - - CogType for the passed field.
Returns:
Sql to alter a column.

dropColumn

public java.lang.String dropColumn(java.lang.String tableName,
                                   java.lang.String fieldName)
Description copied from interface: SqlDialect
Returns complete Sql to drop a column.

Specified by:
dropColumn in interface SqlDialect
Parameters:
tableName - - Name of table to drop column from.
fieldName - - Name of field to drop.
Returns:
complete Sql to drop a column.