/**
   * @param dataSource
   * @return dummy item writer custom
   */
  @Bean
  public ItemWriter<CustomPojo> writer(DataSource dataSource) {
    if ("hsqldb".equals(this.mode)) {
      // hsqldb writer using JdbcBatchItemWriter (the difference is the
      // datasource)
      JdbcBatchItemWriter<CustomPojo> writer = new JdbcBatchItemWriter<CustomPojo>();
      writer.setItemSqlParameterSourceProvider(
          new BeanPropertyItemSqlParameterSourceProvider<CustomPojo>());
      writer.setSql("INSERT INTO pojo (id, description) VALUES (:id, :description)");
      writer.setDataSource(dataSource);
      return writer;
    } else if ("mysql".equals(this.mode)) {
      JdbcBatchItemWriter<CustomPojo> writer = new JdbcBatchItemWriter<CustomPojo>();

      writer.setSql("INSERT INTO pojo (id, description) VALUES (:id, :description)");
      writer.setDataSource(dataSource);
      writer.setItemSqlParameterSourceProvider(
          new BeanPropertyItemSqlParameterSourceProvider<CustomPojo>());
      return writer;
    }
    /*
     * else if ("mongo".equals(this.mode)) { // a writer using the
     * MongoItemWriter MongoItemWriter<CustomPojo> writer = new
     * MongoItemWriter<CustomPojo>();
     * writer.setCollection("testCollection"); return writer; }
     */
    else if ("flat".equals(this.mode)) {
      // FlatFileItemWriter writer
      FlatFileItemWriter<CustomPojo> writer = new CustomFlatFileItemWriter();
      writer.setResource(new ClassPathResource("output.csv"));

      BeanWrapperFieldExtractor<CustomPojo> fieldExtractor = new CustomFieldExtractor();
      fieldExtractor.setNames(new String[] {"id", "description"});

      DelimitedLineAggregator<CustomPojo> delLineAgg = new CustomDelimitedAggregator();
      delLineAgg.setDelimiter(",");
      delLineAgg.setFieldExtractor(fieldExtractor);

      writer.setLineAggregator(delLineAgg);
      return writer;
    } else {
      // dummy custom writer
      CustomItemWriter writer = new CustomItemWriter();
      return writer;
    }
  }
 private FieldExtractor<FlightPlanRouteDefinition> fieldExtractor() {
   BeanWrapperFieldExtractor<FlightPlanRouteDefinition> extractor =
       new BeanWrapperFieldExtractor<FlightPlanRouteDefinition>();
   extractor.setNames(
       new String[] {
         "airline",
         "aircraftModel",
         "aircraftNumber",
         "aircraftTitle",
         "groundspeed",
         "originTimezone",
         "flightFrequency",
         "originAirport",
         "outboundFlightLevel",
         "destinationAirport",
         "returnFlightLevel",
         "distance",
         "routeTime"
       });
   return extractor;
 }
コード例 #3
0
 protected FieldExtractor<FullRouteDefinition> fieldExtractor() {
   BeanWrapperFieldExtractor<FullRouteDefinition> extractor =
       new BeanWrapperFieldExtractor<FullRouteDefinition>();
   extractor.setNames(
       new String[] {
         "airline",
         "aircraftModel",
         "aircraftNumber",
         "aircraftTitle",
         "groundspeed",
         "originTimezone",
         "originAirport",
         "originLatitude",
         "originLongitude",
         "destinationAirport",
         "destinationLatitude",
         "destinationLongitude",
         "flightFrequency",
         "lowestFlightLevel"
       });
   return extractor;
 }