private void prepareDatabase ( ) throws ClassNotFoundException , SQLException , UnknownPoiCategoryException { Class . forName ( "org.sqlite.JDBC" ) ; this . conn = DriverManager . getConnection ( "jdbc:sqlite:" + this . configuration . getOutputFile ( ) . getAbsolutePath ( ) ) ; this . conn . setAutoCommit ( false ) ; Statement stmt = this . conn . createStatement ( ) ; // Create tables stmt . execute ( DbConstants . DROP_WAYNODES_STATEMENT ) ; stmt . execute ( DbConstants . DROP_NODES_STATEMENT ) ; stmt . execute ( DbConstants . DROP_METADATA_STATEMENT ) ; stmt . execute ( DbConstants . DROP_INDEX_STATEMENT ) ; stmt . execute ( DbConstants . DROP_CATEGORY_MAP_STATEMENT ) ; stmt . execute ( DbConstants . DROP_DATA_STATEMENT ) ; stmt . execute ( DbConstants . DROP_CATEGORIES_STATEMENT ) ; stmt . execute ( DbConstants . CREATE_CATEGORIES_STATEMENT ) ; stmt . execute ( DbConstants . CREATE_DATA_STATEMENT ) ; stmt . execute ( DbConstants . CREATE_CATEGORY_MAP_STATEMENT ) ; stmt . execute ( DbConstants . CREATE_INDEX_STATEMENT ) ; stmt . execute ( DbConstants . CREATE_METADATA_STATEMENT ) ; stmt . execute ( DbConstants . CREATE_NODES_STATEMENT ) ; stmt . execute ( DbConstants . CREATE_WAYNODES_STATEMENT ) ; this . pStmtCatMap = this . conn . prepareStatement ( DbConstants . INSERT_CATEGORY_MAP_STATEMENT ) ; this . pStmtData = this . conn . prepareStatement ( DbConstants . INSERT_DATA_STATEMENT ) ; this . pStmtIndex = this . conn . prepareStatement ( DbConstants . INSERT_INDEX_STATEMENT ) ; this . pStmtNodesC = this . conn . prepareStatement ( DbConstants . INSERT_NODES_STATEMENT ) ; this . pStmtNodesR = this . conn . prepareStatement ( DbConstants . FIND_NODES_STATEMENT ) ; this . pStmtWayNodesR = this . conn . prepareStatement ( DbConstants . FIND_WAYNODES_BY_ID_STATEMENT ) ; // Insert categories PreparedStatement pStmt = this . conn . prepareStatement ( DbConstants . INSERT_CATEGORIES_STATEMENT ) ; PoiCategory root = this . categoryManager . getRootCategory ( ) ; pStmt . setLong ( 1 , root . getID ( ) ) ; pStmt . setString ( 2 , root . getTitle ( ) ) ; pStmt . setNull ( 3 , 0 ) ; pStmt . addBatch ( ) ; Stack < PoiCategory > children = new Stack <> ( ) ; children . push ( root ) ; while ( ! children . isEmpty ( ) ) { for ( PoiCategory c : children . pop ( ) . getChildren ( ) ) { pStmt . setLong ( 1 , c . getID ( ) ) ; pStmt . setString ( 2 , c . getTitle ( ) ) ; pStmt . setInt ( 3 , c . getParent ( ) . getID ( ) ) ; pStmt . addBatch ( ) ; children . push ( c ) ; } } pStmt . executeBatch ( ) ; this . conn . commit ( ) ; }
Prepare database .