Project Wonder 5.0.0.8654

er.extensions.eof
Class ERXEOAccessUtilities

java.lang.Object
  extended by er.extensions.eof.ERXEOAccessUtilities

public class ERXEOAccessUtilities
extends Object

Collection of EOAccess related utilities.


Nested Class Summary
static class ERXEOAccessUtilities.ChannelAction
          Deals with the nitty-gritty of direct row manipulation by correctly opening, closing, locking and unlocking the needed EOF objects for direct row manipulation.
 
Field Summary
static Logger log
          logging support
 
Constructor Summary
ERXEOAccessUtilities()
           
 
Method Summary
static NSArray attributePathForKeyPath(EOEntity entity, String keyPath)
          Creates an array of relationships and attributes from the given keypath to give to the EOSQLExpression method sqlStringForAttributePath.
static EOAttribute attributeWithColumnNameFromEntity(String columnName, EOEntity entity)
           
static void batchFetchRelationship(EODatabaseContext databaseContext, EORelationship relationship, NSArray objects, EOEditingContext editingContext, boolean skipFaultedRelationships)
          Batch fetch a relationship, optionally skipping any relationship that has already faulted in its to-many relationship.
static void batchFetchRelationship(EODatabaseContext databaseContext, String entityName, String relationshipName, NSArray objects, EOEditingContext editingContext, boolean skipFaultedRelationships)
          Batch fetch a relationship, optionally skipping any relationship that has already faulted in its to-many relationship.
static NSArray classPropertiesNotInParent(EOEntity entity, boolean includeAttributes, boolean includeToOneRelationships, boolean includeToManyRelationships)
           
static boolean closeDatabaseConnections(EOObjectStoreCoordinator osc)
          Closes the (JDBC) Connection from all database channels for the specified EOObjectStoreCoordinator
static EOAttribute createAggregateAttribute(EOEditingContext ec, String function, String attributeName, String entityName)
          Creates an aggregate integer attribute for a given function name.
static EOAttribute createAggregateAttribute(EOEditingContext ec, String function, String attributeName, String entityName, Class valueClass, String valueType)
          Creates an aggregate attribute for a given function name.
static EOAttribute createAggregateAttribute(EOEditingContext ec, String function, String attributeName, String entityName, Class valueClass, String valueType, String aggregateName)
          Creates an aggregate attribute for a given function name.
static EOAttribute createAggregateAttribute(EOEditingContext ec, String function, String attributeName, String entityName, Class valueClass, String valueType, String aggregateName, String entityTableAlias)
          Creates an aggregate attribute for a given function name.
static EORelationship createFlattenedRelationship(String relationshipName, String sourceEntityName, String definition, int deleteRule, boolean isMandatory, boolean isClassProperty)
          Programatically adds a flattened relationship to an entity at runtime.
static String createIndexSQLForEntities(NSArray entities)
          Deprecated.  
static String createIndexSQLForEntities(NSArray entities, NSArray externalTypesToIgnore)
          Deprecated.  
static String createIndexSQLForEntitiesForOracle(NSArray entities)
          Deprecated.  
static String createLogString(EOAdaptorChannel channel, EOSQLExpression expression, long millisecondsNeeded)
           
static EORelationship createRelationship(String relationshipName, String sourceEntityName, String sourceAttributeName, String destinationEntityName, String destinationAttributeName, boolean toMany, int deleteRule, boolean isMandatory, boolean isClassProperty, boolean shouldPropagatePrimaryKey)
          Programatically adds a toOne or toMany relationship to an entity at runtime.
static String createSchemaSQLForEntitiesInDatabaseContext(NSArray entities, EODatabaseContext databaseContext, boolean create, boolean drop)
          Deprecated.  
static String createSchemaSQLForEntitiesInModelWithName(NSArray entities, String modelName)
          Deprecated.  
static String createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray entities, String modelName, NSDictionary optionsCreate)
          Deprecated.  
static String createSchemaSQLForEntitiesInModelWithNameAndOptionsForOracle9(NSArray entities, String modelName, NSDictionary optionsCreate)
          oracle 9 has a maximum length of 30 characters for table names, column names and constraint names Foreign key constraint names are defined like this from the plugin:

TABLENAME_FOEREIGNKEYNAME_FK

The whole statement looks like this:

ALTER TABLE [TABLENAME] ADD CONSTRAINT [CONSTRAINTNAME] FOREIGN KEY ([FK]) REFERENCES [DESTINATION_TABLE] ([PK]) DEFERRABLE INITIALLY DEFERRED THIS means that the tablename and the columnname together cannot be longer than 26 characters.

This method checks each foreign key constraint name and if it is longer than 30 characters its replaced with a unique name.
static String createSchemaSQLForEntitiesWithOptions(NSArray entities, EODatabaseContext databaseContext, NSDictionary optionsCreate)
          Deprecated.  
static EODatabaseContext databaseContextForEntityNamed(EOObjectStoreCoordinator osc, String entityName)
          Returns the database context for the given entity in the given EOObjectStoreCoordinator
static EODatabaseContext databaseContextForObject(EOEnterpriseObject eo)
          Returns the database context for an EO.
static int deleteRowsDescribedByQualifier(EOEditingContext ec, String entityName, EOQualifier qualifier)
          Deletes rows described by the qualifier.
static EOEntity destinationEntityForKeyPath(EOEntity entity, String keyPath)
           
static EOEntity entityForEo(EOEnterpriseObject eo)
          Returns the EOEntity for the provided EOEnterpriseObject if one exists
static EOEntity entityMatchingString(EOEditingContext ec, String string)
          Finds an entity that is contained in a string.
static EOEntity entityNamed(EOEditingContext ec, String entityName)
          Similar to the helper in EUUtilities, but allows for null editingContext.
static boolean entityUsesSeparateTable(EOEntity entity)
           
static EOEntity entityUsingTable(EOEditingContext ec, String tableName)
          Finds an entity that is associated with the table name.
static boolean entityWithNamedIsShared(EOEditingContext ec, String entityName)
          Method used to determine if a given entity is a shared entity.
static void evaluateSQLWithEntity(EOEditingContext ec, EOEntity entity, String exp)
          Utility method used to execute arbitrary SQL.
static void evaluateSQLWithEntityNamed(EOEditingContext ec, String entityName, String exp)
          Utility method used to execute arbitrary SQL.
static NSArray externalNamesForEntity(EOEntity entity, boolean includeParentEntities)
           
static NSArray externalNamesForEntityNamed(String entityName, boolean includeParentEntities)
           
static Number getNextValFromSequenceNamed(EOEditingContext ec, String modelName, String sequenceName)
          Deprecated.  
static String guessPluginName(EOModel model)
          Tries to get the plugin name for a JDBC based model.
static String guessPluginNameForConnectionDictionary(NSDictionary connectionDictionary)
          Tries to get the plugin name for a connection dictionary.
static int insertRow(EOEditingContext ec, String entityName, NSDictionary newValues)
          Insert row described dictionary.
static int insertRows(EOEditingContext ec, String entityName, List<NSDictionary> newValues)
          Insert rows described the array of dictionaries.
static boolean isOptimisticLockingFailure(EOGeneralAdaptorException e)
          Returns true if the exception is an optimistic locking exception.
static EORelationship lastRelationship(EORelationship relationship)
          Crude hack to get at the end of a relationship path.
static EOFetchSpecification localizeFetchSpecification(EOEditingContext ec, EOFetchSpecification fetchSpecification)
          Returns a new fetch spec by morphing sort oderings containing the keys foo.name returning foo.name_de where appropriate.
static void logExpression(EOAdaptorChannel channel, EOSQLExpression expression, long startTime)
           
static void makeEditableSharedEntityNamed(String entityName)
          Utility method to make a shared entity editable.
static EOModelGroup modelGroup(EOEditingContext ec)
          Similar to the helper in EUUtilities, but allows for null editingContext.
static NSDictionary primaryKeyDictionaryForEntity(EOEditingContext ec, String entityName)
          Utility method to generate a new primary key dictionary using the adaptor for a given entity.
static NSArray primaryKeysForNewRows(EOEditingContext ec, String entityName, int count)
          Creates count new primary keys for the entity.
static NSArray primaryKeysForObjects(NSArray eos)
          Creates an array containing all of the primary keys of the given objects.
static EOQualifier qualifierFromAttributes(NSArray attributes, NSDictionary values)
          Creates an AND qualifier of EOKeyValueQualifiers for every keypath in the given array of attributes.
static NSArray rawRowsForSQLExpression(EOEditingContext ec, EOModel model, EOSQLExpression expression, NSArray<EOAttribute> attributes)
          Returns the raw rows for the given EOSQLExpression.
static NSArray<NSDictionary> rawRowsForSQLExpression(EOEditingContext ec, String modelName, EOSQLExpression expression)
          Returns the raw rows for the given EOSQLExpression.
static void reapplyChanges(EOEnterpriseObject eo, EOGeneralAdaptorException e)
          Method used to apply a set of changes to a re-fetched eo.
static EOEnterpriseObject refetchFailedObject(EOEditingContext ec, EOGeneralAdaptorException e)
           
static NSArray relationshipsForAttribute(EOEntity entity, EOAttribute attrib)
          Filters a list of relationships for only the ones that have a given EOAttribute as a source attribute.
static EOEntity rootEntityForEntity(EOEntity entity)
           
static EOEntity rootEntityForEntityNamed(String entityName)
           
static int rowCountForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec)
          Deprecated.  
static NSArray snapshotsForObjectsFromRelationshipNamed(NSArray eos, String relKey)
          Given an array of EOs, returns snapshot dictionaries for the given related objects.
static EOAttribute sourceAttributeForRelationship(EOEntity entity, String relationshipName)
          Returns the source attribute for the relationship named relationshipName on entity.
static EOAttribute sourceAttributeForRelationship(EORelationship relationship)
          Returns the source attribute for the relationship.
static String sourceColumnForRelationship(EOEntity entity, String relationshipName)
          Returns the external column name for the source attribute for the relationship named relationshipName on entity.
static String sourceColumnForRelationship(EORelationship relationship)
          Returns the external column name for the source attribute for the relationship named relationshipName on entity.
static EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end)
          Deprecated.  
static String sqlForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec)
          Creates the SQL which is used by the provides EOFetchSpecification.
static String sqlWhereClauseStringForKey(EOSQLExpression e, String key, NSArray valueArray)
          Deprecated.  
static int updateRowsDescribedByQualifier(EOEditingContext ec, String entityName, EOQualifier qualifier, NSDictionary newValues)
          Updates rows described by the qualifier.
static NSSet verifyAllSnapshots()
          In a multi-OSC or multi-instance scenario, when there are bugs, it is possible for the snapshots to become out of sync with the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final Logger log
logging support

Constructor Detail

ERXEOAccessUtilities

public ERXEOAccessUtilities()
Method Detail

entityMatchingString

public static EOEntity entityMatchingString(EOEditingContext ec,
                                            String string)
Finds an entity that is contained in a string. This is used a lot in DirectToWeb. Example: "ListAllStudios"=>Studio

Parameters:
ec - editing context
string - string to look into
Returns:
found entity or null

entityUsingTable

public static EOEntity entityUsingTable(EOEditingContext ec,
                                        String tableName)
Finds an entity that is associated with the table name. When inheritance is used, will return the least derived entity using that table. This can be used to deal with database exceptions where you only have the table name to go on. As multiple entities can map to a single table, the results of this method are inexact.

Parameters:
ec - editing context
tableName - table (external) name to find an entity for
Returns:
found entity or null

entityWithNamedIsShared

public static boolean entityWithNamedIsShared(EOEditingContext ec,
                                              String entityName)
Method used to determine if a given entity is a shared entity.

Parameters:
ec - editing context
entityName - name of the entity
Returns:
if the entity is a shared entity

getNextValFromSequenceNamed

public static Number getNextValFromSequenceNamed(EOEditingContext ec,
                                                 String modelName,
                                                 String sequenceName)
Deprecated. 

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

evaluateSQLWithEntityNamed

public static void evaluateSQLWithEntityNamed(EOEditingContext ec,
                                              String entityName,
                                              String exp)
Utility method used to execute arbitrary SQL. This has the advantage over the EOUtilities rawRowsForSQL in that it can be used with other statements besides just SELECT without throwing exceptions.

Parameters:
ec - editing context that determines which model group and database context to use.
entityName - name of an entity in the model connected to the database you wish to execute SQL against
exp - SQL expression

evaluateSQLWithEntity

public static void evaluateSQLWithEntity(EOEditingContext ec,
                                         EOEntity entity,
                                         String exp)
Utility method used to execute arbitrary SQL. This has the advantage over the EOUtilities rawRowsForSQL in that it can be used with other statements besides just SELECT without throwing exceptions.

Parameters:
ec - editing context that determines which model group and database context to use.
entity - an entity in the model connected to the database you wish to execute SQL against
exp - SQL expression

sqlForFetchSpecification

public static String sqlForFetchSpecification(EOEditingContext ec,
                                              EOFetchSpecification spec)
Creates the SQL which is used by the provides EOFetchSpecification.

Parameters:
ec - the EOEditingContext
spec - the EOFetchSpecification in question
Returns:
the SQL which the EOFetchSpecification would use

rawRowsForSQLExpression

public static NSArray<NSDictionary> rawRowsForSQLExpression(EOEditingContext ec,
                                                            String modelName,
                                                            EOSQLExpression expression)
Returns the raw rows for the given EOSQLExpression. When possible, you should use the variant of this method that requires you to pass in the array of EOAttributes you are fetching. If you do not pass in attributes, this will use channel.describeResults(), which can produce attributes that may not be able to be faulted back into EO's because of case mismatches.

Parameters:
ec - the EOEditingContext
modelName - the name of the model in question
expression - the EOSQLExpression in question
Returns:
array of dictionaries

rawRowsForSQLExpression

public static NSArray rawRowsForSQLExpression(EOEditingContext ec,
                                              EOModel model,
                                              EOSQLExpression expression,
                                              NSArray<EOAttribute> attributes)
Returns the raw rows for the given EOSQLExpression.

Parameters:
ec - the EOEditingContext
model - the model in question
expression - the EOSQLExpression to fetch with
attributes - the attributes to fetch
Returns:
array of dictionaries

sqlExpressionForFetchSpecification

public static EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec,
                                                                 EOFetchSpecification spec,
                                                                 long start,
                                                                 long end)
Deprecated. 

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

rowCountForFetchSpecification

public static int rowCountForFetchSpecification(EOEditingContext ec,
                                                EOFetchSpecification spec)
Deprecated. 

Returns the number of rows the supplied EOFetchSpecification would return.

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

modelGroup

public static EOModelGroup modelGroup(EOEditingContext ec)
Similar to the helper in EUUtilities, but allows for null editingContext. If ec is null, it will try to get at the session via thread storage and use its defaultEditingContext. This is here now so we can remove the delgate in ERXApplication.

Parameters:
ec - editing context used to locate the model group (can be null)

entityNamed

public static EOEntity entityNamed(EOEditingContext ec,
                                   String entityName)
Similar to the helper in EUUtilities, but allows for null editingContext.

Parameters:
ec - editing context used to locate the model group (can be null)
entityName - entity name

createAggregateAttribute

public static EOAttribute createAggregateAttribute(EOEditingContext ec,
                                                   String function,
                                                   String attributeName,
                                                   String entityName)
Creates an aggregate integer attribute for a given function name. These can then be used to query on when using raw rows.

Parameters:
ec - editing context used to locate the model group
function - name of the function MAX, MIN, etc
attributeName - name of the attribute
entityName - name of the entity
Returns:
aggregate function attribute

createAggregateAttribute

public static EOAttribute createAggregateAttribute(EOEditingContext ec,
                                                   String function,
                                                   String attributeName,
                                                   String entityName,
                                                   Class valueClass,
                                                   String valueType)
Creates an aggregate attribute for a given function name. These can then be used to query on when using raw rows.

Parameters:
ec - editing context used to locate the model group
function - name of the function MAX, MIN, etc
attributeName - name of the attribute
entityName - name of the entity
valueClass - the java class of this attribute's values
valueType - the EOAttribute value type
Returns:
aggregate function attribute

createAggregateAttribute

public static EOAttribute createAggregateAttribute(EOEditingContext ec,
                                                   String function,
                                                   String attributeName,
                                                   String entityName,
                                                   Class valueClass,
                                                   String valueType,
                                                   String aggregateName)
Creates an aggregate attribute for a given function name. These can then be used to query on when using raw rows.

Parameters:
ec - editing context used to locate the model group
function - name of the function MAX, MIN, etc
attributeName - name of the attribute
entityName - name of the entity
aggregateName - the name to assign to the aggregate column in the query
valueClass - the java class of this attribute's values
valueType - the EOAttribute value type
Returns:
aggregate function attribute

createAggregateAttribute

public static EOAttribute createAggregateAttribute(EOEditingContext ec,
                                                   String function,
                                                   String attributeName,
                                                   String entityName,
                                                   Class valueClass,
                                                   String valueType,
                                                   String aggregateName,
                                                   String entityTableAlias)
Creates an aggregate attribute for a given function name. These can then be used to query on when using raw rows.

Parameters:
ec - editing context used to locate the model group
function - name of the function MAX, MIN, etc
attributeName - name of the attribute
entityName - name of the entity
aggregateName - the name to assign to the aggregate column in the query
valueClass - the java class of this attribute's values
valueType - the EOAttribute value type
entityTableAlias - the "t0"-style name of the attribute in this query (or null for "t0")
Returns:
aggregate function attribute

createSchemaSQLForEntitiesInModelWithNameAndOptionsForOracle9

public static String createSchemaSQLForEntitiesInModelWithNameAndOptionsForOracle9(NSArray entities,
                                                                                   String modelName,
                                                                                   NSDictionary optionsCreate)
oracle 9 has a maximum length of 30 characters for table names, column names and constraint names Foreign key constraint names are defined like this from the plugin:

TABLENAME_FOEREIGNKEYNAME_FK

The whole statement looks like this:

ALTER TABLE [TABLENAME] ADD CONSTRAINT [CONSTRAINTNAME] FOREIGN KEY ([FK]) REFERENCES [DESTINATION_TABLE] ([PK]) DEFERRABLE INITIALLY DEFERRED THIS means that the tablename and the columnname together cannot be longer than 26 characters.

This method checks each foreign key constraint name and if it is longer than 30 characters its replaced with a unique name.

See Also:
createSchemaSQLForEntitiesInModelWithNameAndOptions

createSchemaSQLForEntitiesInModelWithNameAndOptions

public static String createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray entities,
                                                                         String modelName,
                                                                         NSDictionary optionsCreate)
Deprecated. 

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 - a NSDictionary containing the different options. Possible keys are
  • EOSchemaGeneration.DropTablesKey
  • EOSchemaGeneration.DropPrimaryKeySupportKey
  • EOSchemaGeneration.CreateTablesKey
  • EOSchemaGeneration.CreatePrimaryKeySupportKey
  • EOSchemaGeneration.PrimaryKeyConstraintsKey
  • EOSchemaGeneration.ForeignKeyConstraintsKey
  • EOSchemaGeneration.CreateDatabaseKey
  • EOSchemaGeneration.DropDatabaseKey


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

    createSchemaSQLForEntitiesWithOptions

    public static String createSchemaSQLForEntitiesWithOptions(NSArray entities,
                                                               EODatabaseContext databaseContext,
                                                               NSDictionary optionsCreate)
    Deprecated. 

    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

    createSchemaSQLForEntitiesInModelWithName

    public static String createSchemaSQLForEntitiesInModelWithName(NSArray entities,
                                                                   String modelName)
    Deprecated. 

    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

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


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

    createSchemaSQLForEntitiesInDatabaseContext

    public static String createSchemaSQLForEntitiesInDatabaseContext(NSArray entities,
                                                                     EODatabaseContext databaseContext,
                                                                     boolean create,
                                                                     boolean drop)
    Deprecated. 

    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

    createIndexSQLForEntitiesForOracle

    public static String createIndexSQLForEntitiesForOracle(NSArray entities)
    Deprecated. 


    createIndexSQLForEntities

    public static String createIndexSQLForEntities(NSArray entities)
    Deprecated. 


    createIndexSQLForEntities

    public static String createIndexSQLForEntities(NSArray entities,
                                                   NSArray externalTypesToIgnore)
    Deprecated. 


    entityUsesSeparateTable

    public static boolean entityUsesSeparateTable(EOEntity entity)

    attributeWithColumnNameFromEntity

    public static EOAttribute attributeWithColumnNameFromEntity(String columnName,
                                                                EOEntity entity)

    isOptimisticLockingFailure

    public static boolean isOptimisticLockingFailure(EOGeneralAdaptorException e)
    Returns true if the exception is an optimistic locking exception.

    Parameters:
    e - the exception as recieved from saveChanges()
    Returns:
    true if the error could be handled.

    snapshotsForObjectsFromRelationshipNamed

    public static NSArray snapshotsForObjectsFromRelationshipNamed(NSArray eos,
                                                                   String relKey)
    Given an array of EOs, returns snapshot dictionaries for the given related objects.


    primaryKeyDictionaryForEntity

    public static NSDictionary primaryKeyDictionaryForEntity(EOEditingContext ec,
                                                             String entityName)
    Utility method to generate a new primary key dictionary using the adaptor for a given entity. This is can be handy if you need to have a primary key for an object before it is saved to the database. This method uses the same method that EOF uses by default for generating primary keys. See ERXGeneratesPrimaryKeyInterfacefor more information about using a newly created dictionary as the primary key for an enterprise object.

    Parameters:
    ec - editing context
    entityName - name of the entity to generate the primary key dictionary for.
    Returns:
    a dictionary containing a new primary key for the given entity.

    primaryKeysForObjects

    public static NSArray primaryKeysForObjects(NSArray eos)
    Creates an array containing all of the primary keys of the given objects.

    Parameters:
    eos - array of enterprise objects