/** * Converts all files with .xml.gz and .xml extensions from specified directory into database. * * @throws XMLStreamException Thrown if problem occurred while reading XML stream. * @throws SQLException Thrown if problem occurred while communicating with database. */ public static void convert() throws XMLStreamException, SQLException { final long startTimestamp = System.currentTimeMillis(); try (final Connection con = DriverManager.getConnection(Config.getDbConnectionUrl())) { exchangeFormatConvertor = new ExchangeFormatConvertor(con); specialExchangeFormatConvertor = new SpecialExchangeFormatConvertor(con); con.setAutoCommit(false); if (Config.isCreateTables()) { Log.write("Recreating tables..."); if (Config.isNoGis() || Config.isMysqlDriver()) { if (Config.isMysqlDriver()) { runSQLFromResource(con, "/sql/schema_no_gis_mysql_tbl.sql"); } else { runSQLFromResource(con, "/sql/schema_no_gis_tbl.sql"); } } else { runSQLFromResource(con, "/sql/schema_tbl.sql"); } } if (!Config.isNoGis() && !Config.isMysqlDriver()) { Log.write("Recreating RÚIAN statistics views..."); runSQLFromResource(con, "/sql/ruian_stats.sql"); runSQLFromResource(con, "/sql/ruian_stats_full.sql"); } if (Config.isTruncateAll()) { Log.write("Truncating all data tables..."); runSQLFromResource(con, "/sql/truncate_all.sql"); } if (Config.isResetTransactionIds()) { Log.write("Resetting transaction ids..."); runSQLFromResource(con, "/sql/reset_transaction_ids.sql"); } if (!Config.isNoGis() && !Config.isMysqlDriver() && !Config.isConvertToEWKT() && GMLUtils.checkMultipointBug(con)) { Log.write( "Installed version of Postgis is affected by " + "multipoint bug " + "http://trac.osgeo.org/postgis/ticket/1928, enabling " + "workaround..."); GMLUtils.setMultipointBugWorkaround(true); } con.commit(); for (final Path file : getInputFiles(Config.getInputDirPath())) { processFile(file); con.commit(); } if (Config.isCreateTables()) { Log.write("Creating indexes..."); if (Config.isNoGis() || Config.isMysqlDriver()) { if (Config.isMysqlDriver()) { runSQLFromResource(con, "/sql/schema_no_gis_mysql_idx.sql"); } else { runSQLFromResource(con, "/sql/schema_no_gis_idx.sql"); } } else { runSQLFromResource(con, "/sql/schema_idx.sql"); } } Log.write("Total duration: " + (System.currentTimeMillis() - startTimestamp) + " ms"); } }