make update process without setter methods with BeanUtils.copyProperties(source,target,editableColumns)

This is just code sample that is why some imports some injections are missed!


import static com.company.project.util.EntityUtil.copyPropertiesExceptId; 

public class OfficeServiceImpl implementes OfficeService{

public OfficePhoto update(Long companyId, Long officeId, Long id, OfficePhotoEditableColumn     officePhotoEditableColumn) throws EntityNotFountException {


    OfficePhoto byId = findById(companyId, officeId, id);

    copyPropertiesExceptId(byId, officePhotoEditableColumn, OfficePhotoEditableColumn.class);

    return officePhotoRepo.save(byId);

}

}

this method does update proses without using any setter methods:

we just give (target,source,editableColumsObject) :


public class EntityUtil{

public static void copyPropertiesExceptId(BaseEntity target, BaseEntity source, Class editableColumns) {

    long targetOriginalId = target.getId();

    BeanUtils.copyProperties(source, target, editableColumns);

    target.setId(targetOriginalId);

}

}

EDIT: OfficePhoto extends OfficePhotoEditableColumn

this approach using when we want to seperate editable columns from relations with other entities 

OfficePhotoEditableColumn holds editable columns for OfficePhoto

Comments

Popular posts from this blog

Installation instructions for some programs on linux ubuntu

Hibernate and Application Performance

timezone ile bagli Jackson deserializableda problem