private void writePOI ( long id , double latitude , double longitude , Map < String , String > poiData , Set < PoiCategory > categories ) { try { // Index data this . pStmtIndex . setLong ( 1 , id ) ; this . pStmtIndex . setDouble ( 2 , latitude ) ; this . pStmtIndex . setDouble ( 3 , latitude ) ; this . pStmtIndex . setDouble ( 4 , longitude ) ; this . pStmtIndex . setDouble ( 5 , longitude ) ; this . pStmtIndex . addBatch ( ) ; // POI data this . pStmtData . setLong ( 1 , id ) ; if ( this . configuration . isAllTags ( ) ) { // All tags should be written to DB this . pStmtData . setString ( 2 , tagsToString ( poiData ) ) ; } else { // Use preferred language boolean foundPreferredLanguageName = false ; String name = null ; for ( String key : poiData . keySet ( ) ) { if ( "name" . equals ( key ) && ! foundPreferredLanguageName ) { name = poiData . get ( key ) ; } else if ( this . configuration . getPreferredLanguage ( ) != null && ! foundPreferredLanguageName ) { Matcher matcher = NAME_LANGUAGE_PATTERN . matcher ( key ) ; if ( matcher . matches ( ) ) { String language = matcher . group ( 3 ) ; if ( language . equalsIgnoreCase ( this . configuration . getPreferredLanguage ( ) ) ) { name = poiData . get ( key ) ; foundPreferredLanguageName = true ; } } } } // If name tag is set if ( name != null ) { this . pStmtData . setString ( 2 , name ) ; } else { this . pStmtData . setNull ( 2 , Types . NULL ) ; } } this . pStmtData . addBatch ( ) ; // Categories data this . pStmtCatMap . setLong ( 1 , id ) ; for ( PoiCategory category : categories ) { this . pStmtCatMap . setInt ( 2 , category . getID ( ) ) ; this . pStmtCatMap . addBatch ( ) ; } if ( this . poiAdded % BATCH_LIMIT == 0 ) { this . pStmtIndex . executeBatch ( ) ; this . pStmtData . executeBatch ( ) ; this . pStmtCatMap . executeBatch ( ) ; this . pStmtIndex . clearBatch ( ) ; this . pStmtData . clearBatch ( ) ; this . pStmtCatMap . clearBatch ( ) ; } } catch ( SQLException e ) { e . printStackTrace ( ) ; } }
Write a POI to the database .