10 |
import java.util.List; |
import java.util.List; |
11 |
import java.util.Map; |
import java.util.Map; |
12 |
|
|
|
import dk.daoas.daoadresseservice.AddressUtils; |
|
13 |
import dk.daoas.daoadresseservice.DaekningsType; |
import dk.daoas.daoadresseservice.DaekningsType; |
14 |
import dk.daoas.daoadresseservice.beans.Address; |
import dk.daoas.daoadresseservice.beans.Address; |
15 |
import dk.daoas.daoadresseservice.beans.ExtendedBean; |
import dk.daoas.daoadresseservice.beans.ExtendedBean; |
19 |
|
|
20 |
public static List<Address> getAllAdresses() throws SQLException { |
public static List<Address> getAllAdresses() throws SQLException { |
21 |
|
|
22 |
String sql = "SELECT id,vejnavn,husnr,husnrbogstav,kommunekode,vejkode,postnr,gadeid,distributor,dbkbane,koreliste,rute " |
String sql = "SELECT id,vejnavn,husnr,husnrbogstav,kommunekode,vejkode,postnr,gadeid,upper(distributor) AS distributor,dbkbane,koreliste,rute " |
23 |
+ "FROM fulddaekning.adressetabel " |
+ "FROM fulddaekning.adressetabel " |
24 |
+ "WHERE postnr >=5000" //DEBUG only |
//+ "WHERE postnr >=2000" //DEBUG only |
25 |
; |
; |
26 |
|
|
27 |
Connection conn = DBConnection.getConnection(); |
Connection conn = DBConnection.getConnection(); |
28 |
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
29 |
ResultSet res = stmt.executeQuery(sql); |
ResultSet res = stmt.executeQuery(sql); |
30 |
|
|
31 |
List<Address> list = new ArrayList<Address>(); |
List<Address> list = new ArrayList<Address>(2600000);//initial capacity 2.6 mio |
32 |
|
|
33 |
while (res.next()) { |
while (res.next()) { |
34 |
Address a = new Address(); |
Address a = new Address(); |
51 |
a.daekningsType = DaekningsType.DAEKNING_DIREKTE; |
a.daekningsType = DaekningsType.DAEKNING_DIREKTE; |
52 |
} else { |
} else { |
53 |
a.daekningsType = DaekningsType.DAEKNING_IKKEDAEKKET; |
a.daekningsType = DaekningsType.DAEKNING_IKKEDAEKKET; |
54 |
} |
} |
|
|
|
|
if (a.distributor != null) { |
|
|
a.distributor = a.distributor.toUpperCase(); |
|
|
} |
|
55 |
|
|
56 |
list.add(a); |
list.add(a); |
57 |
} |
} |
65 |
} |
} |
66 |
|
|
67 |
public static List<ExtendedBean> getExtendedAdresslist() throws SQLException { |
public static List<ExtendedBean> getExtendedAdresslist() throws SQLException { |
68 |
String sql = "select orgid, a.id as targetid, afstand,type from fulddaekning.afstand_anden_rute a " + |
String sql = "select orgid, a.id as targetid, afstand, LOWER(type) as type from fulddaekning.afstand_anden_rute a " + |
69 |
"join odbc.transporttype t " + |
"join odbc.transporttype t " + |
70 |
"on t.Art = 'Transpost' " + |
"on t.Art = 'Transpost' " + |
71 |
"and ( (t.Type = 'Cykel' and a.Afstand < 1.001) or (t.Type = 'Scooter' and a.Afstand < 1.201) or (t.Type = 'Bil' and a.Afstand < 2.601) ) " + |
"and ( (t.Type = 'Cykel' and a.Afstand < 1.001) or (t.Type = 'Scooter' and a.Afstand < 1.201) or (t.Type = 'Bil' and a.Afstand < 2.601) ) " + |
82 |
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
83 |
ResultSet res = stmt.executeQuery(sql); |
ResultSet res = stmt.executeQuery(sql); |
84 |
|
|
85 |
List<ExtendedBean> list = new ArrayList<ExtendedBean>(); |
List<ExtendedBean> list = new ArrayList<ExtendedBean>( 350000); //Initial capacity 350K |
86 |
while (res.next()) { |
while (res.next()) { |
87 |
ExtendedBean eb = new ExtendedBean(); |
ExtendedBean eb = new ExtendedBean(); |
88 |
eb.orgId = res.getInt(1); |
eb.orgId = res.getInt(1); |
89 |
eb.targetId = res.getInt(2); |
eb.targetId = res.getInt(2); |
90 |
eb.afstand = res.getDouble(3); |
eb.afstand = res.getDouble(3); |
91 |
eb.transport = res.getString(4).toLowerCase(); |
eb.transport = res.getString(4); |
92 |
|
|
93 |
list.add(eb); |
list.add(eb); |
94 |
} |
} |
103 |
} |
} |
104 |
|
|
105 |
public static Map<Integer,HundredePctBean> get100PctList() throws SQLException { |
public static Map<Integer,HundredePctBean> get100PctList() throws SQLException { |
106 |
String sql = "SELECT postnr,distributor,rute,koreliste,dbkbane " + |
String sql = "SELECT postnr,UPPER(distributor) as distributor,rute,koreliste,dbkbane " + |
107 |
"FROM bogleveringer.adresser_udenfor_daekning"; |
"FROM bogleveringer.adresser_udenfor_daekning"; |
108 |
|
|
109 |
Connection conn = DBConnection.getConnection(); |
Connection conn = DBConnection.getConnection(); |
116 |
|
|
117 |
HundredePctBean bean = new HundredePctBean(); |
HundredePctBean bean = new HundredePctBean(); |
118 |
bean.postnr = res.getInt(1); |
bean.postnr = res.getInt(1); |
119 |
bean.distributor = res.getString(2).toUpperCase(); |
bean.distributor = res.getString(2); |
120 |
bean.rute = res.getString(3); |
bean.rute = res.getString(3); |
121 |
bean.koreliste = res.getString(4); |
bean.koreliste = res.getString(4); |
122 |
bean.dbkBane = res.getInt(5); |
bean.dbkBane = res.getInt(5); |
128 |
stmt.close(); |
stmt.close(); |
129 |
conn.close(); |
conn.close(); |
130 |
|
|
131 |
System.out.println("Loaded " + map.size() + " extendedbeans"); |
System.out.println("Loaded " + map.size() + " 100pct beans"); |
132 |
|
|
133 |
return map; |
return map; |
134 |
|
|