FileDao.java 1.74 KB
package vion.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import vion.model.Account;
import vion.model.File;
import vion.model.Store;

import java.util.List;

@Repository
public class FileDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    private static final String SELECT_FILE_ALL = "SELECT * FROM tbl_file_info";

    public List<File> getFileAll() {
        return jdbcTemplate.query(SELECT_FILE_ALL, new BeanPropertyRowMapper<File>(File.class));
    }

    private static final String SELECT_FILE_BY_SOURCEID = "SELECT * FROM tbl_file_info where store_id=? and source_id=?";

    public List<File> getFileBySourceId(Integer store_id,Integer source_id) {
        return jdbcTemplate.query(SELECT_FILE_BY_SOURCEID,new Object[]{store_id,source_id},
                new BeanPropertyRowMapper<File>(File.class));
    }
/*

    private static final String SAVE_FILE= "INSERT INTO tbl_file_info(\n" +
            "            store_id, type, source_type, source_id, name, url)\n" +
            "    VALUES (?, ?, ?, ?, ?, ?);";

    public Integer addFile(File file) {
        return jdbcTemplate.update(SAVE_FILE,
                new Object[]{file.getStore_id(),file.getType(),file.getSource_type(),
                        file.getSource_id(),file.getName(),file.getUrl()});
    }

    private static final String UPDATE_FILE= "UPDATE tbl_file_info\n" +
            "   SET store_id=? WHERE source_id=?";

    public Integer updateFileStoreid(File file) {
        return jdbcTemplate.update(UPDATE_FILE,
                new Object[]{file.getStore_id(),file.getSource_id()});
    }*/
}