epgtools.epgdbbean.bean.channel.ChannelGetter.java Source code

Java tutorial

Introduction

Here is the source code for epgtools.epgdbbean.bean.channel.ChannelGetter.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 epgtools.epgdbbean.bean.channel;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanMapHandler;

/**
 * DB?????????
 *
 * @author dosdiaopfhj
 */
public class ChannelGetter {

    private final QueryRunner runner = new QueryRunner();
    private final Connection con;

    /**
     * SQL? ????? ??????ID???????????????????
     * ?????????????????ID??????????
     */
    public static final String GET_CHANNELS = "SELECT * FROM useablechannels ORDER BY channel_no";

    /**
     * @param con DB??
     */
    public ChannelGetter(Connection con) {
        this.con = con;
    }

    /**
     * DB?????????
     *
     * @return ??????(??) ?????
     * @throws java.sql.SQLException
     */
    public synchronized Map<Integer, Useablechannels_ReadOnly> getChannels() throws SQLException {
        //?
        Map<Integer, Useablechannels> Channels;
        Channels = Collections.synchronizedMap(runner.query(con, ChannelGetter.GET_CHANNELS,
                new BeanMapHandler<Integer, Useablechannels>(Useablechannels.class, "channel_no")));
        Map<Integer, Useablechannels_ReadOnly> Channels_Ro;
        Channels_Ro = Collections.synchronizedMap(new TreeMap<Integer, Useablechannels_ReadOnly>());
        Channels_Ro.putAll(Channels);
        return Collections.unmodifiableMap(Channels_Ro);
    }

}