Uploaded image for project: 'DeltaSpike'
  1. DeltaSpike
  2. DELTASPIKE-606

Simplified DTO mapping for Entity updates

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0.0
    • Data-Module
    • None

    Description

      Updating a DTO currently still requires custom code in a mapper. This should be reduced to a minimum in the mapper base class.

      SimpleQueryInOutMapperBase:

      @Inject
      private QueryInvocationContext context;
      
      protected abstract Object getPrimaryKey(Dto dto);
      
      protected E findEntity(Object pk)
      {
          return (E) context.getEntityManager().find(context.getEntityClass(), pk);
      } 
      
      @Override
      public Object mapParameter(final Object parameter)
      {
          Object pk = getPrimaryKey((Dto) parameter);
          if (pk != null)
          {
              E entity = findEntity(pk);
              return toEntity(entity, (Dto) parameter);
          }
          return toEntity(newEntity(), (Dto) parameter);
      }
      

      Note that this is an API breaking change (toEntity).

      Attachments

        Activity

          People

            thomashug Thomas Hug
            thomashug Thomas Hug
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: