gt: 		final String keyword = _station.getKeyword();
context: /**
   This file is part of Windroid.
  
   Windroid is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
  
   Windroid is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the GNU General Public License
   along with Windroid.  If not, see <http://www.gnu.org/licenses/>.
  
   */
  package de.macsystems.windroid.db.sqlite;
  
  import java.util.Iterator;
  
  import android.database.Cursor;
  import android.database.SQLException;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteStatement;
  import android.util.Log;
  import de.macsystems.windroid.Logging;
  import de.macsystems.windroid.common.SpotConfigurationVO;
  import de.macsystems.windroid.db.DBException;
  import de.macsystems.windroid.db.ISpotDAO;
  import de.macsystems.windroid.identifyable.Continent;
  import de.macsystems.windroid.identifyable.Country;
  import de.macsystems.windroid.identifyable.IdentifyAble;
  import de.macsystems.windroid.identifyable.Region;
  import de.macsystems.windroid.identifyable.Schedule;
  import de.macsystems.windroid.identifyable.Station;
  import de.macsystems.windroid.identifyable.World;
  import de.macsystems.windroid.io.IOUtils;
  import de.macsystems.windroid.progress.IProgress;
  import de.macsystems.windroid.progress.NullProgressAdapter;
  
  /**
   * 
   * @author Jens Hohl
   * @version $Id$
   */
  public final class SpotImpl extends BaseImpl implements ISpotDAO
  {
  
  	private final static String LOG_TAG = SpotImpl.class.getSimpleName();
  
  	private final static String INSERT_SPOT = "INSERT INTO spot "
  			+ "(spotid,continentid,countryid,regionid,name,keyword,superforecast,report,forecast,statistic,wavereport,waveforecast) "
  			+ "values (?,?,?,?,?,?,?,?,?,?,?,?);";
  	private final static String INSERT_CONTINENT = "INSERT INTO continent (id,name) values (?,?);";
  	private final static String INSERT_COUNTRY = "INSERT INTO country (id,name,continentid) values (?,?,?);";
  	private final static String INSERT_REGION = "INSERT INTO region (id,name,countryid) values (?,?,?);";
  
  	/**
  	 * 
  	 * @param _database
  	 * @throws NullPointerException
  	 */
  	public SpotImpl(final Database _database) throws NullPointerException
  	{
  		this(_database, NullProgressAdapter.INSTANCE);
  	}
  
  	/**
  	 * 
  	 * @param _database
  	 * @param _progress
  	 * @throws NullPointerException
  	 */
  	public SpotImpl(final Database _database, final IProgress _progress) throws NullPointerException
  	{
  		super(_database, "spot", _progress);
  	}
  
  	/*
  	 * (non-Javadoc)
  	 * 
  	 * @see de.macsystems.windroid.db.ISpotDAO#insertSpots()
  	 */
  	public void insertSpots(final World _world)
  	{
  		if (Logging.isEnabled)
  		{
  			Log.d(LOG_TAG, "executeInsert");
  		}
  
  		if (_world == null)
  		{
  			throw new NullPointerException("world");
  		}
  
  		final int PROGRESS = 100;
  		final SQLiteDatabase db = getWritableDatabase();
  		final SQLiteStatement insertSpotStatement = db.compileStatement(INSERT_SPOT);
  		final SQLiteStatement insertContinentStatement = db.compileStatement(INSERT_CONTINENT);
  		final SQLiteStatement insertCountryStatement = db.compileStatement(INSERT_COUNTRY);
  		final SQLiteStatement insertRegionStatement = db.compileStatement(INSERT_REGION);
  
  		final long start = System.currentTimeMillis();
  		db.beginTransaction();
  		int index = 0;
  		try
  		{
  			for (final Continent continent : _world)
  			// for (final Continent continent : Continent.values())
  			{
  				updateContinentTable(insertContinentStatement, continent);
  				insertContinentStatement.executeInsert();
  
  				final Iterator<Country> countrys = continent.iterator();
  				while (countrys.hasNext())
  				{
  					final Country country = countrys.next();
  					updateCountryTable(insertCountryStatement, country, continent);
  					insertCountryStatement.executeInsert();
  
  					if (Thread.currentThread().isInterrupted())
  					{
  						throw new RuntimeException("Thread interrupted while insert.");
  					}
  
  					for (final Region region : country)
  					{
  						updateRegionTable(insertRegionStatement, region, country);
  						insertRegionStatement.executeInsert();
  
  						for (final Station station : region)
  						{
  							updateSpotTable(insertSpotStatement, continent, country, region, station);
  							insertSpotStatement.executeInsert();
  							index++;
  							if (index % PROGRESS == 0)
  							{
  								getProgress().incrementBy(PROGRESS);
  							}
  						}
  					}
  				}
  			}
  			db.setTransactionSuccessful();
  		}
  		catch (final SQLException e)
  		{
  			Log.e(LOG_TAG, "Failed to insert Spots", e);
  			throw e;
  		}
  		finally
  		{
  			db.endTransaction();
  			IOUtils.close(insertSpotStatement);
  			IOUtils.close(insertCountryStatement);
  			IOUtils.close(insertRegionStatement);
  			IOUtils.close(insertContinentStatement);
  			IOUtils.close(db);
  			if (Logging.isEnabled)
  			{
  				final long time = System.currentTimeMillis() - start;
  				Log.d(LOG_TAG, "Insert finished. Time " + time + " ms");
  			}
  		}
  
  	}
  
  	/**
  	 * 
  	 * @param insertStatement
  	 * @param country
  	 * @param continent
  	 */
  	private final static void updateCountryTable(final SQLiteStatement insertStatement, final Country country,
  			final Continent continent)
  	{
  		insertStatement.bindString(1, country.getId());
  		insertStatement.bindString(2, country.getName());
  		insertStatement.bindString(3, continent.getId());
  	}
  
  	/**
  	 * 
  	 * @param insertStatement
  	 * @param region
  	 * @param county
  	 */
  	private final static void updateRegionTable(final SQLiteStatement insertStatement, final Region region,
  			final Country county)
  	{
  		insertStatement.bindString(1, region.getId());
  		insertStatement.bindString(2, region.getName());
  		insertStatement.bindString(3, county.getId());
  	}
  
  	/**
  	 * @param insertStatement
  	 * @param continent
  	 * @param region
  	 * @param station
  	 */
  	private final static void updateContinentTable(final SQLiteStatement insertStatement, final Continent continent)
  	{
  		insertStatement.bindString(1, continent.getId());
  		insertStatement.bindString(2, continent.getName());
  	}
  
  	/**
  	 * 
  	 * @param _insertStatement
  	 * @param _continent
  	 * @param _country
  	 * @param _region
  	 * @param _station
  	 */
  	private final static void updateSpotTable(final SQLiteStatement _insertStatement, final IdentifyAble _continent,
  			final IdentifyAble _country, final IdentifyAble _region, final Station _station)
  	{
  		final String spotID = _station.getId();
  		final String continentID = _continent.getId();
  		final String countryID = _country.getId();
  		final String regionID = _region.getId();
  		final String name = _station.getName();
  