@Override
  @SuppressWarnings("ValueOfIncrementOrDecrementUsed")
  protected void fill(final PreparedStatement pstm, final Pou item, final boolean update)
      throws SQLException {
    final PreparedStatementEx pstmEx = new PreparedStatementEx(pstm);
    int index = 1;
    pstm.setString(index++, item.getNazev());
    pstmEx.setBoolean(index++, item.getNespravny());
    pstm.setInt(index++, item.getOrpKod());
    pstm.setInt(index++, item.getSpravniObecKod());
    pstm.setLong(index++, item.getIdTransRuian());
    pstmEx.setDate(index++, item.getPlatiOd());
    pstm.setLong(index++, item.getNzIdGlobalni());
    pstmEx.setBoolean(index++, item.getZmenaGrafiky());

    if (!Config.isNoGis()) {
      pstm.setString(index++, item.getDefinicniBod());
      pstm.setString(index++, item.getHranice());
    }

    pstm.setInt(index++, item.getKod());

    if (update) {
      pstmEx.setLong(index++, item.getIdTransRuian());
    }
  }
  /**
   * Runs SQL statements from specified resource.
   *
   * @param con database connection
   * @param resourceName name of the resource from which to read the SQL statements
   */
  private static void runSQLFromResource(final Connection con, final String resourceName) {
    if (Config.isDryRun()) {
      return;
    }

    final StringBuilder sbSQL = new StringBuilder(10_240);

    try (final BufferedReader reader =
            new BufferedReader(
                new InputStreamReader(
                    MainConvertor.class.getResourceAsStream(resourceName), "UTF-8"));
        final Statement stm = con.createStatement()) {
      String line = reader.readLine();

      while (line != null) {
        sbSQL.append(line);

        if (line.endsWith(";")) {
          stm.execute(sbSQL.toString());
          sbSQL.setLength(0);
        } else {
          sbSQL.append('\n');
        }

        line = reader.readLine();
      }
    } catch (final SQLException ex) {
      throw new RuntimeException("Statement failed: " + sbSQL.toString(), ex);
    } catch (final IOException ex) {
      throw new RuntimeException("Failed to read SQL statements from resource", ex);
    }
  }
  /**
   * Converts all files with .xml.gz and .xml extensions from specified directory into database.
   *
   * @throws XMLStreamException Thrown if problem occurred while reading XML stream.
   * @throws SQLException Thrown if problem occurred while communicating with database.
   */
  public static void convert() throws XMLStreamException, SQLException {
    final long startTimestamp = System.currentTimeMillis();

    try (final Connection con = DriverManager.getConnection(Config.getDbConnectionUrl())) {
      exchangeFormatConvertor = new ExchangeFormatConvertor(con);
      specialExchangeFormatConvertor = new SpecialExchangeFormatConvertor(con);

      con.setAutoCommit(false);

      if (Config.isCreateTables()) {
        Log.write("Recreating tables...");

        if (Config.isNoGis() || Config.isMysqlDriver()) {
          if (Config.isMysqlDriver()) {
            runSQLFromResource(con, "/sql/schema_no_gis_mysql_tbl.sql");
          } else {
            runSQLFromResource(con, "/sql/schema_no_gis_tbl.sql");
          }
        } else {
          runSQLFromResource(con, "/sql/schema_tbl.sql");
        }
      }

      if (!Config.isNoGis() && !Config.isMysqlDriver()) {
        Log.write("Recreating RÚIAN statistics views...");
        runSQLFromResource(con, "/sql/ruian_stats.sql");
        runSQLFromResource(con, "/sql/ruian_stats_full.sql");
      }

      if (Config.isTruncateAll()) {
        Log.write("Truncating all data tables...");
        runSQLFromResource(con, "/sql/truncate_all.sql");
      }

      if (Config.isResetTransactionIds()) {
        Log.write("Resetting transaction ids...");
        runSQLFromResource(con, "/sql/reset_transaction_ids.sql");
      }

      if (!Config.isNoGis()
          && !Config.isMysqlDriver()
          && !Config.isConvertToEWKT()
          && GMLUtils.checkMultipointBug(con)) {
        Log.write(
            "Installed version of Postgis is affected by "
                + "multipoint bug "
                + "http://trac.osgeo.org/postgis/ticket/1928, enabling "
                + "workaround...");
        GMLUtils.setMultipointBugWorkaround(true);
      }

      con.commit();

      for (final Path file : getInputFiles(Config.getInputDirPath())) {
        processFile(file);
        con.commit();
      }

      if (Config.isCreateTables()) {
        Log.write("Creating indexes...");

        if (Config.isNoGis() || Config.isMysqlDriver()) {
          if (Config.isMysqlDriver()) {
            runSQLFromResource(con, "/sql/schema_no_gis_mysql_idx.sql");
          } else {
            runSQLFromResource(con, "/sql/schema_no_gis_idx.sql");
          }
        } else {
          runSQLFromResource(con, "/sql/schema_idx.sql");
        }
      }

      Log.write("Total duration: " + (System.currentTimeMillis() - startTimestamp) + " ms");
    }
  }