org.jminor.framework.domain
Class Entities

java.lang.Object
  extended by org.jminor.framework.domain.Entities

public final class Entities
extends Object

A Entity factory class


Nested Class Summary
static class Entities.Validator
          A default extensible Entity.Validator implementation.
 
Method Summary
static Entity.Definition define(String entityID, Property... propertyDefinitions)
          Defines a new entity, by default the entityID is used as the underlying table name
static Entity.Definition define(String entityID, String tableName, Property... propertyDefinitions)
          Defines a new entity
static Entity entity(Entity.Key key)
          Creates a new Entity instance with the given primary key
static Entity entity(String entityID)
          Creates a new Entity instance with the given entityID
static Entity entity(String entityID, Map<String,Object> values, Map<String,Object> originalValues)
          Creates a new Entity instance with the given entityID and the given values/originalValues
static String getCaption(String entityID)
           
static Collection<Property.ColumnProperty> getColumnProperties(String entityID)
           
static List<Property.ColumnProperty> getColumnProperties(String entityID, boolean includePrimaryKeyProperties, boolean includeReadOnly, boolean includeNonUpdatable)
          Retrieves the column properties comprising the entity identified by entityID
static Property.ColumnProperty getColumnProperty(String entityID, String propertyID)
           
static Collection<String> getDefinedEntities()
           
static Map<String,String> getDefinitions()
           
static Map<String,String> getDefinitions(String domainID)
           
static Collection<Property.DenormalizedProperty> getDenormalizedProperties(String entityID, String foreignKeyPropertyID)
           
static Collection<String> getDomainEntityIDs(String domainID)
           
static Collection<String> getEntitySearchPropertyIDs(String entityID)
           
static Collection<Property.ForeignKeyProperty> getForeignKeyProperties(String entityID)
           
static List<Property.ForeignKeyProperty> getForeignKeyProperties(String entityID, String referenceEntityID)
          Returns the foreign key properties referencing entities of the given type
static Property.ForeignKeyProperty getForeignKeyProperty(String entityID, String propertyID)
           
static IdSource getIdSource(String entityID)
           
static String getIdValueSource(String entityID)
           
static Collection<String> getLinkedPropertyIDs(String entityID, String propertyID)
          Returns the IDs of any properties which values are linked to the property identified by propertyID in the entity identified by entityID
static String getOrderByClause(String entityID)
           
static List<Property.PrimaryKeyProperty> getPrimaryKeyProperties(String entityID)
           
static Map<String,Property> getProperties(String entityID)
           
static Collection<Property> getProperties(String entityID, boolean includeHidden)
           
static List<Property> getProperties(String entityID, Collection<String> propertyIDs)
           
static List<Property> getProperties(String entityID, String... propertyIDs)
           
static Property getProperty(String entityID, String propertyID)
           
static List<Property.ColumnProperty> getSearchProperties(String entityID)
          Retrieves the properties used when searching for a entity of the given type, if no search property IDs are defined all STRING based properties are returned.
static List<Property.ColumnProperty> getSearchProperties(String entityID, Collection<String> searchPropertyIds)
          Retrieves the properties used when searching for a entity of the given type, if no search property IDs are defined all STRING based properties are returned.
static String getSelectColumnsString(String entityID)
           
static String getSelectQuery(String entityID)
           
static String getSelectTableName(String entityID)
           
static ValueMap.ToString<String> getStringProvider(String entityID)
           
static String getTableName(String entityID)
           
static Collection<Property.TransientProperty> getTransientProperties(String entityID)
           
static Entity.Validator getValidator(String entityID)
           
static List<Property> getVisibleProperties(String entityID)
           
static boolean hasDenormalizedProperties(String entityID)
           
static boolean hasDenormalizedProperties(String entityID, String foreignKeyPropertyID)
           
static boolean hasLinkedProperties(String entityID, String propertyID)
          Returns true if the property identified by propertyID in the entity identified by entityID has any linked properties, that is properties which values depend on the value of the given property
static boolean isDefined(String entityID)
           
static boolean isPrimaryKeyAutoGenerated(String entityID)
          Returns true if the value for the primary key of this entity is automatically generated, either by the framework, such as values queried from sequences or set by triggers
static boolean isReadOnly(String entityID)
           
static boolean isSmallDataset(String entityID)
           
static Entity.Key key(String entityID)
          Creates a new Entity.Key instance with the given entityID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

entity

public static Entity entity(String entityID)
Creates a new Entity instance with the given entityID

Parameters:
entityID - the entity ID
Returns:
a new Entity instance

entity

public static Entity entity(Entity.Key key)
Creates a new Entity instance with the given primary key

Parameters:
key - the primary key
Returns:
a new Entity instance

entity

public static Entity entity(String entityID,
                            Map<String,Object> values,
                            Map<String,Object> originalValues)
Creates a new Entity instance with the given entityID and the given values/originalValues

Parameters:
entityID - the entity ID
values - the values
originalValues - the original values
Returns:
a new Entity instance

key

public static Entity.Key key(String entityID)
Creates a new Entity.Key instance with the given entityID

Parameters:
entityID - the entity ID
Returns:
a new Entity.Key instance

define

public static Entity.Definition define(String entityID,
                                       Property... propertyDefinitions)
Defines a new entity, by default the entityID is used as the underlying table name

Parameters:
entityID - the ID uniquely identifying the entity
propertyDefinitions - the Property objects to base this entity on
Returns:
a new Entity.Definition

define

public static Entity.Definition define(String entityID,
                                       String tableName,
                                       Property... propertyDefinitions)
Defines a new entity

Parameters:
entityID - the ID uniquely identifying the entity
tableName - the name of the underlying table
propertyDefinitions - the Property objects to base the entity on
Returns:
a new Entity.Definition

getDomainEntityIDs

public static Collection<String> getDomainEntityIDs(String domainID)
Parameters:
domainID - the domain ID
Returns:
all entity IDs associated with the given domain

getEntitySearchPropertyIDs

public static Collection<String> getEntitySearchPropertyIDs(String entityID)
Parameters:
entityID - the entity ID
Returns:
a String array containing the IDs of the properties used as default search properties for entities identified by entityID

getSearchProperties

public static List<Property.ColumnProperty> getSearchProperties(String entityID)
Retrieves the properties used when searching for a entity of the given type, if no search property IDs are defined all STRING based properties are returned.

Parameters:
entityID - the entity ID
Returns:
the search properties to use

getSearchProperties

public static List<Property.ColumnProperty> getSearchProperties(String entityID,
                                                                Collection<String> searchPropertyIds)
Retrieves the properties used when searching for a entity of the given type, if no search property IDs are defined all STRING based properties are returned.

Parameters:
entityID - the entity ID
searchPropertyIds - the IDs of the properties to use as search properties
Returns:
the search properties to use

getPrimaryKeyProperties

public static List<Property.PrimaryKeyProperty> getPrimaryKeyProperties(String entityID)
Parameters:
entityID - the entity ID
Returns:
a list containing the primary key properties of the entity identified by entityID

isReadOnly

public static boolean isReadOnly(String entityID)
Parameters:
entityID - the entity ID
Returns:
true if the entity identified by entityID is read only
Throws:
RuntimeException - if the entity is undefined

isSmallDataset

public static boolean isSmallDataset(String entityID)
Parameters:
entityID - the entity ID
Returns:
true if the entity identified by entityID is based on a small dataset
Throws:
RuntimeException - if the entity is undefined

getOrderByClause

public static String getOrderByClause(String entityID)
Parameters:
entityID - the entity ID
Returns:
a comma separated list of columns to use in the order by clause

getSelectTableName

public static String getSelectTableName(String entityID)
Parameters:
entityID - the entity ID
Returns:
the name of the table used to select entities identified by entityID
Throws:
RuntimeException - if the entity is undefined

getTableName

public static String getTableName(String entityID)
Parameters:
entityID - the entity ID
Returns:
the name of the table on which entities identified by entityID are based
Throws:
RuntimeException - if the entity is undefined

getSelectQuery

public static String getSelectQuery(String entityID)
Parameters:
entityID - the entity ID
Returns:
the sql query used when selecting entities identified by entityID
Throws:
RuntimeException - if the entity is undefined

getSelectColumnsString

public static String getSelectColumnsString(String entityID)
Parameters:
entityID - the entity ID
Returns:
the query string used to select entities identified by entityID
Throws:
RuntimeException - if the entity is undefined

getIdSource

public static IdSource getIdSource(String entityID)
Parameters:
entityID - the entity ID
Returns:
the IdSource of the entity identified by entityID
Throws:
RuntimeException - if the entity is undefined

getStringProvider

public static ValueMap.ToString<String> getStringProvider(String entityID)
Parameters:
entityID - the entity ID
Returns:
the StringProvider used in case toString() is called for the given entity
Throws:
RuntimeException - if the entity is undefined

isPrimaryKeyAutoGenerated

public static boolean isPrimaryKeyAutoGenerated(String entityID)
Returns true if the value for the primary key of this entity is automatically generated, either by the framework, such as values queried from sequences or set by triggers

Parameters:
entityID - the entity ID
Returns:
true if the value for the primary key is automatically generated

getColumnProperties

public static List<Property.ColumnProperty> getColumnProperties(String entityID,
                                                                boolean includePrimaryKeyProperties,
                                                                boolean includeReadOnly,
                                                                boolean includeNonUpdatable)
Retrieves the column properties comprising the entity identified by entityID

Parameters:
entityID - the entity ID
includePrimaryKeyProperties - if true primary key properties are included
includeReadOnly - if true then properties that are marked as 'read only' are included
includeNonUpdatable - if true then non updatable properties are included
Returns:
a list containing the database properties (properties that map to database columns) comprising the entity identified by entityID

getVisibleProperties

public static List<Property> getVisibleProperties(String entityID)
Parameters:
entityID - the entity ID
Returns:
a list containing the visible (non-hidden) properties in the entity identified by entityID
Throws:
RuntimeException - if no visible properties are defined for the given entity

getColumnProperty

public static Property.ColumnProperty getColumnProperty(String entityID,
                                                        String propertyID)
Parameters:
entityID - the entity ID
propertyID - the property ID
Returns:
the column property identified by property ID

getProperty

public static Property getProperty(String entityID,
                                   String propertyID)
Parameters:
entityID - the entity ID
propertyID - the property ID
Returns:
the property identified by propertyID in the entity identified by entityID
Throws:
RuntimeException - in case no such property exists

getProperties

public static List<Property> getProperties(String entityID,
                                           Collection<String> propertyIDs)
Parameters:
entityID - the entity ID
propertyIDs - the property IDs of the properties to retrieve
Returns:
a list containing the properties identified by propertyIDs, found in the entity identified by entityID

getProperties

public static List<Property> getProperties(String entityID,
                                           String... propertyIDs)
Parameters:
entityID - the entity ID
propertyIDs - the property IDs of the properties to retrieve
Returns:
a list containing the properties identified by propertyIDs, found in the entity identified by entityID

getProperties

public static Collection<Property> getProperties(String entityID,
                                                 boolean includeHidden)
Parameters:
entityID - the entity ID
includeHidden - true if hidden properties should be included in the result
Returns:
a collection containing the properties found in the entity identified by entityID

getColumnProperties

public static Collection<Property.ColumnProperty> getColumnProperties(String entityID)
Parameters:
entityID - the entity ID
Returns:
a collection containing all database properties found in the entity identified by entityID, that is, properties that map to database columns

getTransientProperties

public static Collection<Property.TransientProperty> getTransientProperties(String entityID)
Parameters:
entityID - the entity ID
Returns:
a collection containing all transient database properties found in the entity identified by entityID, that is, properties that do not map to database columns

getForeignKeyProperties

public static Collection<Property.ForeignKeyProperty> getForeignKeyProperties(String entityID)
Parameters:
entityID - the entity ID
Returns:
a collection containing all the foreign key properties found in the entity identified by entityID

hasDenormalizedProperties

public static boolean hasDenormalizedProperties(String entityID)
Parameters:
entityID - the entity ID
Returns:
true if the given entity contains denormalized properties

getDenormalizedProperties

public static Collection<Property.DenormalizedProperty> getDenormalizedProperties(String entityID,
                                                                                  String foreignKeyPropertyID)
Parameters:
entityID - the entity ID
foreignKeyPropertyID - the foreign key id
Returns:
a collection containing all denormalized properties of the entity identified by entityID which source is the entity identified by propertyOwnerEntityID

hasDenormalizedProperties

public static boolean hasDenormalizedProperties(String entityID,
                                                String foreignKeyPropertyID)
Parameters:
entityID - the entity ID
foreignKeyPropertyID - the foreign key id
Returns:
true if the entity identified by entityID contains denormalized properties which source is the entity identified by propertyOwnerEntityID

hasLinkedProperties

public static boolean hasLinkedProperties(String entityID,
                                          String propertyID)
Returns true if the property identified by propertyID in the entity identified by entityID has any linked properties, that is properties which values depend on the value of the given property

Parameters:
entityID - the entityID
propertyID - the propertyID
Returns:
true if any derived properties are linked to the given property

getLinkedPropertyIDs

public static Collection<String> getLinkedPropertyIDs(String entityID,
                                                      String propertyID)
Returns the IDs of any properties which values are linked to the property identified by propertyID in the entity identified by entityID

Parameters:
entityID - the entityID
propertyID - the propertyID
Returns:
the IDs of any properties which values are linked to the given property

getForeignKeyProperties

public static List<Property.ForeignKeyProperty> getForeignKeyProperties(String entityID,
                                                                        String referenceEntityID)
Returns the foreign key properties referencing entities of the given type

Parameters:
entityID - the ID of the entity from which to retrieve the foreign key properties
referenceEntityID - the ID of the reference entity
Returns:
a List containing the properties, an empty list is returned in case no properties fit the criteria

getForeignKeyProperty

public static Property.ForeignKeyProperty getForeignKeyProperty(String entityID,
                                                                String propertyID)
Parameters:
entityID - the entity ID
propertyID - the property ID
Returns:
the Property.ForeignKeyProperty with the given propertyID
Throws:
RuntimeException - in case no such property exists

getProperties

public static Map<String,Property> getProperties(String entityID)
Parameters:
entityID - the entity ID
Returns:
a map containing the properties the given entity is comprised of, mapped to their respective propertyIDs

getIdValueSource

public static String getIdValueSource(String entityID)
Parameters:
entityID - the entity ID
Returns:
the name of the primary key value source for the given entity
Throws:
RuntimeException - in case no id source name is specified

getCaption

public static String getCaption(String entityID)
Parameters:
entityID - the entity ID
Returns:
the caption associated with the given entity type

getValidator

public static Entity.Validator getValidator(String entityID)
Parameters:
entityID - the entityID
Returns:
the validator for the given entity type

getDefinedEntities

public static Collection<String> getDefinedEntities()
Returns:
the entityIDs of all defined entities

isDefined

public static boolean isDefined(String entityID)
Parameters:
entityID - the entity ID
Returns:
true if the entity is defined

getDefinitions

public static Map<String,String> getDefinitions()
Returns:
a map containing all defined entityIDs, with their respective table names as an associated value

getDefinitions

public static Map<String,String> getDefinitions(String domainID)
Parameters:
domainID - the ID of the domain for which to retrieve the entity definitions
Returns:
a map containing all defined entityIDs, with their respective table names as an associated value