I have the following DTO classes:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Conclusion {
private Integer id;
// ......
private List<CType> cTypes;
}
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CType {
private Integer id;
// ......
private VType vType;
}
And also their corresponding entity classes:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "conclusion")
public class Conclusion {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false)
private Integer id;
// ......
@OneToMany
@JoinColumn(name = "id")
private List<CTypeEntity> cTypeEntities;
}
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "c_types")
public class CTypeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false)
private Integer id;
// ......
@Column(name = "v_type_id")
private Integer vTypeId;
}
Also, all corresponding Dao and JPA Repository interfaces are present. Now, I am writing my mapstruct Mapper interface which should be used for mapping entities to DTOs and vice versa. Here is the mapper:
@Mapper
public interface ConclusionMapper {
@Mappings({
@Mapping(target = "cTypes", source = "cTypeEntities")
})
Conclusion toConclusion(ConclusionEntity entity);
List<Conclusion> toConclusionList(List<ConclusionEntity> entities);
@Mappings({
@Mapping(target = "cTypeEntities", source = "cTypes")
})
ConclusionEntity fromConclusion(Conclusion conclusion);
List<ConclusionEntity> fromConclusionList(List<Conclusion> conclusions);
@Mappings({
@Mapping(target = "cType", source = "vTypeId", qualifiedByName = "formVType")
})
ConclusionTaxType toCType(CTypeEntity cTypeEntity);
List<CType> toCTypes(List<CTypeEntity> cTypeEntities);
CTypeEntity fromCType(CType cType);
List<CTypeEntity> fromCTypeList(List<CType> cTypes);
@Named("formVType")
default VType formVType(CTypeEntity entity) {
// TODO: instantiate a DAO which will return an instance of VType
VTypeDao dao; // instantiate somehow
return vTypeDao.findById(entity.getVId());
}
}
VTypeDao looks like this:
public interface VTypeDao {
VType findById(int id);
boolean exists(int id);
List<VType> findAll();
}
@Component
public class VTypeDaoImpl implements VTypeDao {
private final VTypeRepo vTypeRepo;
public VTypeDaoImpl(VTypeRepo vTypeRepo) {
this.vTypeRepo = vTypeRepo;
}
// ............................. method implementations
}
My question is: How to instantiate an object of VTypeDao (or at least VTypeRepo so I could pass if to VTypeDaoImpl as a parameter)?
There is no factory class for getting the appropriate implementation of VTypeDao.
EDIT: VTypeDao and its implementation are third party components to my project.