public class ERXSQLHelper extends Object
Name | Description |
---|---|
databaseProductName.SQLHelper | the class name of the SQLHelper for the database product name |
Modifier and Type | Class and Description |
---|---|
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.DB2SQLHelper |
static class |
ERXSQLHelper.DerbySQLHelper |
static class |
ERXSQLHelper.EROracleSQLHelper |
static class |
ERXSQLHelper.FirebirdSQLHelper |
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 |
Constructor and Description |
---|
ERXSQLHelper() |
Modifier and Type | Method and Description |
---|---|
int |
_groupByOrHavingIndex(EOSQLExpression expression)
Returns the index in the expression's statement where group by and having
clauses should be inserted.
|
int |
_orderByIndex(EOSQLExpression expression)
Returns the index in the expression's statement where order by clauses
should be inserted.
|
void |
addGroupByClauseToExpression(EOEditingContext editingContext,
EOFetchSpecification fetchSpec,
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(NSArray<EOAttribute> attributes,
EOSQLExpression expression)
Adds a group-by clause to the given SQL Expression based on the given
list of attributes.
|
void |
addHavingCountClauseToExpression(NSSelector selector,
int value,
EOSQLExpression expression)
Adds a " having count(*) > x" clause to a group by expression.
|
void |
appendItemToListString(String itemString,
StringBuffer listString)
Adds itemString to a comma-separated list.
|
NSArray<EOAttribute> |
attributesToFetchForEntity(EOFetchSpecification fetchSpec,
EOEntity entity)
Returns the list 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(String... columnNames) |
NSMutableArray<String> |
columnNamesFromColumnIndexes(ERXSQLHelper.ColumnIndex... columnIndexes) |
protected char |
commandSeparatorChar()
This is totally cheating ...
|
protected String |
commandSeparatorString() |
protected Pattern |
commentPattern()
Returns a pattern than matches only blank lines.
|
String |
createDependentSchemaSQLForEntities(NSArray<EOEntity> entities,
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.
|
String |
createIndexSQLForEntities(NSArray<EOEntity> entities) |
String |
createIndexSQLForEntities(NSArray<EOEntity> entities,
NSArray<String> externalTypesToIgnore) |
String |
createSchemaSQLForEntitiesInDatabaseContext(NSArray<EOEntity> entities,
EODatabaseContext databaseContext,
boolean create,
boolean drop)
creates SQL to create tables for the specified Entities.
|
String |
createSchemaSQLForEntitiesInModel(NSArray<EOEntity> entities,
EOModel model)
Creates SQL to create tables for the specified Entities.
|
String |
createSchemaSQLForEntitiesInModelAndOptions(NSArray<EOEntity> entities,
EOModel model,
NSDictionary optionsCreate)
creates SQL to create tables for the specified Entities.
|
String |
createSchemaSQLForEntitiesInModelWithName(NSArray<EOEntity> entities,
String modelName)
creates SQL to create tables for the specified Entities.
|
String |
createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray<EOEntity> entities,
String modelName,
NSDictionary optionsCreate)
creates SQL to create tables for the specified Entities.
|
String |
createSchemaSQLForEntitiesWithOptions(NSArray<EOEntity> entities,
EOAdaptor adaptor,
NSDictionary<String,String> optionsDictionary)
Creates the schema sql for a set of entities.
|
String |
createSchemaSQLForEntitiesWithOptions(NSArray<EOEntity> entities,
EODatabaseContext databaseContext,
NSDictionary<String,String> optionsCreate)
Creates the schema sql for a set of entities.
|
String |
customQueryExpressionHintAsString(Object hint)
Returns the custom query expression hint as a String.
|
NSMutableDictionary<String,String> |
defaultOptionDictionary(boolean create,
boolean drop)
Creates an option dictionary to use with the other methods
|
String |
externalTypeForJDBCType(JDBCAdaptor adaptor,
int jdbcType)
JDBCAdaptor.externalTypeForJDBCType just returns the first type it finds
instead of trying to find a best match.
|
protected String |
formatValueForAttribute(EOSQLExpression expression,
Object value,
EOAttribute attribute,
String key) |
Number |
getNextValFromSequenceNamed(EOEditingContext ec,
String modelName,
String sequenceName)
Convenience method to get the next unique ID from a sequence.
|
boolean |
handleDatabaseException(EODatabaseContext databaseContext,
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
|
String |
limitExpressionForSQL(EOSQLExpression expression,
EOFetchSpecification fetchSpecification,
String sql,
long start,
long end) |
protected int |
maximumElementPerInClause(EOEntity entity)
The database specific limit, or or most efficient number, of elements in an IN clause in a statement.
|
String |
migrationTableName()
Returns the name of the table to use for database migrations.
|
static ERXSQLHelper |
newSQLHelper(EOAdaptor adaptor) |
static ERXSQLHelper |
newSQLHelper(EOAdaptorChannel adaptorChannel) |
static ERXSQLHelper |
newSQLHelper(EODatabaseChannel databaseChannel) |
static ERXSQLHelper |
newSQLHelper(EODatabaseContext databaseContext) |
static ERXSQLHelper |
newSQLHelper(EOEditingContext ec,
EOEntity entity) |
static ERXSQLHelper |
newSQLHelper(EOEditingContext ec,
EOModel model) |
static ERXSQLHelper |
newSQLHelper(EOEditingContext ec,
String modelName) |
static ERXSQLHelper |
newSQLHelper(EOEntity entity) |
static ERXSQLHelper |
newSQLHelper(EOModel model) |
static ERXSQLHelper |
newSQLHelper(EOSQLExpression expression) |
static ERXSQLHelper |
newSQLHelper(JDBCAdaptor adaptor) |
static ERXSQLHelper |
newSQLHelper(JDBCPlugIn plugin) |
static ERXSQLHelper |
newSQLHelper(String databaseProductName) |
void |
prepareConnectionForSchemaChange(EOEditingContext ec,
EOModel model) |
String |
quoteColumnName(String columnName) |
String |
readFormatForAggregateFunction(String functionName,
String columnName,
String aggregateName)
Returns the attribute read format for an aggregate function for a
particular column with a name.
|
String |
readFormatForAggregateFunction(String functionName,
String columnName,
String aggregateName,
boolean usesDistinct)
Returns the attribute read format for an aggregate function for a
particular column with a name.
|
boolean |
reassignExternalTypeForValueTypeOverride(EOAttribute attribute) |
void |
removeSelectFromExpression(EOAttribute attribute,
EOSQLExpression sqlExpression)
Removes an attribute from the select list.
|
void |
restoreConnectionSettingsAfterSchemaChange(EOEditingContext ec,
EOModel model) |
int |
rowCountForFetchSpecification(EOEditingContext ec,
EOFetchSpecification spec)
Returns the number of rows the supplied EOFetchSpecification would
return.
|
boolean |
shouldExecute(String sql) |
boolean |
shouldPerformDistinctInMemory(EOFetchSpecification fetchSpecification)
Returns whether or not this database should perform the distinct portion of the
given fetch spec in memory or not.
|
NSArray<String> |
splitSQLStatements(String sql)
Splits semicolon-separate sql statements into an array of strings
|
NSArray<String> |
splitSQLStatementsFromFile(File f)
Splits the SQL statements from the given file.
|
NSArray<String> |
splitSQLStatementsFromInputStream(InputStream is)
Splits the SQL statements from the given input stream
|
EOSQLExpression |
sqlExpressionForFetchSpecification(EOEditingContext ec,
EOFetchSpecification spec,
long start,
long end)
Creates the SQL which is used by the provided EOFetchSpecification,
limited by the given range.
|
EOSQLExpression |
sqlExpressionForFetchSpecification(EOEditingContext ec,
EOFetchSpecification spec,
long start,
long end,
NSArray<EOAttribute> attributes)
Creates the SQL which is used by the provided EOFetchSpecification,
limited by the given range.
|
protected String |
sqlForCountDistinct(EOEntity entity)
Returns the SQL to count the distinct number of rows.
|
String |
sqlForCreateIndex(String indexName,
String tableName,
ERXSQLHelper.ColumnIndex... columnIndexes)
Returns the SQL expression for creating an index on the given set
of columns
|
String |
sqlForCreateIndex(String indexName,
String tableName,
String... columnNames)
Returns the SQL expression for creating an index on the given set
of columns
|
String |
sqlForCreateUniqueIndex(String indexName,
String tableName,
ERXSQLHelper.ColumnIndex... columnIndexes)
Returns the SQL expression for creating a unique index on the given set
of columns
|
String |
sqlForCreateUniqueIndex(String indexName,
String tableName,
String... columnNames)
Returns the SQL expression for creating a unique index on the given set
of columns
|
String |
sqlForFullTextQuery(ERXFullTextQualifier qualifier,
EOSQLExpression expression)
Returns the SQL expression for a full text search query.
|
protected String |
sqlForGetNextValFromSequencedNamed(String sequenceName)
Returns the SQL required to select the next value from the given sequence.
|
String |
sqlForRegularExpressionQuery(String key,
String value)
Returns the SQL expression for a regular expression query.
|
protected String |
sqlForSubquery(String subquery,
String alias)
Returns the syntax for using the given query as an aliased subquery in a from-clause.
|
String |
sqlWhereClauseStringForKey(EOSQLExpression e,
String key,
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.
|
public void prepareConnectionForSchemaChange(EOEditingContext ec, EOModel model)
public void restoreConnectionSettingsAfterSchemaChange(EOEditingContext ec, EOModel model)
public boolean shouldExecute(String sql)
public String createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray<EOEntity> entities, String modelName, NSDictionary optionsCreate)
entities
- a NSArray containing the entities for which create table
statements should be generated or null
if all entities
in the model should be used.modelName
- the name of the EOModeloptionsCreate
- String
containing SQL statements to create
tablespublic String createSchemaSQLForEntitiesInModelAndOptions(NSArray<EOEntity> entities, EOModel model, NSDictionary optionsCreate)
entities
- a NSArray containing the entities for which create table
statements should be generated or null if all entities in the
model should be used.model
- the EOModeloptionsCreate
- a NSDictionary containing the different optionsString
containing SQL statements to create
tablespublic String createSchemaSQLForEntitiesWithOptions(NSArray<EOEntity> entities, EODatabaseContext databaseContext, NSDictionary<String,String> optionsCreate)
entities
- the entities to create sql fordatabaseContext
- the database context to useoptionsCreate
- the options (@see
createSchemaSQLForEntitiesInModelWithNameAndOptions)public String createDependentSchemaSQLForEntities(NSArray<EOEntity> entities, EOAdaptor adaptor)
entities
- the entities to generate foradaptor
- the adaptor to usepublic String createSchemaSQLForEntitiesWithOptions(NSArray<EOEntity> entities, EOAdaptor adaptor, NSDictionary<String,String> optionsDictionary)
entities
- the entities to create sql foradaptor
- the adaptor to useoptionsDictionary
- the options (@see
createSchemaSQLForEntitiesInModelWithNameAndOptions)public String createSchemaSQLForEntitiesInModelWithName(NSArray<EOEntity> entities, String modelName)
entities
- a NSArray containing the entities for which create table
statements should be generated or null if all entities in the
model should be used.modelName
- the name of the EOModelString
containing SQL statements to create
tablespublic String createSchemaSQLForEntitiesInModel(NSArray<EOEntity> entities, EOModel model)
entities
- a NSArray containing the entities for which create table
statements should be generated or null if all entities in the
model should be used.model
- the EOModelString
containing SQL statements to create
tablespublic NSMutableDictionary<String,String> defaultOptionDictionary(boolean create, boolean drop)
create
- add create statementsdrop
- add drop statements
This method uses the following defaults options:
YES
and NO
String
containing SQL statements to create
tablespublic String createSchemaSQLForEntitiesInDatabaseContext(NSArray<EOEntity> entities, EODatabaseContext databaseContext, boolean create, boolean drop)
entities
- a NSArray containing the entities for which create table
statements should be generated or null if all entities in the
model should be used.databaseContext
- the databaseContextcreate
- if true, tables and keys are createddrop
- if true, tables and keys are droppedString
containing SQL statements to create
tablespublic String createIndexSQLForEntities(NSArray<EOEntity> entities, NSArray<String> externalTypesToIgnore)
public NSArray<EOAttribute> attributesToFetchForEntity(EOFetchSpecification fetchSpec, EOEntity entity)
fetchSpec
- the fetch specentity
- the entity (which should match fetchSpec.entityName())public EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end)
ec
- the EOEditingContextspec
- the EOFetchSpecification in questionstart
- start of rows to fetchend
- end of rows to fetch (-1 if not used)public String customQueryExpressionHintAsString(Object hint)
hint
- the hint to convert to a Stringpublic EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end, NSArray<EOAttribute> attributes)
ec
- the EOEditingContextspec
- the EOFetchSpecification in questionstart
- start of rows to fetchend
- end of rows to fetch (-1 if not used)attributes
- the attributes to fetch from the given entitypublic String limitExpressionForSQL(EOSQLExpression expression, EOFetchSpecification fetchSpecification, String sql, long start, long end)
public void removeSelectFromExpression(EOAttribute attribute, EOSQLExpression sqlExpression)
attribute
- the attribute to remove from the select listsqlExpression
- the expression to remove frompublic String readFormatForAggregateFunction(String functionName, String columnName, String aggregateName)
functionName
- the aggregate function to generatecolumnName
- the column name to aggregate onaggregateName
- the name to assign to the aggregate resultpublic String readFormatForAggregateFunction(String functionName, String columnName, String aggregateName, boolean usesDistinct)
functionName
- the aggregate function to generatecolumnName
- the column name to aggregate onaggregateName
- the name to assign to the aggregate resultusesDistinct
- true
if function should be used on distinct valuespublic void appendItemToListString(String itemString, StringBuffer listString)
itemString
- the item to appendlistString
- the list bufferpublic void addGroupByClauseToExpression(EOEditingContext editingContext, EOFetchSpecification fetchSpec, EOSQLExpression expression)
editingContext
- the editing context to lookup entities withfetchSpec
- the fetch spec to retrieve attributes fromexpression
- the sql expression to add a "group by" clause topublic int _orderByIndex(EOSQLExpression expression)
expression
- the expression to look intopublic int _groupByOrHavingIndex(EOSQLExpression expression)
expression
- the expression to look intopublic void addGroupByClauseToExpression(NSArray<EOAttribute> attributes, EOSQLExpression expression)
attributes
- the list of attributes to group byexpression
- the sql expression to add a "group by" clause topublic void addHavingCountClauseToExpression(NSSelector selector, int value, EOSQLExpression expression)
selector
- the comparison selector -- just like EOKeyValueQualifiervalue
- the value to compare againstexpression
- the expression to modifypublic String sqlForRegularExpressionQuery(String key, String value)
key
- value
- public String sqlForFullTextQuery(ERXFullTextQualifier qualifier, EOSQLExpression expression)
qualifier
- the full text qualifierexpression
- the EOSQLExpression contextpublic String sqlForCreateUniqueIndex(String indexName, String tableName, String... columnNames)
indexName
- the name of the index to createtableName
- the name of the containing tablecolumnNames
- the list of column names to index onpublic String sqlForCreateUniqueIndex(String indexName, String tableName, ERXSQLHelper.ColumnIndex... columnIndexes)
indexName
- the name of the index to createtableName
- the name of the containing tablecolumnIndexes
- the list of columns to index onpublic String sqlForCreateIndex(String indexName, String tableName, String... columnNames)
indexName
- the name of the index to createtableName
- the name of the containing tablecolumnNames
- the list of column names to index onprotected ERXSQLHelper.ColumnIndex[] columnIndexesFromColumnNames(String... columnNames)
public String sqlForCreateIndex(String indexName, String tableName, ERXSQLHelper.ColumnIndex... columnIndexes)
indexName
- the name of the index to createtableName
- the name of the containing tablecolumnIndexes
- the list of columns to index onpublic int varcharLargeJDBCType()
public int varcharLargeColumnWidth()
public String migrationTableName()
public int jdbcTypeForCustomType(int jdbcType)
jdbcType
- the ERXSQLHelper custom typepublic String externalTypeForJDBCType(JDBCAdaptor adaptor, int jdbcType)
adaptor
- the adaptor to retrieve an external type forjdbcType
- the JDBC type numberpublic int rowCountForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec)
ec
- the EOEditingContextspec
- the EOFetchSpecification in questionprotected String sqlForCountDistinct(EOEntity entity)
Concrete classes may override this implementation to add support for composite primary keys according to their database specific SQL syntax.
entity
- the base entity used in this queryprotected String sqlForSubquery(String subquery, String alias)
subquery
- the subquery to wrapalias
- the alias to useprotected String sqlForGetNextValFromSequencedNamed(String sequenceName)
sequenceName
- the name of the sequencepublic Number getNextValFromSequenceNamed(EOEditingContext ec, String modelName, String sequenceName)
ec
- editing contextmodelName
- name of the model which connects to the database that has the
sequence in itsequenceName
- name of the sequencepublic String sqlWhereClauseStringForKey(EOSQLExpression e, String key, NSArray valueArray)
e
- the SQL expressionkey
- the name of the keyvalueArray
- an array of values to generate an "in" clause forprotected int maximumElementPerInClause(EOEntity entity)
entity
- EOEntity that can be used to fine-tune the resultprotected String formatValueForAttribute(EOSQLExpression expression, Object value, EOAttribute attribute, String key)
public NSArray<String> splitSQLStatements(String sql)
sql
- a multi-line sql statementpublic NSArray<String> splitSQLStatementsFromInputStream(InputStream is) throws IOException
is
- the input stream to read fromIOException
- if there is a problem reading the streampublic NSArray<String> splitSQLStatementsFromFile(File f) throws IOException
f
- the file to read fromIOException
- if there is a problem reading the streamprotected char commandSeparatorChar()
protected String commandSeparatorString()
protected Pattern commentPattern()
public NSMutableArray<String> columnNamesFromColumnIndexes(ERXSQLHelper.ColumnIndex... columnIndexes)
public boolean reassignExternalTypeForValueTypeOverride(EOAttribute attribute)
protected boolean canReliablyPerformDistinctWithSortOrderings()
public boolean shouldPerformDistinctInMemory(EOFetchSpecification fetchSpecification)
fetchSpecification
- the fetch spec to checkpublic boolean handleDatabaseException(EODatabaseContext databaseContext, Throwable throwable)
databaseContext
- throwable
- public static ERXSQLHelper newSQLHelper(EOSQLExpression expression)
public static ERXSQLHelper newSQLHelper(EOEditingContext ec, String modelName)
public static ERXSQLHelper newSQLHelper(EOEditingContext ec, EOEntity entity)
public static ERXSQLHelper newSQLHelper(EOEditingContext ec, EOModel model)
public static ERXSQLHelper newSQLHelper(EODatabaseContext databaseContext)
public static ERXSQLHelper newSQLHelper(EODatabaseChannel databaseChannel)
public static ERXSQLHelper newSQLHelper(EOAdaptor adaptor)
public static ERXSQLHelper newSQLHelper(EOAdaptorChannel adaptorChannel)
public static ERXSQLHelper newSQLHelper(JDBCAdaptor adaptor)
public static ERXSQLHelper newSQLHelper(JDBCPlugIn plugin)
public static ERXSQLHelper newSQLHelper(EOEntity entity)
public static ERXSQLHelper newSQLHelper(EOModel model)
public static ERXSQLHelper newSQLHelper(String databaseProductName)
Copyright © 2002 – 2024 Project Wonder.