Wednesday, 15 April 2015

Which is the best way of dealing with transformation layer between dto and dao in scala? -



Which is the best way of dealing with transformation layer between dto and dao in scala? -

we working in app in scala , maintain transformation layer lean possible.

we convert dao objects dto objects , other way around. in origin have same fields, in future sure won't same. so, want have default implementation, entitytransformerimpl, able implement customs entitytransformer.

we have came solution. it's not bad think might rather slow using reflection load class , create new objects.

class="lang-scala prettyprint-override">package com.triplea.business.transformer import org.apache.commons.beanutils.beanutils import com.triplea.dao.dto.coursedto import com.triplea.business.entity.course class entitytransformerimpl[t, e] extends entitytransformer[t, e] { def transformtodto(entity: t): e = { val clazz = java.lang.class.forname(manifest.asinstanceof[e].getclass().getname()) val ctr = clazz.getconstructor() var dto: e = ctr.newinstance().asinstanceof[e] beanutils.copyproperties(dto, entity) dto } def transformlisttodto(entities: list[t]): list[e] = { entities.map(e => transformtodto(e)) } def transformlisttoentity(dtos: list[e]): list[t] = { dtos.map(e => transformtoentity() } def transformoptiontodto(entities: option[t]): option[e] = { entities.map(e => transformtodto(e)) } def transformoptiontoentity(dtos: option[e]): option[t] = { dtos.map(e => transformtoentity(e)) } }

do think solution? have new ideas implementation?

scala dao transformation dto

No comments:

Post a Comment