Skip to content
Ivan edited this page Aug 5, 2022 · 1 revision

Modificación Interfaces para carga de recursos SQL

  • Crear carpeta 'resources' en ruta 'src/main/' (src/main/resources)

  • Copiar y sanitizar (remover sintaxis y variables java y/o otros) la query principal (o queries) de la interfaz en un archivo *.sql y dejarlo en la carpeta resources.

  • Antes del llamado, insertar el siguiente código:

    URL url = Resources.getResource("queryFacturacion.sql");
    StringBuilder textBuilder = new StringBuilder();
    try {
      InputStream in = new BufferedInputStream((InputStream) url.getContent());
      try (Reader reader = new BufferedReader(
              new InputStreamReader(in, Charset.forName(StandardCharsets.UTF_8.name())))) {
        int q = 0;
        while ((q = reader.read()) != -1) {
          textBuilder.append((char) q);
        }
      }
    } catch (Exception e){
      e.printStackTrace();
    }
    String orQuery = textBuilder.toString();
  • En el siguiente código, revisar que método '.withQuery' lea el parámetro orQuery.

     PCollection<SapRow> oracleRows = p.apply("Consultar Facturacion", JdbcIO.<SapRow>read()
            .withDataSourceConfiguration(JdbcIO.DataSourceConfiguration.create(
                    "oracle.jdbc.driver.OracleDriver",
                    oracleConnectionString)
                    //options.getOracleConnectionString())
                    .withConnectionProperties("oracle.jdbc.timezoneAsRegion=false"))
            .withQuery(orQuery) //método
            .withCoder(AvroCoder.of(SapRow.class))
            .withRowMapper(new Facturacion.MapOracleResultIntoSapRow())
    );

Clone this wiki locally