Package mc.core.model.base
Class EntityUtils
java.lang.Object
mc.core.model.base.EntityUtils
class with static utility methods for dealing with ejb3 and hibernate specifics. direct use of hibernate methods
should only be in here, to keep hibernate constraints out to the rest of the system
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanequals(IBaseEntity entity, Object another) static <T extends IBaseEntity>
List<T>forceInitialize(List<T> entityList) static <T extends IBaseEntity>
TforceInitialize(T entity) if entity is HibernateProxy forces initialization so that properties other than the id can be accessed.static <T extends IBaseEntity>
Class<T>static <T extends IBaseEntity>
Class<T>getClass(T entity) NEW: combines forceInitialize and stripProxy, so this is guaranteed to always return the real classstatic inthashCode(IBaseEntity entity) static <S extends IBaseEntity>
SifInstanceOf(IBaseEntity entity, Class<S> entityClass) return the casted entity if it is of given entityClass, otherwise nullstatic <S extends IBaseEntity>
booleanisInstance(S entity, Class<?> entityClass) static <S extends IBaseEntity,T extends S>
List<T>static <S extends IBaseEntity,T extends S>
TsafeCast(S entity) cast entity to a derived entity class.static <T> List<T>helper for always returning a valid list object from getter methodsstatic <T> Set<T>helper for always returning a valid set object from getter methodsstatic <T extends IBaseEntity>
Class<T>stripProxy(T entity) returns the entity class if entity is wrapped by HibernateProxytoDisplay(Collection<? extends IBaseEntity> entityList, Locale locale) helper for getting display string for entities in locale.static StringtoDisplay(IBaseEntity entity, Locale locale) helper for getting display string for entity in locale.static StringtoDisplayString(Collection<? extends IBaseEntity> entityList, Locale locale) helper for getting display string for entities in locale.static StringtoString(IBaseEntity entity) helper for creating a String identifier for an entity
-
Constructor Details
-
EntityUtils
public EntityUtils()
-
-
Method Details
-
getClass
NEW: combines forceInitialize and stripProxy, so this is guaranteed to always return the real class -
getClass
- Parameters:
potentialProxyClass- Manually implemented class or aHibernateProxyinstance.- Returns:
- Manually implemented class. This represents the most concrete match that can be determined by the given class which leaves the possibility of getting an abstract class.
-
stripProxy
returns the entity class if entity is wrapped by HibernateProxy -
forceInitialize
if entity is HibernateProxy forces initialization so that properties other than the id can be accessed. WARNING: entity must be attached to persistence context.
Not recursive: Any properties referencing lazy loaded objects or collections must be initialized themselves. -
forceInitialize
-
safeCast
cast entity to a derived entity class. calls forceInitialize prior to cast to ensure entity is a real entity and not a base class proxy. casting base class proxies will result in ClassCastException. still you have to make sure that entity is really of target type. otherwise you will get a ClassCastException.- Type Parameters:
S- super entity typeT- target entity type- Parameters:
entity- to cast and maybe initialize- Returns:
- entity casted to target entity type.
-
safeCast
-
isInstance
-
ifInstanceOf
return the casted entity if it is of given entityClass, otherwise null -
safeList
helper for always returning a valid list object from getter methods- Type Parameters:
T- generic type for list- Parameters:
list- list property member, can be null- Returns:
- list itself if not null, or empty list of same type if null
-
safeSet
helper for always returning a valid set object from getter methods- Type Parameters:
T- generic set for list- Parameters:
set- set property member, can be null- Returns:
- set itself if not null, or empty set of same type if null
-
toString
helper for creating a String identifier for an entity- Parameters:
entity-- Returns:
- String in the form: "[entity.class.simpleName]@[entity.id]" or "null" if entity is null
-
toDisplay
helper for getting display string for entity in locale.- Parameters:
entity- Attached entity ornull.locale- Language of desired output. Ifnull, master locale is used.- Returns:
- Entity display according to DO classes or empty string. Never
null.
-
toDisplay
helper for getting display string for entities in locale.- Parameters:
entityList- Attached entities ornull.locale- Language of desired output. Ifnull, master locale is used.- Returns:
- Entity display strings according to DO classes.
nullifentityListwasnull.
-
toDisplayString
helper for getting display string for entities in locale.- Parameters:
entityList- Attached entities ornull.locale- Language of desired output. Ifnull, master locale is used.- Returns:
- Display strings concatenated by comma according to DO classes.
nullifentityListwasnullor empty.
-
equals
-
hashCode
-