Class Entities

java.lang.Object
ch.tocco.nice2.persist.core.api.entity.Entities

public final class Entities extends Object
Static methods for dealing with entities.
  • Method Details

    • unmodifiableEntity

      public static Entity unmodifiableEntity(Entity entity)
      Wraps the entity to be unmodifiable.
    • nullKeyEntity

      public static Entity nullKeyEntity(Entity entity)
      Wraps the entity so that it forgets all about its existing Primary Key.
    • nullCounterEntity

      public static Entity nullCounterEntity(Entity entity)
      Wraps the entity so that it forgets all values of counter fields.
    • createCopy

      public static Entity createCopy(Entity sourceEntity, EntityManager eManager)
      Creates a new entity based on the given one without storing it (State=CONCEPTION).

      Info: Fields part of the Primary key are ignored as well as fields of type counter.

      Limits: Relations are not copied. Obviously. Such a method would have to store everything. Does not call fillNonNullable(), you may or may not have to do that, probably depends on the source if it was complete or not.

      Parameters:
      sourceEntity - The source of data, won't be modified.
      Returns:
      The newly in-memory created entity in conception state.
    • createCopy

      public static Entity createCopy(Entity sourceEntity)
      Same as createCopy(Entity, EntityManager). Uses the EntityManager of the given entity.
      See Also:
    • createCopy

      public static Entity createCopy(Entity sourceEntity, EntityManager eManager, @Nullable @Nullable List<String> excludedFields)
    • wrapForCopy

      public static Entity wrapForCopy(Entity entity)
      Wraps the entity so that primary key and counter info is nullified, and makes it unmodifiable.
      Parameters:
      entity - The source entity, won't be modified.
      Returns:
      The wrapper containing the source.
    • copyFields

      public static void copyFields(Entity sourceEntity, Entity targetEntity)
      Copies the field values of the source to the target.

      WARNING: All values are copied over, including pk fields!

      Limits: Relations are not copied. Obviously. Such a method would have to store everything. Does not call fillNonNullable(), you may or may not have to do that, probably depends on the source if it was complete or not.

      Parameters:
      sourceEntity - The source of data, won't be modified.
      targetEntity - The entity where all field values will be overridden.
    • copyFields

      public static void copyFields(Entity sourceEntity, Entity targetEntity, @Nullable @Nullable List<String> excludedFields)
    • clearFields

      public static void clearFields(Entity entity)
      Set every field to null or empty value except keys if possible.
    • copyRelations

      public static void copyRelations(Entity sourceEntity, Entity targetEntity)
      Copy relations (relation references) from source entity to target entity.
      Parameters:
      sourceEntity - The entity to copy the relation references from.
      targetEntity - The entity to copy the relation references to.
    • copyRelations

      public static void copyRelations(Entity sourceEntity, Entity targetEntity, Set<String> excludedRelationNames)
      Copy relations (relation references) from source entity to target entity.
      Parameters:
      sourceEntity - The entity to copy the relation references from.
      targetEntity - The entity to copy the relation references to.
      excludedRelationNames - The relations to ignore and skip.
    • copyRelationReference

      public static void copyRelationReference(Entity sourceEntity, Entity targetEntity, String relationName)
      Copies the relation reference from source onto target entity.

      This method relates the same entity, it does not create a copy of the linked entity.

    • resolvePathToFieldValue

      @Deprecated @Nullable public static @Nullable TypedValue<?> resolvePathToFieldValue(Entity entity, String pathString) throws NoEntityToLoadException
      Resolve a path of relations to a single field value. All relations on the path may only be n:1 relations.
      Parameters:
      entity - the starting entity
      pathString - a string containing an arbitrary path to follow from the starting entity
      Returns:
      the field value corresponding to the specified path
      Throws:
      NoEntityToLoadException
    • resolvePathToEntityList

      @Deprecated public static EntityList resolvePathToEntityList(Entity entity, String pathString) throws NoEntityToLoadException
      Resolve a path of relations to an entity list. All relations on the path may only be n:1 relations except for the last relation which can be either 1:n or n:1
      Parameters:
      entity - the starting entity
      pathString - a string containing an arbitrary path to follow from the starting entity
      Returns:
      the entity list corresponding to the specified relation path
      Throws:
      NoEntityToLoadException
    • resolvePathWithoutLastStep

      @Deprecated public static Entity resolvePathWithoutLastStep(Entity entity, Path path) throws NoEntityToLoadException
      Resolve a path of relations (without the last step) to an entity all relations on the path may only be n:1 relations.
      Parameters:
      entity - the starting entity
      path - the path object to follow
      Returns:
      the entity corresponding to the path without the last step
      Throws:
      NoEntityToLoadException
    • resolvePathWithoutLastStepOrNull

      @Nullable @Deprecated public static @Nullable Entity resolvePathWithoutLastStepOrNull(Entity entity, Path path)
      Resolve a path of relations (without the last step) to an entity all relations on the path may only be n:0..1 relations. return null if there was no entity found
      Parameters:
      entity - the starting entity
      path - the path object to follow
      Returns:
      the entity corresponding to the path without the last step
    • resolvePathToEntityListWithoutLastStep

      public static EntityList resolvePathToEntityListWithoutLastStep(Entity entity, Path path, QueryBuilderFactory queryBuilderFactory)
      Resolve a path without it's last step to an entity list. This method is capable of traversing all types of relations (1:n, n:n, n:1), similar to a path in a query e.g. find X where relY.relZ.pk == 1
      Parameters:
      entity - the starting point entity
      path - a path
      queryBuilderFactory - queryBuilderFactory
      Returns:
      the resolved entity list
    • reversePathWithoutLastStep

      public static Entities.ReversePath reversePathWithoutLastStep(EntityModel entityModel, Path path)
      Reverse a path without the last step
      Parameters:
      entityModel - the starting point entity model
      path - the path to reverse
      Returns:
      a path string representing the opposite direction of the provided path
    • reversePath

      public static Entities.ReversePath reversePath(EntityModel entityModel, Path path)
      Reverse a path
      Parameters:
      entityModel - the starting point entity model
      path - the path to reverse
      Returns:
      a path string representing the opposite direction of the provided path
    • resolvePathWithCondition

      public static EntityList resolvePathWithCondition(EntityList baseEntities, String path, @Nullable @Nullable String condition, QueryBuilderFactory queryBuilderFactory, Context context)
      Resolve a path applying a condition to the "last step"
      Parameters:
      baseEntities - a base entity list to resolve the path on
      path - a path string ending in a relation (not a field)
      condition - a condition for the target entity of the provided path
      queryBuilderFactory - queryBuilderFactory
      Returns:
      an EntityList containing entities that are found behind this path satisfying the provided condition
    • deleteEntities

      public static void deleteEntities(EntityList listWithEntitiesToDelete)
      Deletes all entities in supplied entity list
      Parameters:
      listWithEntitiesToDelete - the