private < E extends Entity > void copyEntityToSql ( Iterable < E > entities , Table table ) throws SQLException { table . createSqlTable ( connection , namespace , true ) ; String entityInsertSql = table . generateInsertSql ( namespace , true ) ; PreparedStatement insertStatement = connection . prepareStatement ( entityInsertSql ) ; // Iterate over agencies and add to prepared statement int count = 0 , batchSize = 0 ; for ( E entity : entities ) { entity . setStatementParameters ( insertStatement , true ) ; insertStatement . addBatch ( ) ; count ++ ; batchSize ++ ; // FIXME: Add batching execute on n if ( batchSize > JdbcGtfsLoader . INSERT_BATCH_SIZE ) { insertStatement . executeBatch ( ) ; batchSize = 0 ; } } // Handle remaining insertStatement . executeBatch ( ) ; LOG . info ( "Inserted {} {}" , count , table . name ) ; // FIXME: Should some tables not have indexes? table . createIndexes ( connection , namespace ) ; }
Creates table for the specified Table inserts all entities for the iterable in batches and finally creates indexes on the table .