private void filterCategories ( ) throws SQLException { LOGGER . info ( "Filtering categories..." ) ; PreparedStatement pStmtChildren = this . conn . prepareStatement ( "SELECT COUNT(*) FROM poi_categories WHERE parent = ?;" ) ; PreparedStatement pStmtPoi = this . conn . prepareStatement ( "SELECT COUNT(*) FROM poi_category_map WHERE category = ?;" ) ; PreparedStatement pStmtDel = this . conn . prepareStatement ( "DELETE FROM poi_categories WHERE id = ?;" ) ; Statement stmt = this . conn . createStatement ( ) ; ResultSet rs = stmt . executeQuery ( "SELECT id FROM poi_categories ORDER BY id;" ) ; while ( rs . next ( ) ) { int id = rs . getInt ( 1 ) ; pStmtChildren . setInt ( 1 , id ) ; ResultSet rsChildren = pStmtChildren . executeQuery ( ) ; if ( rsChildren . next ( ) ) { long nChildren = rsChildren . getLong ( 1 ) ; if ( nChildren == 0 ) { pStmtPoi . setInt ( 1 , id ) ; ResultSet rsPoi = pStmtPoi . executeQuery ( ) ; if ( rsPoi . next ( ) ) { long nPoi = rsPoi . getLong ( 1 ) ; // If category not have POI, delete it from DB if ( nPoi == 0 ) { pStmtDel . setInt ( 1 , id ) ; pStmtDel . executeUpdate ( ) ; } } } } } }
Filter categories i . e . without POIs and children .