Class ProjectionMappings

java.lang.Object
tech.ydb.yoj.repository.db.projection.ProjectionMappings

public final class ProjectionMappings extends Object
  • Method Details

    • lenientFieldMapping

      @NonNull public static <P extends Entity<P>, T extends Entity<T>> @NonNull Map<String,String> lenientFieldMapping(@NonNull @NonNull Class<P> projectionType, @NonNull @NonNull Class<T> entityType)
      Creates a lenient one-to-one mapping from entity fields to projection fields, which contains all strict mappings, plus mappings of the form <entity field> <-> <projection field with the same path> (if both fields exist).
      Type Parameters:
      P - projection type
      T - entity type
      Parameters:
      projectionType - projection class
      entityType - entity class
      Returns:
      Map: Entity field path -> Projection field path
      See Also:
    • strictFieldMapping

      @NonNull public static <P extends Entity<P>, T extends Entity<T>> @NonNull Map<String,String> strictFieldMapping(@NonNull @NonNull Class<P> projectionType, @NonNull @NonNull Class<T> entityType)
      Creates a one-to-one mapping from entity fields to entity projection ID fields, assuming that the projection ID contains fields with the same name as in the main entity and at most one field for the main entity ID (with any name).

    E.g., the following entity-projection pair qualifies:

     @Value class MyEntity implements Entity<MyEntity> {
         Id id;
         String field;
    
         @Value static class Id implements Entity.Id<MyEntity> { String value; }
     }
    
     @Value class MyIndex implements Entity<MyIndex> {
         Id id;
    
         @Value
         static class Id implements Entity.Id<MyIndex> {
             // MUST have the same Java field name as in the entity class
             // (DB name specified in @Column annotation does not matter.)
             String field;
    
             // OPTIONAL. If present, this field MAY have any name
             MyEntity.Id entityId;
         }
     }