service.DataLinkService.java Source code

Java tutorial

Introduction

Here is the source code for service.DataLinkService.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import entity.DataLink;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import persistence.DataLinkDao;
import service.parent.PrimService;
import support.ServiceResult;

/**
 * ??  ??  ?    
 * @author Rice Pavel
 */
@Service
public class DataLinkService extends PrimService {

    @Autowired
    private DataLinkDao dataLinkDao;

    /**
     * ? ??  ?    
     * @param oldId ? 
     * @param oldName  ?   -  
     * @param newId  
     * @param newCl ??  ??. ? ?? ??? -  ?? ? ??.
     */
    public void saveLink(Long oldId, String oldName, Long newId, Class newCl) {
        DataLink link = new DataLink();
        link.setOldId(oldId);
        link.setNewId(newId);
        link.setOldModelName(oldName);
        link.setNewModelName(getNameByClass(newCl));
        dataLinkDao.save(link);
    }

    /**
     * ??   ? 
     * @param oldId ? 
     * @param oldName  ? 
     * @return 
     */
    public boolean existOldId(Long oldId, String oldName) {
        return (getNewId(oldId, oldName) != null);
    }

    /**
     *     ?
     * @param oldId ? 
     * @param oldName  ?   -  
     * @param newCl ??  ??
     * @return id  null
     */
    public Long getNewId(Long oldId, String oldName) {
        DataLink link = dataLinkDao.getByParams(oldId, oldName);
        if (link != null) {
            return link.getNewId();
        }
        return null;
    }

    public List<DataLink> getByName(String oldModelName) {
        return dataLinkDao.getByName(oldModelName);
    }

    public List<DataLink> getAll() {
        return dataLinkDao.getAll();
    }

    public ServiceResult delete(Long id) {
        DataLink link = dataLinkDao.find(id);
        return _delete(link, dataLinkDao);
    }

    public ServiceResult delete(DataLink link) {
        return _delete(link, dataLinkDao);
    }

    private String getNameByClass(Class cl) {
        return cl.getCanonicalName();
    }

}