10 |
import java.util.List; |
import java.util.List; |
11 |
import java.util.Map; |
import java.util.Map; |
12 |
|
|
|
import dk.daoas.daoadresseservice.Address; |
|
|
import dk.daoas.daoadresseservice.AddressUtils; |
|
13 |
import dk.daoas.daoadresseservice.DaekningsType; |
import dk.daoas.daoadresseservice.DaekningsType; |
14 |
import dk.daoas.daoadresseservice.ExtendedBean; |
import dk.daoas.daoadresseservice.beans.Address; |
15 |
import dk.daoas.daoadresseservice.HundredePctBean; |
import dk.daoas.daoadresseservice.beans.ExtendedBean; |
16 |
|
import dk.daoas.daoadresseservice.beans.HundredePctBean; |
17 |
|
import dk.daoas.daoadresseservice.util.DeduplicateHelper; |
18 |
|
|
19 |
public class DatabaseLayer { |
public class DatabaseLayer { |
20 |
|
|
21 |
public static List<Address> getAllAdresses() throws SQLException { |
public static List<Address> getAllAdresses() throws SQLException { |
22 |
|
|
23 |
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 " |
24 |
+ "FROM fulddaekning.adressetabel " |
+ "FROM fulddaekning.adressetabel " |
25 |
+ "WHERE postnr BETWEEN 8700 and 8899 OR POSTNR=8300" //DEBUG only |
+ "WHERE gadeid IS NOT NULL " |
26 |
|
//+ "AND postnr = 8700" //DEBUG only |
27 |
; |
; |
28 |
|
|
29 |
Connection conn = DBConnection.getConnection(); |
Connection conn = DBConnection.getConnection(); |
30 |
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); |
31 |
|
stmt.setFetchSize(Integer.MIN_VALUE); |
32 |
ResultSet res = stmt.executeQuery(sql); |
ResultSet res = stmt.executeQuery(sql); |
33 |
|
|
34 |
List<Address> list = new ArrayList<Address>(); |
List<Address> list = new ArrayList<Address>(2600000);//initial capacity 2.6 mio |
35 |
|
|
36 |
|
DeduplicateHelper<String> vejnavnCache = new DeduplicateHelper<String>(); |
37 |
|
DeduplicateHelper<String> husnrbogstavCache = new DeduplicateHelper<String>(); |
38 |
|
DeduplicateHelper<String> distributorCache = new DeduplicateHelper<String>(); |
39 |
|
DeduplicateHelper<String> korelisteCache = new DeduplicateHelper<String>(); |
40 |
|
DeduplicateHelper<String> ruteCache = new DeduplicateHelper<String>(); |
41 |
|
|
42 |
|
|
43 |
while (res.next()) { |
while (res.next()) { |
44 |
|
|
45 |
Address a = new Address(); |
Address a = new Address(); |
46 |
a.id = res.getInt(1); |
a.id = res.getInt(1); |
47 |
a.vejnavn = res.getString(2); |
a.vejnavn = vejnavnCache.getInstance( res.getString(2) ); |
48 |
a.husnr = res.getInt(3); |
a.husnr = res.getInt(3); |
49 |
a.husnrbogstav = res.getString(4); |
a.husnrbogstav = husnrbogstavCache.getInstance( res.getString(4) ); |
50 |
a.kommunekode = res.getInt(5); |
a.kommunekode = res.getInt(5); |
51 |
a.vejkode = res.getInt(6); |
a.vejkode = res.getInt(6); |
52 |
a.postnr = res.getInt(7); |
a.postnr = res.getInt(7); |
53 |
a.gadeid = res.getLong(8); |
a.gadeid = res.getLong(8); |
54 |
a.distributor = res.getString(9); |
a.distributor = distributorCache.getInstance(res.getString(9)); |
55 |
a.dbkBane = res.getInt(10); |
a.dbkBane = res.getInt(10); |
56 |
a.koreliste = res.getString(11); |
a.koreliste = korelisteCache.getInstance( res.getString(11) ); |
57 |
a.rute = res.getString(12); |
a.rute = ruteCache.getInstance( res.getString(12) ); |
58 |
|
|
59 |
a.vasketVejnavn = AddressUtils.vaskVejnavn(a.vejnavn); |
//a.vasketVejnavn = AddressUtils.vaskVejnavn(a.vejnavn); |
60 |
|
|
61 |
if (a.rute != null && a.rute.length()> 0) { |
if (a.rute != null && a.rute.length()> 0) { |
62 |
a.daekningsType = DaekningsType.DAEKNING_DIREKTE; |
a.daekningsType = DaekningsType.DAEKNING_DIREKTE; |
63 |
} else { |
} else { |
64 |
a.daekningsType = DaekningsType.DAEKNING_IKKEDAEKKET; |
a.daekningsType = DaekningsType.DAEKNING_IKKEDAEKKET; |
65 |
} |
} |
|
|
|
|
if (a.distributor != null) { |
|
|
a.distributor = a.distributor.toUpperCase(); |
|
|
} |
|
66 |
|
|
67 |
list.add(a); |
list.add(a); |
68 |
} |
} |
76 |
} |
} |
77 |
|
|
78 |
public static List<ExtendedBean> getExtendedAdresslist() throws SQLException { |
public static List<ExtendedBean> getExtendedAdresslist() throws SQLException { |
79 |
String sql = "select orgid, a.id as targetid, afstand,type from fulddaekning.afstand_anden_rute a " + |
|
80 |
|
String sql = "select orgid, a.id as targetid, afstand, LOWER(type) as type from fulddaekning.afstand_anden_rute a " + |
81 |
"join odbc.transporttype t " + |
"join odbc.transporttype t " + |
82 |
"on t.Art = 'Transpost' " + |
"on t.Art = 'Transpost' " + |
83 |
"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) ) " + |
92 |
|
|
93 |
Connection conn = DBConnection.getConnection(); |
Connection conn = DBConnection.getConnection(); |
94 |
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); |
95 |
|
stmt.setFetchSize(Integer.MIN_VALUE); |
96 |
|
|
97 |
ResultSet res = stmt.executeQuery(sql); |
ResultSet res = stmt.executeQuery(sql); |
98 |
|
|
99 |
List<ExtendedBean> list = new ArrayList<ExtendedBean>(); |
DeduplicateHelper<String> transportCache = new DeduplicateHelper<String>(); |
100 |
while (res.next()) { |
|
101 |
|
List<ExtendedBean> list = new ArrayList<ExtendedBean>( 350000); //Initial capacity 350K |
102 |
|
while (res.next()) { |
103 |
|
|
104 |
ExtendedBean eb = new ExtendedBean(); |
ExtendedBean eb = new ExtendedBean(); |
105 |
eb.orgId = res.getInt(1); |
eb.orgId = res.getInt(1); |
106 |
eb.targetId = res.getInt(2); |
eb.targetId = res.getInt(2); |
107 |
eb.afstand = res.getDouble(3); |
eb.afstand = res.getDouble(3); |
108 |
eb.transport = res.getString(4).toLowerCase(); |
eb.transport = transportCache.getInstance(res.getString(4)); |
109 |
|
|
110 |
list.add(eb); |
list.add(eb); |
111 |
} |
} |
120 |
} |
} |
121 |
|
|
122 |
public static Map<Integer,HundredePctBean> get100PctList() throws SQLException { |
public static Map<Integer,HundredePctBean> get100PctList() throws SQLException { |
123 |
String sql = "SELECT postnr,distributor,rute,koreliste,dbkbane " + |
String sql = "SELECT postnr,UPPER(distributor) as distributor,rute,koreliste,dbkbane " + |
124 |
"FROM bogleveringer.adresser_udenfor_daekning"; |
"FROM bogleveringer.adresser_udenfor_daekning"; |
125 |
|
|
126 |
Connection conn = DBConnection.getConnection(); |
Connection conn = DBConnection.getConnection(); |
129 |
|
|
130 |
Map<Integer,HundredePctBean> map = new HashMap<Integer,HundredePctBean>(); |
Map<Integer,HundredePctBean> map = new HashMap<Integer,HundredePctBean>(); |
131 |
|
|
132 |
|
DeduplicateHelper<String> distributorCache = new DeduplicateHelper<String>(); |
133 |
|
|
134 |
while (res.next()) { |
while (res.next()) { |
135 |
|
|
136 |
|
|
137 |
HundredePctBean bean = new HundredePctBean(); |
HundredePctBean bean = new HundredePctBean(); |
138 |
bean.postnr = res.getInt(1); |
bean.postnr = res.getInt(1); |
139 |
bean.distributor = res.getString(2).toUpperCase(); |
bean.distributor = distributorCache.getInstance(res.getString(2)); |
140 |
bean.rute = res.getString(3); |
bean.rute = res.getString(3); |
141 |
bean.koreliste = res.getString(4); |
bean.koreliste = res.getString(4); |
142 |
bean.dbkBane = res.getInt(5); |
bean.dbkBane = res.getInt(5); |
148 |
stmt.close(); |
stmt.close(); |
149 |
conn.close(); |
conn.close(); |
150 |
|
|
151 |
System.out.println("Loaded " + map.size() + " extendedbeans"); |
System.out.println("Loaded " + map.size() + " 100pct beans"); |
152 |
|
|
153 |
return map; |
return map; |
154 |
|
|