Project Wonder 2.0

er.extensions
Class ERXEOAccessUtilities

java.lang.Object
  extended byer.extensions.ERXEOAccessUtilities

public class ERXEOAccessUtilities
extends Object

Collection of EOAccess related utilities.


Field Summary
protected static NSArray entityNames
          Finds an entity that is contained in a string.
static ERXLogger log
          logging support
 
Constructor Summary
ERXEOAccessUtilities()
           
 
Method Summary
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 attribute for a given function name.
static String createSchemaSQLForEntitiesInModelWithName(NSArray entities, String modelName)
          creates SQL to create tables for the specified Entities.
static String createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray entities, String modelName, NSDictionary optionsCreate)
          creates SQL to create tables for the specified Entities.
static EODatabaseContext databaseContextForEntityNamed(EOObjectStoreCoordinator osc, String entityName)
          Returns the database context for the given entity in the given EOObjectStoreCoordinator
static EOEntity destinationEntityForKeyPath(EOEntity entity, String keyPath)
          Returns the last entity for the given key path.
static EOEntity entityForEo(EOEnterpriseObject eo)
          Returns the EOEntity for the provided EOEnterpriseObject if one exists
static EOEntity entityMatchingString(EOEditingContext ec, String string)
           
static EOEntity entityNamed(EOEditingContext ec, String entityName)
          Similar to the helper in EUUtilities, but allows for null editingContext.
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 Number getNextValFromSequenceNamed(EOEditingContext ec, String modelName, String sequenceName)
          Convenience method to get the next unique ID from a sequence.
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 primaryKeysForObjects(NSArray eos)
          Creates an array containing all of the primary keys of the given objects.
static NSArray rawRowsForSQLExpression(EOEditingContext ec, String modelName, EOSQLExpression expression)
          Returns the raw rows for the given EOSQLExpression.
static boolean recoverFromAdaptorException(EOEditingContext editingContext, EOGeneralAdaptorException exception)
          Tries to recover from a EOGeneralAdaptorException.
static int rowCountForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec)
          Returns the number of rows the supplied EOFetchSpecification would return.
static NSArray snapshotsForObjectsFromRelationshipNamed(NSArray eos, String relKey)
          Given an array of EOs, returns snapshot dictionaries for the given related objects.
static 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.
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)
          Creates a where clause string " someKey IN ( someValue1,...)".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final ERXLogger log
logging support


entityNames

protected static NSArray entityNames
Finds an entity that is contained in a string. This is used a lot in DirectToWeb. Example: "ListAllStudios"=>Studio

Constructor Detail

ERXEOAccessUtilities

public ERXEOAccessUtilities()
Method Detail

entityMatchingString

public static EOEntity entityMatchingString(EOEditingContext ec,
                                            String string)

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)
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 rawRowsForSQLExpression(EOEditingContext ec,
                                              String modelName,
                                              EOSQLExpression expression)
Returns the raw rows for the given EOSQLExpression.

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

sqlExpressionForFetchSpecification

public static 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.

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)
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 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

createSchemaSQLForEntitiesInModelWithNameAndOptions

public static String createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray entities,
                                                                         String modelName,
                                                                         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 - a NSDictionary containing the different options. Possible keys are
  1. DropTablesKey
    1. DropPrimaryKeySupportKey
      1. CreateTablesKey
        1. CreatePrimaryKeySupportKey
          1. PrimaryKeyConstraintsKey
            1. ForeignKeyConstraintsKey
              1. CreateDatabaseKey
                1. DropDatabaseKey


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

createSchemaSQLForEntitiesInModelWithName

public static String createSchemaSQLForEntitiesInModelWithName(NSArray entities,
                                                               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

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


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

recoverFromAdaptorException

public static boolean recoverFromAdaptorException(EOEditingContext editingContext,
                                                  EOGeneralAdaptorException exception)
Tries to recover from a EOGeneralAdaptorException.

Parameters:
exception - the exception as recieved from saveChanges()
editingContext - editing context that created the error
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

sqlWhereClauseStringForKey

public static String sqlWhereClauseStringForKey(EOSQLExpression e,
                                                String key,
                                                NSArray valueArray)
Creates a where clause string " someKey IN ( someValue1,...)".


databaseContextForEntityNamed

public static EODatabaseContext databaseContextForEntityNamed(EOObjectStoreCoordinator osc,
                                                              String entityName)
Returns the database context for the given entity in the given EOObjectStoreCoordinator

Parameters:
entityName -
osc -
Returns:

closeDatabaseConnections

public static boolean closeDatabaseConnections(EOObjectStoreCoordinator osc)
Closes the (JDBC) Connection from all database channels for the specified EOObjectStoreCoordinator


destinationEntityForKeyPath

public static EOEntity destinationEntityForKeyPath(EOEntity entity,
                                                   String keyPath)
Returns the last entity for the given key path. If the path is empty or null, returns the given entity.

Parameters:
entity -
keyPath -
Returns:

entityForEo

public static EOEntity entityForEo(EOEnterpriseObject eo)
Returns the EOEntity for the provided EOEnterpriseObject if one exists

Parameters:
eo - the EOEnterpriseObject
Returns:
the EOEntity from the EOEnterpriseObject

classPropertiesNotInParent

public static NSArray classPropertiesNotInParent(EOEntity entity,
                                                 boolean includeAttributes,
                                                 boolean includeToOneRelationships,
                                                 boolean includeToManyRelationships)

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.