1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package com.totalchange.osopendata.generator;
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.sql.Connection;
27 import java.sql.DriverManager;
28 import java.sql.SQLException;
29 import java.sql.Statement;
30 import java.util.logging.Logger;
31
32 public final class Populate {
33 private static final Logger logger = Logger.getLogger(Populate.class
34 .getName());
35
36 public static void populate(String db, String codePointDir,
37 String locatorDir) throws ClassNotFoundException, SQLException,
38 IOException {
39 logger.info("Creating connection to database " + db);
40
41 Class.forName("org.hsqldb.jdbcDriver");
42 Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:" + db
43 + ";shutdown=true;hsqldb.default_table_type=cached", "SA", "");
44 conn.setAutoCommit(true);
45
46 try {
47
48
49 File codePointRoot = new File(codePointDir);
50 File csvRoot = new File(codePointRoot, "data" + File.separator
51 + "CSV");
52 File codeListFile = new File(codePointRoot, "doc" + File.separator
53 + "codelist.txt");
54 PopulateCodepoint.populate(conn, csvRoot, codeListFile);
55
56
57
58 File locatorRoot = new File(locatorDir);
59 File dataDir = new File(locatorRoot, "data");
60 PopulateLocator.populate(conn, dataDir);
61
62 Statement st = conn.createStatement();
63 try {
64 logger.info("Closing and compacting database");
65 st.execute("SHUTDOWN COMPACT");
66 } finally {
67 st.close();
68 }
69 } finally {
70 conn.close();
71 }
72
73 logger.info("Database populated and available here: "
74 + new File(db).getAbsolutePath());
75 }
76
77 public static void main(String[] args) throws Exception {
78 populate("osopendata", "C:\\Documents and Settings\\ralphj\\Desktop\\"
79 + "Misc\\OS OpenData\\Code-Point Open",
80 "C:\\Documents and Settings\\ralphj\\Desktop\\Misc\\"
81 + "OS OpenData\\OS Locator");
82 }
83 }