Subversion Repository Public Repository

TransPort_Tracking

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.transtracking.dao.impl;

import com.bestray.transtracking.dao.CountryDao;
import com.bestray.transtracking.dao.mapper.CountryResultSetExtractor;
import com.bestray.transtracking.dao.mapper.StateResultSetExtractor;
import com.bestray.trastrack.domain.Country;
import com.bestray.trastrack.domain.State;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *
 * @author Girija Sahu
 */
public class CountryDaoImpl implements CountryDao {
 private DataSource ds;
    public CountryDaoImpl(DataSource ds) {
        this.ds = ds;
    }

    public List<Country> getCountyList() throws Exception{
         JdbcTemplate template = new JdbcTemplate(ds);
        String query = "Select id,name from country ";
       List<Country> countryList = (List<Country>) template.query(query, new CountryResultSetExtractor());
        return countryList;
    }

    public List<State> getStateList() throws Exception{
        JdbcTemplate template = new JdbcTemplate(ds);
        String query = "Select id,name from state order by name ";
       List<State> stateList = (List<State>) template.query(query, new StateResultSetExtractor());
        return stateList;
    }

    public Country getCountryById(Long countryId)throws Exception {
        JdbcTemplate template = new JdbcTemplate(ds);
        String query = "Select id,name from country where id =?";
       List<Country> countryList = (List<Country>) template.query(query, new Object[]{countryId},new CountryResultSetExtractor());
        return countryList.size()>0?countryList.get(0):null;
    }

    public State getStateById(Long stateId)throws Exception {
         JdbcTemplate template = new JdbcTemplate(ds);
        String query = "Select id,name from state where id =?";
       List<State> stateList = (List<State>) template.query(query,new Object[]{stateId} , new StateResultSetExtractor());
       return stateList.size()>0?stateList.get(0):null;
    }
    
}

Commits for TransPort_Tracking/TransPortTracking/src/main/java/com/bestray/transtracking/dao/impl/CountryDaoImpl.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Sat 28 Jul, 2018 05:29:14 +0000