Project Wonder 5.0

er.extensions.jdbc
Class ERXSQLHelper

java.lang.Object
  extended by er.extensions.jdbc.ERXSQLHelper
Direct Known Subclasses:
ERXSQLHelper.DerbySQLHelper, ERXSQLHelper.FrontBaseSQLHelper, ERXSQLHelper.H2SQLHelper, ERXSQLHelper.MicrosoftSQLHelper, ERXSQLHelper.MySQLSQLHelper, ERXSQLHelper.NoSQLHelper, ERXSQLHelper.OpenBaseSQLHelper, ERXSQLHelper.OracleSQLHelper, ERXSQLHelper.PostgresqlSQLHelper

public class ERXSQLHelper
extends java.lang.Object

ERXSQLHelper provides support for additional database-vender-specific operations that JDBCPlugIn does not cover. By default this will try to load the class er.extensions.ERXSQLHelper$DatabaseVendorSQLHelper. For instance, er.extensions.ERXSQLHelper$FrontBaseSQLHelper. If you want to change the helper that is used for a particular database vendor, then override FrontBase.SQLHelper, Oracle.SQLHelper, etc. Case is important (because the vendor name is prepended to the class name), and should match what your JDBCPlugIn.databaseProductName() returns.

Author:
mschrag
Properties
databaseProductName.SQLHelper the class name of the SQLHelper for the database product name
           

Nested Class Summary
static class ERXSQLHelper.ColumnIndex
          IndexLimit represents the reference to a column for use in an index definition along with an optional limit.
static interface ERXSQLHelper.CustomTypes
          custom JDBC types
static class ERXSQLHelper.DerbySQLHelper
           
static class ERXSQLHelper.EROracleSQLHelper
           
static class ERXSQLHelper.FrontBaseSQLHelper
           
static class ERXSQLHelper.H2SQLHelper
           
static class ERXSQLHelper.MicrosoftSQLHelper
           
static class ERXSQLHelper.MySQLSQLHelper
           
static class ERXSQLHelper.NoSQLHelper
           
static class ERXSQLHelper.OpenBaseSQLHelper
           
static class ERXSQLHelper.OracleSQLHelper
           
static class ERXSQLHelper.PostgresqlSQLHelper
           
 
Field Summary
static org.apache.log4j.Logger log
          logging support
 
Constructor Summary
ERXSQLHelper()
           
 
Method Summary
 int _groupByOrHavingIndex(com.webobjects.eoaccess.EOSQLExpression expression)
          Returns the index in the expression's statement where group by and having clauses should be inserted.
 int _orderByIndex(com.webobjects.eoaccess.EOSQLExpression expression)
          Returns the index in the expression's statement where order by clauses should be inserted.
 void addGroupByClauseToExpression(com.webobjects.eocontrol.EOEditingContext editingContext, com.webobjects.eocontrol.EOFetchSpecification fetchSpec, com.webobjects.eoaccess.EOSQLExpression expression)
          Adds a group-by clause to the given SQL Expression based on the list of attributes defined in the given fetch spec.
 void addGroupByClauseToExpression(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOAttribute> attributes, com.webobjects.eoaccess.EOSQLExpression expression)
          Adds a group-by clause to the given SQL Expression based on the given list of attributes.
 void addHavingCountClauseToExpression(com.webobjects.foundation.NSSelector selector, int value, com.webobjects.eoaccess.EOSQLExpression expression)
          Adds a " having count(*) > x" clause to a group by expression.
 void appendItemToListString(java.lang.String itemString, java.lang.StringBuffer listString)
          Adds itemString to a comma-separated list.
 com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOAttribute> attributesToFetchForEntity(com.webobjects.eocontrol.EOFetchSpecification fetchSpec, com.webobjects.eoaccess.EOEntity entity)
          Returns the last of attributes to fetch for a fetch spec.
protected  boolean canReliablyPerformDistinctWithSortOrderings()
          Returns whether or not this database can always perform the a distinct operation when sort orderings are applied.
protected  ERXSQLHelper.ColumnIndex[] columnIndexesFromColumnNames(java.lang.String... columnNames)
           
 com.webobjects.foundation.NSMutableArray<java.lang.String> columnNamesFromColumnIndexes(ERXSQLHelper.ColumnIndex... columnIndexes)
           
protected  char commandSeparatorChar()
          This is totally cheating ...
protected  java.lang.String commandSeparatorString()
           
protected  java.util.regex.Pattern commentPattern()
          Returns a pattern than matches only blank lines.
 java.lang.String createDependentSchemaSQLForEntities(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, com.webobjects.eoaccess.EOAdaptor adaptor)
          Generates table create statements for a set of entities, then finds all the entities that those entities depend on (in other models) and generates foreign key statements for those, so you can generate sql for cross-model.
 java.lang.String createIndexSQLForEntities(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities)
           
 java.lang.String createIndexSQLForEntities(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, com.webobjects.foundation.NSArray<java.lang.String> externalTypesToIgnore)
           
 java.lang.String createSchemaSQLForEntitiesInDatabaseContext(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, com.webobjects.eoaccess.EODatabaseContext databaseContext, boolean create, boolean drop)
          creates SQL to create tables for the specified Entities.
 java.lang.String createSchemaSQLForEntitiesInModel(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, com.webobjects.eoaccess.EOModel model)
          Creates SQL to create tables for the specified Entities.
 java.lang.String createSchemaSQLForEntitiesInModelAndOptions(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, com.webobjects.eoaccess.EOModel model, com.webobjects.foundation.NSDictionary optionsCreate)
          creates SQL to create tables for the specified Entities.
 java.lang.String createSchemaSQLForEntitiesInModelWithName(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, java.lang.String modelName)
          creates SQL to create tables for the specified Entities.
 java.lang.String createSchemaSQLForEntitiesInModelWithNameAndOptions(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, java.lang.String modelName, com.webobjects.foundation.NSDictionary optionsCreate)
          creates SQL to create tables for the specified Entities.
 java.lang.String createSchemaSQLForEntitiesWithOptions(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, com.webobjects.eoaccess.EOAdaptor adaptor, com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> optionsDictionary)
          Creates the schema sql for a set of entities.
 java.lang.String createSchemaSQLForEntitiesWithOptions(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities, com.webobjects.eoaccess.EODatabaseContext databaseContext, com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> optionsCreate)
          Creates the schema sql for a set of entities.
 java.lang.String customQueryExpressionHintAsString(java.lang.Object hint)
          Returns the custom query expression hint as a String.
 com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.String> defaultOptionDictionary(boolean create, boolean drop)
          Creates an option dictionary to use with the other methods
 java.lang.String externalTypeForJDBCType(com.webobjects.jdbcadaptor.JDBCAdaptor adaptor, int jdbcType)
          JDBCAdaptor.externalTypeForJDBCType just returns the first type it finds instead of trying to find a best match.
protected  java.lang.String formatValueForAttribute(com.webobjects.eoaccess.EOSQLExpression expression, java.lang.Object value, com.webobjects.eoaccess.EOAttribute attribute, java.lang.String key)
           
 java.lang.Number getNextValFromSequenceNamed(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String modelName, java.lang.String sequenceName)
          Convenience method to get the next unique ID from a sequence.
 boolean handleDatabaseException(com.webobjects.eoaccess.EODatabaseContext databaseContext, java.lang.Throwable throwable)
          Returns true if the SQL helper can handle the exception.
 int jdbcTypeForCustomType(int jdbcType)
          Returns the JDBC type to use for a given ERXSQLHelper custom type
 java.lang.String limitExpressionForSQL(com.webobjects.eoaccess.EOSQLExpression expression, com.webobjects.eocontrol.EOFetchSpecification fetchSpecification, java.lang.String sql, long start, long end)
           
protected  int maximumElementPerInClause(com.webobjects.eoaccess.EOEntity entity)
          The database specific limit, or or most efficient number, of elements in an IN clause in a statement.
 java.lang.String migrationTableName()
          Returns the name of the table to use for database migrations.
static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOAdaptor adaptor)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EODatabaseChannel databaseChannel)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EODatabaseContext databaseContext)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eoaccess.EOEntity entity)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eoaccess.EOModel model)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String modelName)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOEntity entity)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOModel model)
           
static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOSQLExpression expression)
           
static ERXSQLHelper newSQLHelper(com.webobjects.jdbcadaptor.JDBCAdaptor adaptor)
           
static ERXSQLHelper newSQLHelper(com.webobjects.jdbcadaptor.JDBCPlugIn plugin)
           
static ERXSQLHelper newSQLHelper(java.lang.String databaseProductName)
           
 void prepareConnectionForSchemaChange(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eoaccess.EOModel model)
           
 java.lang.String quoteColumnName(java.lang.String columnName)
           
 java.lang.String readFormatForAggregateFunction(java.lang.String functionName, java.lang.String columnName, java.lang.String aggregateName)
          Returns the attribute read format for an aggregate function for a particular column with a name.
 boolean reassignExternalTypeForValueTypeOverride(com.webobjects.eoaccess.EOAttribute attribute)
           
 void removeSelectFromExpression(com.webobjects.eoaccess.EOAttribute attribute, com.webobjects.eoaccess.EOSQLExpression sqlExpression)
          Removes an attribute from the select list.
 void restoreConnectionSettingsAfterSchemaChange(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eoaccess.EOModel model)
           
 int rowCountForFetchSpecification(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOFetchSpecification spec)
          Returns the number of rows the supplied EOFetchSpecification would return.
 boolean shouldExecute(java.lang.String sql)
           
 boolean shouldPerformDistinctInMemory(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification)
          Returns whether or not this database should perform the distinct portion of the given fetch spec in memory or not.
 com.webobjects.foundation.NSArray<java.lang.String> splitSQLStatements(java.lang.String sql)
          Splits semicolon-separate sql statements into an array of strings
 com.webobjects.foundation.NSArray<java.lang.String> splitSQLStatementsFromFile(java.io.File f)
          Splits the SQL statements from the given file.
 com.webobjects.foundation.NSArray<java.lang.String> splitSQLStatementsFromInputStream(java.io.InputStream is)
          Splits the SQL statements from the given input stream
 com.webobjects.eoaccess.EOSQLExpression sqlExpressionForFetchSpecification(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOFetchSpecification spec, long start, long end)
          Creates the SQL which is used by the provided EOFetchSpecification, limited by the given range.
 com.webobjects.eoaccess.EOSQLExpression sqlExpressionForFetchSpecification(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOFetchSpecification spec, long start, long end, com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOAttribute> attributes)
          Creates the SQL which is used by the provided EOFetchSpecification, limited by the given range.
 java.lang.String sqlForCreateIndex(java.lang.String indexName, java.lang.String tableName, ERXSQLHelper.ColumnIndex... columnIndexes)
          Returns the SQL expression for creating an index on the given set of columns
 java.lang.String sqlForCreateIndex(java.lang.String indexName, java.lang.String tableName, java.lang.String... columnNames)
          Returns the SQL expression for creating an index on the given set of columns
 java.lang.String sqlForCreateUniqueIndex(java.lang.String indexName, java.lang.String tableName, ERXSQLHelper.ColumnIndex... columnIndexes)
          Returns the SQL expression for creating a unique index on the given set of columns
 java.lang.String sqlForCreateUniqueIndex(java.lang.String indexName, java.lang.String tableName, java.lang.String... columnNames)
          Returns the SQL expression for creating a unique index on the given set of columns
 java.lang.String sqlForFullTextQuery(ERXFullTextQualifier qualifier, com.webobjects.eoaccess.EOSQLExpression expression)
          Returns the SQL expression for a full text search query.
protected  java.lang.String sqlForGetNextValFromSequencedNamed(java.lang.String sequenceName)
          Returns the SQL required to select the next value from the given sequence.
 java.lang.String sqlForRegularExpressionQuery(java.lang.String key, java.lang.String value)
          Returns the SQL expression for a regular expression query.
protected  java.lang.String sqlForSubquery(java.lang.String subquery, java.lang.String alias)
          Returns the syntax for using the given query as an aliased subquery in a from-clause.
 java.lang.String sqlWhereClauseStringForKey(com.webobjects.eoaccess.EOSQLExpression e, java.lang.String key, com.webobjects.foundation.NSArray valueArray)
          Creates a where clause string " someKey IN ( someValue1,...)".
 int varcharLargeColumnWidth()
          Returns the width that should be used for a varcharLarge column in migrations.
 int varcharLargeJDBCType()
          Returns the JDBCType that should be used for a varcharLarge column in migrations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.log4j.Logger log
logging support

Constructor Detail

ERXSQLHelper

public ERXSQLHelper()
Method Detail

prepareConnectionForSchemaChange

public void prepareConnectionForSchemaChange(com.webobjects.eocontrol.EOEditingContext ec,
                                             com.webobjects.eoaccess.EOModel model)

restoreConnectionSettingsAfterSchemaChange

public void restoreConnectionSettingsAfterSchemaChange(com.webobjects.eocontrol.EOEditingContext ec,
                                                       com.webobjects.eoaccess.EOModel model)

shouldExecute

public boolean shouldExecute(java.lang.String sql)

createSchemaSQLForEntitiesInModelWithNameAndOptions

public java.lang.String createSchemaSQLForEntitiesInModelWithNameAndOptions(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                                            java.lang.String modelName,
                                                                            com.webobjects.foundation.NSDictionary optionsCreate)
creates SQL to create tables for the specified Entities. This can be used with EOUtilities rawRowsForSQL method to create the tables.

Parameters:
entities - a NSArray containing the entities for which create table statements should be generated or null if all entitites in the model should be used.
modelName - the name of the EOModel
optionsCreate -
Returns:
a String containing SQL statements to create tables

createSchemaSQLForEntitiesInModelAndOptions

public java.lang.String createSchemaSQLForEntitiesInModelAndOptions(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                                    com.webobjects.eoaccess.EOModel model,
                                                                    com.webobjects.foundation.NSDictionary optionsCreate)
creates SQL to create tables for the specified Entities. This can be used with EOUtilities rawRowsForSQL method to create the tables.

Parameters:
entities - a NSArray containing the entities for which create table statements should be generated or null if all entitites in the model should be used.
model - the EOModel
optionsCreate - a NSDictionary containing the different options
Returns:
a String containing SQL statements to create tables

createSchemaSQLForEntitiesWithOptions

public java.lang.String createSchemaSQLForEntitiesWithOptions(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                              com.webobjects.eoaccess.EODatabaseContext databaseContext,
                                                              com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> optionsCreate)
Creates the schema sql for a set of entities.

Parameters:
entities - the entities to create sql for
databaseContext - the database context to use
optionsCreate - the options (@see createSchemaSQLForEntitiesInModelWithNameAndOptions)
Returns:
a sql script

createDependentSchemaSQLForEntities

public java.lang.String createDependentSchemaSQLForEntities(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                            com.webobjects.eoaccess.EOAdaptor adaptor)
Generates table create statements for a set of entities, then finds all the entities that those entities depend on (in other models) and generates foreign key statements for those, so you can generate sql for cross-model.

Parameters:
entities - the entities to generate for
adaptor - the adaptor to use
Returns:
the sql script

createSchemaSQLForEntitiesWithOptions

public java.lang.String createSchemaSQLForEntitiesWithOptions(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                              com.webobjects.eoaccess.EOAdaptor adaptor,
                                                              com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> optionsDictionary)
Creates the schema sql for a set of entities.

Parameters:
entities - the entities to create sql for
adaptor - the adaptor to use
optionsDictionary - the options (@see createSchemaSQLForEntitiesInModelWithNameAndOptions)
Returns:
a sql script

createSchemaSQLForEntitiesInModelWithName

public java.lang.String createSchemaSQLForEntitiesInModelWithName(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                                  java.lang.String modelName)
creates SQL to create tables for the specified Entities. This can be used with EOUtilities rawRowsForSQL method to create the tables.

Parameters:
entities - a NSArray containing the entities for which create table statements should be generated or null if all entitites in the model should be used.
modelName - the name of the EOModel
Returns:
a String containing SQL statements to create tables

createSchemaSQLForEntitiesInModel

public java.lang.String createSchemaSQLForEntitiesInModel(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                          com.webobjects.eoaccess.EOModel model)
Creates SQL to create tables for the specified Entities. This can be used with EOUtilities rawRowsForSQL method to create the tables.

Parameters:
entities - a NSArray containing the entities for which create table statements should be generated or null if all entitites in the model should be used.
model - the EOModel
Returns:
a String containing SQL statements to create tables

defaultOptionDictionary

public com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.String> defaultOptionDictionary(boolean create,
                                                                                                                boolean drop)
Creates an option dictionary to use with the other methods

Parameters:
create - add create statements
drop - add drop statements

This method uses the following defaults options:
  • EOSchemaGeneration.DropTablesKey=YES if drop
  • EOSchemaGeneration.DropPrimaryKeySupportKey=YES if drop
  • EOSchemaGeneration.CreateTablesKey=YES if create
  • EOSchemaGeneration.CreatePrimaryKeySupportKey=YES if create
  • EOSchemaGeneration.PrimaryKeyConstraintsKey=YES if create
  • EOSchemaGeneration.ForeignKeyConstraintsKey=YES if create
  • EOSchemaGeneration.CreateDatabaseKey=NO
  • EOSchemaGeneration.DropDatabaseKey=NO


Possible values are YES and NO
Returns:
a String containing SQL statements to create tables

createSchemaSQLForEntitiesInDatabaseContext

public java.lang.String createSchemaSQLForEntitiesInDatabaseContext(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                                    com.webobjects.eoaccess.EODatabaseContext databaseContext,
                                                                    boolean create,
                                                                    boolean drop)
creates SQL to create tables for the specified Entities. This can be used with EOUtilities rawRowsForSQL method to create the tables.

Parameters:
entities - a NSArray containing the entities for which create table statements should be generated or null if all entitites in the model should be used.
databaseContext - the databaseContext
create - if true, tables and keys are created
drop - if true, tables and keys are dropped
Returns:
a String containing SQL statements to create tables

createIndexSQLForEntities

public java.lang.String createIndexSQLForEntities(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities)

createIndexSQLForEntities

public java.lang.String createIndexSQLForEntities(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOEntity> entities,
                                                  com.webobjects.foundation.NSArray<java.lang.String> externalTypesToIgnore)

attributesToFetchForEntity

public com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOAttribute> attributesToFetchForEntity(com.webobjects.eocontrol.EOFetchSpecification fetchSpec,
                                                                                                         com.webobjects.eoaccess.EOEntity entity)
Returns the last of attributes to fetch for a fetch spec. The entity is passed in here because it has likely already been looked up for the particular fetch spec.

Parameters:
fetchSpec - the fetch spec
entity - the entity (which should match fetchSpec.entityName())
Returns:
the list of attributes to fetch

sqlExpressionForFetchSpecification

public com.webobjects.eoaccess.EOSQLExpression sqlExpressionForFetchSpecification(com.webobjects.eocontrol.EOEditingContext ec,
                                                                                  com.webobjects.eocontrol.EOFetchSpecification spec,
                                                                                  long start,
                                                                                  long end)
Creates the SQL which is used by the provided EOFetchSpecification, limited by the given range.

Parameters:
ec - the EOEditingContext
spec - the EOFetchSpecification in question
start - start of rows to fetch
end - end of rows to fetch (-1 if not used)
Returns:
the EOSQLExpression which the EOFetchSpecification would use

customQueryExpressionHintAsString

public java.lang.String customQueryExpressionHintAsString(java.lang.Object hint)
Returns the custom query expression hint as a String. At the moment, if it's an EOSQLExpression, it just returns .statement().

Parameters:
hint - the hint to convert to a String
Returns:
the hint as a String

sqlExpressionForFetchSpecification

public com.webobjects.eoaccess.EOSQLExpression sqlExpressionForFetchSpecification(com.webobjects.eocontrol.EOEditingContext ec,
                                                                                  com.webobjects.eocontrol.EOFetchSpecification spec,
                                                                                  long start,
                                                                                  long end,
                                                                                  com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOAttribute> attributes)
Creates the SQL which is used by the provided EOFetchSpecification, limited by the given range.

Parameters:
ec - the EOEditingContext
spec - the EOFetchSpecification in question
start - start of rows to fetch
end - end of rows to fetch (-1 if not used)
attributes - the attributes to fetch from the given entity
Returns:
the EOSQLExpression which the EOFetchSpecification would use

limitExpressionForSQL

public java.lang.String limitExpressionForSQL(com.webobjects.eoaccess.EOSQLExpression expression,
                                              com.webobjects.eocontrol.EOFetchSpecification fetchSpecification,
                                              java.lang.String sql,
                                              long start,
                                              long end)

removeSelectFromExpression

public void removeSelectFromExpression(com.webobjects.eoaccess.EOAttribute attribute,
                                       com.webobjects.eoaccess.EOSQLExpression sqlExpression)
Removes an attribute from the select list.

Parameters:
attribute - the attribute to remove from the select list
sqlExpression - the expression to remove from

readFormatForAggregateFunction

public java.lang.String readFormatForAggregateFunction(java.lang.String functionName,
                                                       java.lang.String columnName,
                                                       java.lang.String aggregateName)
Returns the attribute read format for an aggregate function for a particular column with a name.

Parameters:
functionName - the aggregate function to generate
columnName - the column name to aggregate on
aggregateName - the name to assign to the aggregate result
Returns:
the generated read format

appendItemToListString

public void appendItemToListString(java.lang.String itemString,
                                   java.lang.StringBuffer listString)
Adds itemString to a comma-separated list. If listString already has entries, this method appends a comma followed by itemString. There is no good way to hook in and use EOSQLExpression's version of this, so we have our own copy of it.

Parameters:
itemString - the item to append
listString - the list buffer

addGroupByClauseToExpression

public void addGroupByClauseToExpression(com.webobjects.eocontrol.EOEditingContext editingContext,
                                         com.webobjects.eocontrol.EOFetchSpecification fetchSpec,
                                         com.webobjects.eoaccess.EOSQLExpression expression)
Adds a group-by clause to the given SQL Expression based on the list of attributes defined in the given fetch spec.

Parameters:
editingContext - the editing context to lookup entities with
fetchSpec - the fetch spec to retrieve attributes from
expression - the sql expression to add a "group by" clause to

_orderByIndex

public int _orderByIndex(com.webobjects.eoaccess.EOSQLExpression expression)
Returns the index in the expression's statement where order by clauses should be inserted.

Parameters:
expression - the expression to look into
Returns:
the index into statement where the order by should be inserted

_groupByOrHavingIndex

public int _groupByOrHavingIndex(com.webobjects.eoaccess.EOSQLExpression expression)
Returns the index in the expression's statement where group by and having clauses should be inserted.

Parameters:
expression - the expression to look into
Returns:
the index into statement where the group by should be inserted

addGroupByClauseToExpression

public void addGroupByClauseToExpression(com.webobjects.foundation.NSArray<com.webobjects.eoaccess.EOAttribute> attributes,
                                         com.webobjects.eoaccess.EOSQLExpression expression)
Adds a group-by clause to the given SQL Expression based on the given list of attributes.

Parameters:
attributes - the list of attributes to group by
expression - the sql expression to add a "group by" clause to

addHavingCountClauseToExpression

public void addHavingCountClauseToExpression(com.webobjects.foundation.NSSelector selector,
                                             int value,
                                             com.webobjects.eoaccess.EOSQLExpression expression)
Adds a " having count(*) > x" clause to a group by expression.

Parameters:
selector - the comparison selector -- just like EOKeyValueQualifier
value - the value to compare against
expression - the expression to modify

sqlForRegularExpressionQuery

public java.lang.String sqlForRegularExpressionQuery(java.lang.String key,
                                                     java.lang.String value)
Returns the SQL expression for a regular expression query.

Parameters:
key -
value -
Returns:
the regex SQL

sqlForFullTextQuery

public java.lang.String sqlForFullTextQuery(ERXFullTextQualifier qualifier,
                                            com.webobjects.eoaccess.EOSQLExpression expression)
Returns the SQL expression for a full text search query.

Parameters:
qualifier - the full text qualifier
expression - the EOSQLExpression context
Returns:
a SQL expression

sqlForCreateUniqueIndex

public java.lang.String sqlForCreateUniqueIndex(java.lang.String indexName,
                                                java.lang.String tableName,
                                                java.lang.String... columnNames)
Returns the SQL expression for creating a unique index on the given set of columns

Parameters:
indexName - the name of the index to create
tableName - the name of the containing table
columnNames - the list of column names to index on
Returns:
a SQL expression

sqlForCreateUniqueIndex

public java.lang.String sqlForCreateUniqueIndex(java.lang.String indexName,
                                                java.lang.String tableName,
                                                ERXSQLHelper.ColumnIndex... columnIndexes)
Returns the SQL expression for creating a unique index on the given set of columns

Parameters:
indexName - the name of the index to create
tableName - the name of the containing table
columnIndexes - the list of columns to index on
Returns:
a SQL expression

sqlForCreateIndex

public java.lang.String sqlForCreateIndex(java.lang.String indexName,
                                          java.lang.String tableName,
                                          java.lang.String... columnNames)
Returns the SQL expression for creating an index on the given set of columns

Parameters:
indexName - the name of the index to create
tableName - the name of the containing table
columnNames - the list of column names to index on
Returns:
a SQL expression

columnIndexesFromColumnNames

protected ERXSQLHelper.ColumnIndex[] columnIndexesFromColumnNames(java.lang.String... columnNames)

sqlForCreateIndex

public java.lang.String sqlForCreateIndex(java.lang.String indexName,
                                          java.lang.String tableName,
                                          ERXSQLHelper.ColumnIndex... columnIndexes)
Returns the SQL expression for creating an index on the given set of columns

Parameters:
indexName - the name of the index to create
tableName - the name of the containing table
columnIndexes - the list of columns to index on
Returns:
a SQL expression

varcharLargeJDBCType

public int varcharLargeJDBCType()
Returns the JDBCType that should be used for a varcharLarge column in migrations.

Returns:
the JDBCType that should be used for a varcharLarge column in migrations

varcharLargeColumnWidth

public int varcharLargeColumnWidth()
Returns the width that should be used for a varcharLarge column in migrations.

Returns:
the width that should be used for a varcharLarge column in migrations

migrationTableName

public java.lang.String migrationTableName()
Returns the name of the table to use for database migrations.

Returns:
the name of the table to use for database migrations

jdbcTypeForCustomType

public int jdbcTypeForCustomType(int jdbcType)
Returns the JDBC type to use for a given ERXSQLHelper custom type

Parameters:
jdbcType - the ERXSQLHelper custom type
Returns:
the JDBC type to use

externalTypeForJDBCType

public java.lang.String externalTypeForJDBCType(com.webobjects.jdbcadaptor.JDBCAdaptor adaptor,
                                                int jdbcType)
JDBCAdaptor.externalTypeForJDBCType just returns the first type it finds instead of trying to find a best match. This can still fail, mind you, but it should be much better than the EOF default impl.

Parameters:
adaptor - the adaptor to retrieve an external type for
jdbcType - the JDBC type number
Returns:
a guess at the external type name to use

rowCountForFetchSpecification

public int rowCountForFetchSpecification(com.webobjects.eocontrol.EOEditingContext ec,
                                         com.webobjects.eocontrol.EOFetchSpecification spec)
Returns the number of rows the supplied EOFetchSpecification would return.

Parameters:
ec - the EOEditingContext
spec - the EOFetchSpecification in question
Returns:
the number of rows

sqlForSubquery

protected java.lang.String sqlForSubquery(java.lang.String subquery,
                                          java.lang.String alias)
Returns the syntax for using the given query as an aliased subquery in a from-clause.

Parameters:
subquery - the subquery to wrap
alias - the alias to use
Returns:
the formatted subquery expression

sqlForGetNextValFromSequencedNamed

protected java.lang.String sqlForGetNextValFromSequencedNamed(java.lang.String sequenceName)
Returns the SQL required to select the next value from the given sequence. This should return a single row with a single column.

Parameters:
sequenceName - the name of the sequence
Returns:
the next sequence value

getNextValFromSequenceNamed

public java.lang.Number getNextValFromSequenceNamed(com.webobjects.eocontrol.EOEditingContext ec,
                                                    java.lang.String modelName,
                                                    java.lang.String sequenceName)
Convenience method to get the next unique ID from a sequence.

Parameters:
ec - editing context
modelName - name of the model which connects to the database that has the sequence in it
sequenceName - name of the sequence
Returns:
next value in the sequence

sqlWhereClauseStringForKey

public java.lang.String sqlWhereClauseStringForKey(com.webobjects.eoaccess.EOSQLExpression e,
                                                   java.lang.String key,
                                                   com.webobjects.foundation.NSArray valueArray)
Creates a where clause string " someKey IN ( someValue1,...)". Can migrate keyPaths.

Parameters:
e - the SQL expression
key - the name of the key
valueArray - an array of values to generate an "in" clause for
Returns:
the where clause for the given key

maximumElementPerInClause

protected int maximumElementPerInClause(com.webobjects.eoaccess.EOEntity entity)
The database specific limit, or or most efficient number, of elements in an IN clause in a statement. If there are more that this number of elements, additional IN clauses will be generated, ORed to the others.

Parameters:
entity - EOEntity that can be used to fine-tune the result
Returns:
database specific limit, or or most efficient number, of elements in an IN clause in a statement

formatValueForAttribute

protected java.lang.String formatValueForAttribute(com.webobjects.eoaccess.EOSQLExpression expression,
                                                   java.lang.Object value,
                                                   com.webobjects.eoaccess.EOAttribute attribute,
                                                   java.lang.String key)

splitSQLStatements

public com.webobjects.foundation.NSArray<java.lang.String> splitSQLStatements(java.lang.String sql)
Splits semicolon-separate sql statements into an array of strings

Parameters:
sql - a multi-line sql statement
Returns:
an array of sql statements

splitSQLStatementsFromInputStream

public com.webobjects.foundation.NSArray<java.lang.String> splitSQLStatementsFromInputStream(java.io.InputStream is)
                                                                                      throws java.io.IOException
Splits the SQL statements from the given input stream

Parameters:
is - the input stream to read from
Returns:
an array of SQL statements
Throws:
java.io.IOException - if there is a problem reading the stream

splitSQLStatementsFromFile

public com.webobjects.foundation.NSArray<java.lang.String> splitSQLStatementsFromFile(java.io.File f)
                                                                               throws java.io.IOException
Splits the SQL statements from the given file.

Parameters:
f - the file to read from
Returns:
an array of SQL statements
Throws:
java.io.IOException - if there is a problem reading the stream

commandSeparatorChar

protected char commandSeparatorChar()
This is totally cheating ... But I just need the separator character for now. We can rewrite the script parser later. Actually, somewhere on earth there is already a sql parser or two. Probably worth getting that one.

Returns:
the separator character used by this database

commandSeparatorString

protected java.lang.String commandSeparatorString()

commentPattern

protected java.util.regex.Pattern commentPattern()
Returns a pattern than matches only blank lines. Subclasses should implement this to return a pattern matching the vendor specific comment indicator(s).

Returns:
regex pattern that indicates this line is an SQL comment

columnNamesFromColumnIndexes

public com.webobjects.foundation.NSMutableArray<java.lang.String> columnNamesFromColumnIndexes(ERXSQLHelper.ColumnIndex... columnIndexes)

reassignExternalTypeForValueTypeOverride

public boolean reassignExternalTypeForValueTypeOverride(com.webobjects.eoaccess.EOAttribute attribute)

quoteColumnName

public java.lang.String quoteColumnName(java.lang.String columnName)

canReliablyPerformDistinctWithSortOrderings

protected boolean canReliablyPerformDistinctWithSortOrderings()
Returns whether or not this database can always perform the a distinct operation when sort orderings are applied. Oracle, for instance, will fail if you try to sort on a key that isn't in the list of fetched keys.

Returns:
whether or not this database can always perform the a distinct operation when sort orderings are applied

shouldPerformDistinctInMemory

public boolean shouldPerformDistinctInMemory(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification)
Returns whether or not this database should perform the distinct portion of the given fetch spec in memory or not.

Parameters:
fetchSpecification - the fetch spec to check
Returns:
whether or not this database should perform the distinct portion of the given fetch spec in memory or not

handleDatabaseException

public boolean handleDatabaseException(com.webobjects.eoaccess.EODatabaseContext databaseContext,
                                       java.lang.Throwable throwable)
Returns true if the SQL helper can handle the exception. Typical uses are morphing unique constraints to NSValidation exceptions.

Parameters:
databaseContext -
throwable -
Returns:
whether or not the SQL helper can handl this exception

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOSQLExpression expression)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eocontrol.EOEditingContext ec,
                                        java.lang.String modelName)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eocontrol.EOEditingContext ec,
                                        com.webobjects.eoaccess.EOEntity entity)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eocontrol.EOEditingContext ec,
                                        com.webobjects.eoaccess.EOModel model)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EODatabaseContext databaseContext)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EODatabaseChannel databaseChannel)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOAdaptor adaptor)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOAdaptorChannel adaptorChannel)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.jdbcadaptor.JDBCAdaptor adaptor)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.jdbcadaptor.JDBCPlugIn plugin)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOEntity entity)

newSQLHelper

public static ERXSQLHelper newSQLHelper(com.webobjects.eoaccess.EOModel model)

newSQLHelper

public static ERXSQLHelper newSQLHelper(java.lang.String databaseProductName)

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.