Project Wonder 5.0

er.extensions.eof
Class EOEnterpriseObjectClazz<T extends com.webobjects.eocontrol.EOEnterpriseObject>

java.lang.Object
  extended by er.extensions.eof.EOEnterpriseObjectClazz<T>
Direct Known Subclasses:
ERXCustomObject.ERXCustomObjectClazz, ERXGenericRecord.ERXGenericRecordClazz

public class EOEnterpriseObjectClazz<T extends com.webobjects.eocontrol.EOEnterpriseObject>
extends java.lang.Object

Adds class-level inheritance to EOF.

In Java, static methods are similar to class methods in Objective-C, but one cannot use static methods in interfaces and static methods cannot be overridden by a subclass. Using the clazz pattern removes those limitations.

Instead of using a static method, we can use a static inner class (a clazz) instead. This allows for the methods on the clazz to be available statically to the class. The advantage is that static utility methods don't need to be generated for every subclass of an EOEnterpriseObject. It is generally sufficient to simply use the utility methods available on the EOEnterpriseObjectClazz.

Every subclass of this class will get their own "ClazzObject" instance, so it's OK to store things which might be different in superclasses. That is, the "User"'s implementation can override the "Person"'s and because Person.clazz() will get it's own instance, it will do only "Person" things.

Use subclasses of EOEnterpriseObjectClazz as inner classes in your EO subclasses to work around the missing class object inheritance of java. They must be named XXX.XXXClazz to work.

The methods from EOUtilities are mirrored here so you don't have to import EOAccess in your subclasses, which is not legal for client-side classes. The implementation for a client-side class could then be easily switched to use the server-side EOUtilites implementation.


Nested Class Summary
static interface EOEnterpriseObjectClazz.ClazzFactory
          Provides a hook to control how a clazz object is chosen from a given entity.
static class EOEnterpriseObjectClazz.DefaultClazzFactory
          Default factory implementation.
 
Field Summary
static org.apache.log4j.Logger log
          logging support
 
Constructor Summary
EOEnterpriseObjectClazz()
          Default public constructor.
EOEnterpriseObjectClazz(java.lang.String entityName)
          Constructor that also supplies an entity name.
 
Method Summary
 com.webobjects.foundation.NSArray<T> allObjects(com.webobjects.eocontrol.EOEditingContext ec)
          Gets all of the objects for the clazz's entity.
 com.webobjects.eocontrol.EOClassDescription classDescription()
          Returns the class description for the entity.
static EOEnterpriseObjectClazz clazzForEntityNamed(java.lang.String entityName)
          Method used to get a clazz object for a given entity name.
 T createAndInsertObject(com.webobjects.eocontrol.EOEditingContext ec)
          Creates and inserts an object of the type of the clazz into the given editing context.
 ERXFetchSpecification<T> createFetchSpecification(com.webobjects.eocontrol.EOQualifier qualifier, com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOSortOrdering> sortings)
          Creates a fetch spec for the entity.
protected  void discoverEntityName()
           
 com.webobjects.eoaccess.EOEntity entity()
          Gets the entity corresponding to the entity name of the clazz.
 com.webobjects.eoaccess.EOEntity entity(com.webobjects.eocontrol.EOEditingContext ec)
          Gets the entity corresponding to the entity name of the clazz.
 java.lang.String entityName()
          Gets the entity name of the clazz.
protected  java.lang.String entityNameFromRawRow(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.foundation.NSDictionary dict)
          Utility method to get the entity name from a raw row dictionary, taking subclasses and restricting qualifiers into account.
static EOEnterpriseObjectClazz.ClazzFactory factory()
           
 com.webobjects.foundation.NSArray<T> faultsFromRawRows(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.foundation.NSArray nsarray)
          Constructs an array of faults for a given array of primary keys in a given editing context for the clazz's entity.
 com.webobjects.foundation.NSArray<T> faultsMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOQualifier eoqualifier)
          Fetches an array of faults matching a given qualifier.
 com.webobjects.foundation.NSArray<T> faultsMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOQualifier eoqualifier, com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOSortOrdering> sortOrderings)
          Fetches an array of faults matching a given qualifier and sorted by an array of sort orderings.
 com.webobjects.foundation.NSArray<T> faultsMatchingValues(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.foundation.NSDictionary nsdictionary, com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOSortOrdering> sortOrderings)
          Fetches an array of faults for a given set of criteria.
 com.webobjects.eocontrol.EOFetchSpecification fetchSpecificationNamed(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String name)
          Gets a fetch specification for a given name.
 com.webobjects.eocontrol.EOFetchSpecification fetchSpecificationNamed(java.lang.String name)
          Gets a fetch specification for a given name.
 com.webobjects.foundation.NSArray<T> filteredArray(com.webobjects.foundation.NSArray<T> array, com.webobjects.eocontrol.EOFetchSpecification spec, com.webobjects.foundation.NSDictionary bindings)
          Filters an array with a given fetch spec.
 EOEnterpriseObjectClazz init(java.lang.String entityName)
          Convenience init so you can chain constructor calls:
protected  void initialize()
          Called by the constructor.
 com.webobjects.eocontrol.EOArrayDataSource newArrayDataSource(com.webobjects.eocontrol.EOEditingContext ec)
          Utility to return a new array datasource
 com.webobjects.eoaccess.EODatabaseDataSource newDatabaseDataSource(com.webobjects.eocontrol.EOEditingContext ec)
          Utility to return a new database datasource
 com.webobjects.foundation.NSArray newPrimaryKeys(com.webobjects.eocontrol.EOEditingContext ec, int i)
          Generates an array of primary key values for the clazz's entity.
protected static com.webobjects.eoaccess.EOAttribute objectCountAttribute()
          Creates and caches an eo attribute that can be used to return the number of objects that a given fetch specification will return.
protected static com.webobjects.eoaccess.EOAttribute objectCountUniqueAttribute(com.webobjects.eoaccess.EOAttribute foo)
           
 java.lang.Number objectCountWithFetchSpecificationAndBindings(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String fetchSpecName, com.webobjects.foundation.NSDictionary bindings)
          Find the number of objects matching the given fetch specification and bindings for the clazz's entity name.
 java.lang.Number objectCountWithQualifier(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOQualifier qualifier)
          Returns the number of objects matching the given qualifier for the clazz's entity name.
 T objectFromRawRow(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.foundation.NSDictionary dict)
          Creates an enterprise object from a raw row for the clazz's entity in the given editing context.
 T objectMatchingKeyAndValue(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String key, java.lang.Object value)
          Fetches the object matching the given key and value corresponding to the clazz's entity using the given editing context.
 com.webobjects.foundation.NSArray<T> objectsMatchingKeyAndValue(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String key, java.lang.Object value)
          Fetches all of the objects matching the given key and value corresponding to the clazz's entity using the given editing context.
 com.webobjects.foundation.NSArray<T> objectsMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOQualifier qualifier)
           
 com.webobjects.foundation.NSArray<T> objectsMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOQualifier qualifier, com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOSortOrdering> sortOrdering)
           
 com.webobjects.foundation.NSArray<T> objectsWithFetchSpecificationAndBindings(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String name, com.webobjects.foundation.NSDictionary bindings)
          Fetches an array of objects for a given fetch specification and an array of bindings.
 com.webobjects.foundation.NSArray<T> objectsWithQualifierFormat(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String qualifier, com.webobjects.foundation.NSArray args)
          Fetches all of the objects matching the given qualifier format corresponding to the clazz's entity using the given editing context.
 T objectWithPrimaryKeyValue(com.webobjects.eocontrol.EOEditingContext ec, java.lang.Object pk)
          Fetches the enterprise object for the specified primary key value and corresponding to the clazz's entity name.
 com.webobjects.eocontrol.EOFetchSpecification primaryKeyFetchSpecificationForEntity(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOQualifier eoqualifier, com.webobjects.foundation.NSArray sortOrderings, com.webobjects.foundation.NSArray additionalKeys)
          Constructs a fetch specification that will only fetch the primary keys for a given qualifier.
 com.webobjects.foundation.NSArray primaryKeysMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOQualifier eoqualifier, com.webobjects.foundation.NSArray sortOrderings)
          Fetches an array of primary keys matching a given qualifier and sorted with a given array of sort orderings.
 com.webobjects.foundation.NSArray primaryKeysMatchingValues(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.foundation.NSDictionary nsdictionary, com.webobjects.foundation.NSArray sortOrderings)
          Fetches an array of primary keys matching the values in a given dictionary.
static void resetClazzCache()
          Resets the clazz cache.
protected  void setEntityName(java.lang.String name)
          Sets the entity name of the clazz.
static void setFactory(EOEnterpriseObjectClazz.ClazzFactory value)
           
 
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

EOEnterpriseObjectClazz

public EOEnterpriseObjectClazz()
Default public constructor. In case you let your code generate with a template, you can simply call:

 public static FooClazz clazz = new FooClazz();
 
and the constructor will auto-discover your entity name. This only works when you have a concrete subclass for the entity in question, though.


EOEnterpriseObjectClazz

public EOEnterpriseObjectClazz(java.lang.String entityName)
Constructor that also supplies an entity name.

Parameters:
entityName -
Method Detail

objectCountAttribute

protected static com.webobjects.eoaccess.EOAttribute objectCountAttribute()
Creates and caches an eo attribute that can be used to return the number of objects that a given fetch specification will return.

Returns:
eo count attribute

objectCountUniqueAttribute

protected static com.webobjects.eoaccess.EOAttribute objectCountUniqueAttribute(com.webobjects.eoaccess.EOAttribute foo)
Parameters:
foo -

initialize

protected void initialize()
Called by the constructor.


discoverEntityName

protected void discoverEntityName()

init

public EOEnterpriseObjectClazz init(java.lang.String entityName)
Convenience init so you can chain constructor calls:

 public static FooClazz clazz = (FooClazz)new FooClazz().init("Foo");
 
without having to override the default constructor or the one that takes an entity name. Also useful when you don't have a special clazz defined for your entity, but would rather take one from a superclass.

Parameters:
entityName -

classDescription

public com.webobjects.eocontrol.EOClassDescription classDescription()
Returns the class description for the entity.


newArrayDataSource

public com.webobjects.eocontrol.EOArrayDataSource newArrayDataSource(com.webobjects.eocontrol.EOEditingContext ec)
Utility to return a new array datasource

Parameters:
ec -

newDatabaseDataSource

public com.webobjects.eoaccess.EODatabaseDataSource newDatabaseDataSource(com.webobjects.eocontrol.EOEditingContext ec)
Utility to return a new database datasource

Parameters:
ec -

resetClazzCache

public static void resetClazzCache()
Resets the clazz cache.


clazzForEntityNamed

public static EOEnterpriseObjectClazz clazzForEntityNamed(java.lang.String entityName)
Method used to get a clazz object for a given entity name. This method will cache the generated clazz object so that for a given entity name only one clazz object will be created.

Parameters:
entityName - name of the entity to get the Clazz object for
Returns:
clazz object for the given entity

createAndInsertObject

public T createAndInsertObject(com.webobjects.eocontrol.EOEditingContext ec)
Creates and inserts an object of the type of the clazz into the given editing context.

Parameters:
ec - an editing context
Returns:
newly created and inserted object

newPrimaryKeys

public com.webobjects.foundation.NSArray newPrimaryKeys(com.webobjects.eocontrol.EOEditingContext ec,
                                                        int i)
Generates an array of primary key values for the clazz's entity. Uses the database context for the entity's model and the given editingcontext.

Parameters:
ec - am editing context
i - number of primary keys to generate
Returns:
array of new primary keys

allObjects

public com.webobjects.foundation.NSArray<T> allObjects(com.webobjects.eocontrol.EOEditingContext ec)
Gets all of the objects for the clazz's entity. Just a cover method for the EOUtilities method objectsForEntityNamed.

Parameters:
ec - editingcontext to fetch the objects into
Returns:
array of all the objects for a given entity name.

objectFromRawRow

public T objectFromRawRow(com.webobjects.eocontrol.EOEditingContext ec,
                          com.webobjects.foundation.NSDictionary dict)
Creates an enterprise object from a raw row for the clazz's entity in the given editing context.

Parameters:
ec - editing context to create the eo in
dict - raw row dictionary
Returns:
enterprise object for the raw row

entityNameFromRawRow

protected java.lang.String entityNameFromRawRow(com.webobjects.eocontrol.EOEditingContext ec,
                                                com.webobjects.foundation.NSDictionary dict)
Utility method to get the entity name from a raw row dictionary, taking subclasses and restricting qualifiers into account.

Parameters:
ec - an editing context
dict - raw row dictionary
Returns:
entity name, if any

objectWithPrimaryKeyValue

public T objectWithPrimaryKeyValue(com.webobjects.eocontrol.EOEditingContext ec,
                                   java.lang.Object pk)
Fetches the enterprise object for the specified primary key value and corresponding to the clazz's entity name.

Parameters:
ec - editing context to fetch into
pk - primary key value. Compound primary keys are given as NSDictionaries.
Returns:
enterprise object for the specified primary key value.

objectsWithQualifierFormat

public com.webobjects.foundation.NSArray<T> objectsWithQualifierFormat(com.webobjects.eocontrol.EOEditingContext ec,
                                                                       java.lang.String qualifier,
                                                                       com.webobjects.foundation.NSArray args)
Fetches all of the objects matching the given qualifier format corresponding to the clazz's entity using the given editing context.

Parameters:
ec - editing context
qualifier - qualifier string
args - qualifier format arguments
Returns:
array of objects corresponding to the passed in parameters.

objectsMatchingKeyAndValue

public com.webobjects.foundation.NSArray<T> objectsMatchingKeyAndValue(com.webobjects.eocontrol.EOEditingContext ec,
                                                                       java.lang.String key,
                                                                       java.lang.Object value)
Fetches all of the objects matching the given key and value corresponding to the clazz's entity using the given editing context.

Parameters:
ec - editing context
key - key string
value - value
Returns:
array of objects corresponding to the passed in parameters.

objectsMatchingQualifier

public com.webobjects.foundation.NSArray<T> objectsMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec,
                                                                     com.webobjects.eocontrol.EOQualifier qualifier)

objectsMatchingQualifier

public com.webobjects.foundation.NSArray<T> objectsMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec,
                                                                     com.webobjects.eocontrol.EOQualifier qualifier,
                                                                     com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOSortOrdering> sortOrdering)

objectMatchingKeyAndValue

public T objectMatchingKeyAndValue(com.webobjects.eocontrol.EOEditingContext ec,
                                   java.lang.String key,
                                   java.lang.Object value)
Fetches the object matching the given key and value corresponding to the clazz's entity using the given editing context. If more than one matches, throws a EOMoreThanOneException, otherwise returns null or the match.

Parameters:
ec - editing context
key - key string
value - value
Returns:
array of objects corresponding to the passed in parameters.

objectsWithFetchSpecificationAndBindings

public com.webobjects.foundation.NSArray<T> objectsWithFetchSpecificationAndBindings(com.webobjects.eocontrol.EOEditingContext ec,
                                                                                     java.lang.String name,
                                                                                     com.webobjects.foundation.NSDictionary bindings)
Fetches an array of objects for a given fetch specification and an array of bindings. The fetch specifiation is resolved off of the entity corresponding to the current clazz.

Parameters:
ec - editing content to fetch into
name - fetch specification name
bindings - used to resolve binding keys within the fetch specification
Returns:
array of objects fetched using the given fetch specification

setEntityName

protected void setEntityName(java.lang.String name)
Sets the entity name of the clazz. Also registers the clazz in the cache.

Parameters:
name - of the entity

entityName

public java.lang.String entityName()
Gets the entity name of the clazz.

Returns:
entity name of the clazz.

entity

public com.webobjects.eoaccess.EOEntity entity()
Gets the entity corresponding to the entity name of the clazz.

Returns:
entity for the clazz

entity

public com.webobjects.eoaccess.EOEntity entity(com.webobjects.eocontrol.EOEditingContext ec)
Gets the entity corresponding to the entity name of the clazz.

Parameters:
ec - an editing context
Returns:
entity for the clazz

fetchSpecificationNamed

public com.webobjects.eocontrol.EOFetchSpecification fetchSpecificationNamed(java.lang.String name)
Gets a fetch specification for a given name.

Parameters:
name - of the fetch specification
Returns:
fetch specification for the given name and the clazz's entity name

fetchSpecificationNamed

public com.webobjects.eocontrol.EOFetchSpecification fetchSpecificationNamed(com.webobjects.eocontrol.EOEditingContext ec,
                                                                             java.lang.String name)
Gets a fetch specification for a given name.

Parameters:
ec - editing context to use for finding the model group
name - of the fetch specification
Returns:
fetch specification for the given name and the clazz's entity name

createFetchSpecification

public ERXFetchSpecification<T> createFetchSpecification(com.webobjects.eocontrol.EOQualifier qualifier,
                                                         com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOSortOrdering> sortings)
Creates a fetch spec for the entity.

Returns:
fetch specification for the given name and the clazz's entity name

filteredArray

public com.webobjects.foundation.NSArray<T> filteredArray(com.webobjects.foundation.NSArray<T> array,
                                                          com.webobjects.eocontrol.EOFetchSpecification spec,
                                                          com.webobjects.foundation.NSDictionary bindings)
Filters an array with a given fetch spec.

Parameters:
array -
spec -
bindings -

objectCountWithQualifier

public java.lang.Number objectCountWithQualifier(com.webobjects.eocontrol.EOEditingContext ec,
                                                 com.webobjects.eocontrol.EOQualifier qualifier)
Returns the number of objects matching the given qualifier for the clazz's entity name. Implementation wise this method will generate the correct sql to only perform a count, i.e. all of the objects wouldn't be pulled into memory.

Parameters:
ec - editing context to use for the count qualification
qualifier - to find the matching objects
Returns:
number of matching objects

objectCountWithFetchSpecificationAndBindings

public java.lang.Number objectCountWithFetchSpecificationAndBindings(com.webobjects.eocontrol.EOEditingContext ec,
                                                                     java.lang.String fetchSpecName,
                                                                     com.webobjects.foundation.NSDictionary bindings)
Find the number of objects matching the given fetch specification and bindings for the clazz's entity name. Implementation wise the sql generated will only return the count of the query, not all of the rows matching the qualification.

Parameters:
ec - ec used to perform the count in
fetchSpecName - name of the fetch specification
bindings - dictionary of bindings for the fetch specification
Returns:
number of objects matching the given fetch specification and bindings

primaryKeyFetchSpecificationForEntity

public com.webobjects.eocontrol.EOFetchSpecification primaryKeyFetchSpecificationForEntity(com.webobjects.eocontrol.EOEditingContext ec,
                                                                                           com.webobjects.eocontrol.EOQualifier eoqualifier,
                                                                                           com.webobjects.foundation.NSArray sortOrderings,
                                                                                           com.webobjects.foundation.NSArray additionalKeys)
Constructs a fetch specification that will only fetch the primary keys for a given qualifier.

Parameters:
ec - editing context, not used
eoqualifier - to construct the fetch spec with
sortOrderings - array of sort orderings to sort the result set with.
additionalKeys - array of additional key paths to construct the raw rows key paths to fetch.
Returns:
fetch specification that can be used to fetch primary keys for a given qualifier and sort orderings.

primaryKeysMatchingQualifier

public com.webobjects.foundation.NSArray primaryKeysMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec,
                                                                      com.webobjects.eocontrol.EOQualifier eoqualifier,
                                                                      com.webobjects.foundation.NSArray sortOrderings)
Fetches an array of primary keys matching a given qualifier and sorted with a given array of sort orderings.

Parameters:
ec - editing context to fetch into
eoqualifier - to restrict matching primary keys
sortOrderings - array of sort orders to sort result set
Returns:
array of primary keys matching a given qualifier

primaryKeysMatchingValues

public com.webobjects.foundation.NSArray primaryKeysMatchingValues(com.webobjects.eocontrol.EOEditingContext ec,
                                                                   com.webobjects.foundation.NSDictionary nsdictionary,
                                                                   com.webobjects.foundation.NSArray sortOrderings)
Fetches an array of primary keys matching the values in a given dictionary.

Parameters:
ec - editing context to fetch into
nsdictionary - dictionary of key value pairs to match against.
sortOrderings - array of sort orders to sort the result set by.
Returns:
array of primary keys matching the given criteria.

faultsFromRawRows

public com.webobjects.foundation.NSArray<T> faultsFromRawRows(com.webobjects.eocontrol.EOEditingContext ec,
                                                              com.webobjects.foundation.NSArray nsarray)
Constructs an array of faults for a given array of primary keys in a given editing context for the clazz's entity.

Parameters:
ec - editing context to construct the faults in
nsarray - array of primary key dictionaries
Returns:
array of faults for an array of primary key dictionaries.

faultsMatchingQualifier

public com.webobjects.foundation.NSArray<T> faultsMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec,
                                                                    com.webobjects.eocontrol.EOQualifier eoqualifier)
Fetches an array of faults matching a given qualifier.

Parameters:
ec - editing context to use to fetch into
eoqualifier - qualifier to match against
Returns:
array of faults that match the given qualifier

faultsMatchingQualifier

public com.webobjects.foundation.NSArray<T> faultsMatchingQualifier(com.webobjects.eocontrol.EOEditingContext ec,
                                                                    com.webobjects.eocontrol.EOQualifier eoqualifier,
                                                                    com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOSortOrdering> sortOrderings)
Fetches an array of faults matching a given qualifier and sorted by an array of sort orderings.

Parameters:
ec - editing context to use to fetch into
eoqualifier - qualifier to match against
sortOrderings - array of sort orderings to order the faults
Returns:
array of faults that match the given qualifier

faultsMatchingValues

public com.webobjects.foundation.NSArray<T> faultsMatchingValues(com.webobjects.eocontrol.EOEditingContext ec,
                                                                 com.webobjects.foundation.NSDictionary nsdictionary,
                                                                 com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOSortOrdering> sortOrderings)
Fetches an array of faults for a given set of criteria.

Parameters:
ec - editing context to use to fetch into
nsdictionary - key value criteria to match against
sortOrderings - array of sort orderings to order the faults
Returns:
array of faults that match the given criteria

factory

public static EOEnterpriseObjectClazz.ClazzFactory factory()

setFactory

public static void setFactory(EOEnterpriseObjectClazz.ClazzFactory value)

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

Copyright © 2002 – 2007 Project Wonder.