Class EntityUtils

java.lang.Object
mc.core.model.base.EntityUtils

public abstract class EntityUtils extends Object
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 Details

    • EntityUtils

      public EntityUtils()
  • Method Details

    • getClass

      public static <T extends IBaseEntity> Class<T> getClass(T entity)
      NEW: combines forceInitialize and stripProxy, so this is guaranteed to always return the real class
    • getClass

      public static <T extends IBaseEntity> Class<T> getClass(Class<T> potentialProxyClass)
      Parameters:
      potentialProxyClass - Manually implemented class or a HibernateProxy instance.
      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

      public static <T extends IBaseEntity> Class<T> stripProxy(T entity)
      returns the entity class if entity is wrapped by HibernateProxy
    • forceInitialize

      public static <T extends IBaseEntity> T forceInitialize(T entity)
      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

      public static <T extends IBaseEntity> List<T> forceInitialize(List<T> entityList)
    • safeCast

      public static <S extends IBaseEntity, T extends S> T safeCast(S entity)
      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 type
      T - target entity type
      Parameters:
      entity - to cast and maybe initialize
      Returns:
      entity casted to target entity type.
    • safeCast

      public static <S extends IBaseEntity, T extends S> List<T> safeCast(List<S> entityList)
    • isInstance

      public static <S extends IBaseEntity> boolean isInstance(S entity, Class<?> entityClass)
    • ifInstanceOf

      public static <S extends IBaseEntity> S ifInstanceOf(IBaseEntity entity, Class<S> entityClass)
      return the casted entity if it is of given entityClass, otherwise null
    • safeList

      public static <T> List<T> safeList(List<T> list)
      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

      public static <T> Set<T> safeSet(Set<T> set)
      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

      public static String toString(IBaseEntity entity)
      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

      public static String toDisplay(IBaseEntity entity, Locale locale)
      helper for getting display string for entity in locale.
      Parameters:
      entity - Attached entity or null.
      locale - Language of desired output. If null, master locale is used.
      Returns:
      Entity display according to DO classes or empty string. Never null.
    • toDisplay

      public static List<String> toDisplay(Collection<? extends IBaseEntity> entityList, Locale locale)
      helper for getting display string for entities in locale.
      Parameters:
      entityList - Attached entities or null.
      locale - Language of desired output. If null, master locale is used.
      Returns:
      Entity display strings according to DO classes. null if entityList was null.
    • toDisplayString

      public static String toDisplayString(Collection<? extends IBaseEntity> entityList, Locale locale)
      helper for getting display string for entities in locale.
      Parameters:
      entityList - Attached entities or null.
      locale - Language of desired output. If null, master locale is used.
      Returns:
      Display strings concatenated by comma according to DO classes. null if entityList was null or empty.
    • equals

      public static boolean equals(IBaseEntity entity, Object another)
    • hashCode

      public static int hashCode(IBaseEntity entity)