58 |
conn.createStatement().executeUpdate(sql); |
conn.createStatement().executeUpdate(sql); |
59 |
} |
} |
60 |
|
|
61 |
public BoundingBox getBoundingbox(int postnr) throws SQLException { |
public BoundingBox getBoundingbox(String postnr) throws SQLException { |
62 |
|
String minPostnr = postnr.replace('x', '0'); |
63 |
|
String maxPostnr = postnr.replace('x', '9'); |
64 |
|
|
65 |
String sql = |
String sql = |
66 |
"SELECT max(latitude) latmax, min(latitude) latmin, max(longitude) lngmax,min(longitude) lngmin " + |
"SELECT max(latitude) latmax, min(latitude) latmin, max(longitude) lngmax,min(longitude) lngmin " + |
67 |
"FROM fulddaekning.adressetabel WHERE postnr=? and rute is null;"; |
"FROM fulddaekning.adressetabel WHERE postnr BETWEEN ? and ? and rute is null;"; |
68 |
|
|
69 |
PreparedStatement stmt = conn.prepareStatement(sql); |
PreparedStatement stmt = conn.prepareStatement(sql); |
70 |
stmt.setInt(1, postnr); |
stmt.setString(1, minPostnr); |
71 |
|
stmt.setString(2, maxPostnr); |
72 |
|
|
73 |
ResultSet res = stmt.executeQuery(); |
ResultSet res = stmt.executeQuery(); |
74 |
res.next(); //query returnerer altid 1 række |
res.next(); //query returnerer altid 1 række |
85 |
return bbox; |
return bbox; |
86 |
} |
} |
87 |
|
|
88 |
public Queue<Adresse> hentIkkedaekkedeAdresser(int postnr) throws SQLException { |
public Queue<Adresse> hentIkkedaekkedeAdresser(String postnr) throws SQLException { |
89 |
|
|
90 |
|
String minPostnr = postnr.replace('x', '0'); |
91 |
|
String maxPostnr = postnr.replace('x', '9'); |
92 |
|
|
93 |
ConcurrentLinkedQueue<Adresse> queue = new ConcurrentLinkedQueue<Adresse>(); |
ConcurrentLinkedQueue<Adresse> queue = new ConcurrentLinkedQueue<Adresse>(); |
94 |
|
|
95 |
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
96 |
"FROM fulddaekning.adressetabel a " + |
"FROM fulddaekning.adressetabel a " + |
97 |
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
98 |
"WHERE rute IS NULL " + //Ingen dækning |
"WHERE rute IS NULL " + //Ingen dækning |
99 |
"AND a.postnr=? " + |
"AND a.postnr BETWEEN ? AND ? " + |
100 |
"AND latitude IS NOT NULL " + |
"AND latitude IS NOT NULL " + |
101 |
"AND longitude IS NOT NULL " + |
"AND longitude IS NOT NULL " + |
102 |
"AND gadeid IS NOT NULL "; |
"AND gadeid IS NOT NULL " + |
103 |
|
"AND (a.distributor IS NULL OR a.distributor<>'LUKKET') "; |
104 |
PreparedStatement stmt = conn.prepareStatement(sql); |
PreparedStatement stmt = conn.prepareStatement(sql); |
105 |
stmt.setInt(1, postnr); |
stmt.setString(1, minPostnr); |
106 |
|
stmt.setString(2, maxPostnr); |
107 |
|
|
108 |
queue.addAll( hentAdresseListe( stmt ) ); |
queue.addAll( hentAdresseListe( stmt ) ); |
109 |
return queue; |
return queue; |
110 |
} |
} |
111 |
|
|
112 |
public List<Integer> hentPostnumre() throws SQLException { |
public List<String> hentPostnumre() throws SQLException { |
113 |
ArrayList<Integer> list = new ArrayList<Integer>(); |
ArrayList<String> list = new ArrayList<String>(); |
114 |
|
|
115 |
Constants consts = Constants.getInstance(); |
Constants consts = Constants.getInstance(); |
116 |
|
|
117 |
|
/* |
118 |
String sql = "SELECT postnr " + |
String sql = "SELECT postnr " + |
119 |
"FROM fulddaekning.adressetabel " + |
"FROM fulddaekning.adressetabel " + |
|
//"WHERE distributor = ? and rute is not null " + |
|
120 |
"WHERE postnr BETWEEN ? AND ? " + |
"WHERE postnr BETWEEN ? AND ? " + |
121 |
|
"AND rute is null " + // Træk kun liste på postnumre hvor der er ikke-dækkede adresser |
122 |
"GROUP BY postnr " + |
"GROUP BY postnr " + |
123 |
"ORDER by postnr"; |
"ORDER by postnr"; |
124 |
|
*/ |
125 |
|
|
126 |
|
|
127 |
|
String sql = "SELECT rpad(left(postnr,?),'4', 'x') as postnr2 " + |
128 |
|
"FROM fulddaekning.adressetabel " + |
129 |
|
"WHERE postnr BETWEEN ? AND ? " + |
130 |
|
"AND rute is null " + // Trae kun liste paa postnumre hvor der er ikke-daekede adresser |
131 |
|
"AND (postnr NOT BETWEEN 3900 and 3999) " + //Skip alle groenlandske postnumre |
132 |
|
"GROUP BY postnr2 " + |
133 |
|
"ORDER by postnr2 "; |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
PreparedStatement stmt = conn.prepareStatement(sql); |
PreparedStatement stmt = conn.prepareStatement(sql); |
138 |
//stmt.setString(1, Lookup.distributor ); |
//stmt.setString(1, Lookup.distributor ); |
139 |
stmt.setInt(1, consts.getMinPostnr()); |
|
140 |
stmt.setInt(2, consts.getMaxPostnr()); |
stmt.setInt(1, consts.getPostnrGroup() ); |
141 |
|
|
142 |
|
stmt.setInt(2, consts.getMinPostnr()); |
143 |
|
stmt.setInt(3, consts.getMaxPostnr()); |
144 |
ResultSet res = stmt.executeQuery(); |
ResultSet res = stmt.executeQuery(); |
145 |
|
|
146 |
while (res.next()) { |
while (res.next()) { |
147 |
int postnr = res.getInt("postnr"); |
String postnr = res.getString("postnr2"); |
148 |
list.add(postnr); |
list.add(postnr); |
149 |
} |
} |
150 |
res.close(); |
res.close(); |
174 |
stmt.setDouble(2, bbox.latitudeMax); |
stmt.setDouble(2, bbox.latitudeMax); |
175 |
stmt.setDouble(3, bbox.longitudeMin); |
stmt.setDouble(3, bbox.longitudeMin); |
176 |
stmt.setDouble(4, bbox.longitudeMax); |
stmt.setDouble(4, bbox.longitudeMax); |
177 |
stmt.setString(5, Lookup.distributor); |
stmt.setString(5, LookupMain.distributor); |
178 |
|
|
179 |
List<Adresse> list = hentAdresseListe( stmt ); |
List<Adresse> list = hentAdresseListe( stmt ); |
180 |
return list.toArray( new Adresse[ list.size() ] ); |
return list.toArray( new Adresse[ list.size() ] ); |
196 |
PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
197 |
stmt.setFetchSize(Integer.MIN_VALUE); |
stmt.setFetchSize(Integer.MIN_VALUE); |
198 |
|
|
199 |
stmt.setString(1, Lookup.distributor); |
stmt.setString(1, LookupMain.distributor); |
200 |
|
|
201 |
List<Adresse> list = hentAdresseListe( stmt ); |
List<Adresse> list = hentAdresseListe( stmt ); |
202 |
return list.toArray( new Adresse[ list.size() ] ); |
return list.toArray( new Adresse[ list.size() ] ); |