org.springframework.jdbc.core.RowMapper类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(414)

本文整理了Java中org.springframework.jdbc.core.RowMapper类的一些代码示例,展示了RowMapper类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RowMapper类的具体详情如下:
包路径:org.springframework.jdbc.core.RowMapper
类名称:RowMapper

RowMapper介绍

[英]An interface used by JdbcTemplate for mapping rows of a java.sql.ResultSet on a per-row basis. Implementations of this interface perform the actual work of mapping each row to a result object, but don't need to worry about exception handling. java.sql.SQLException will be caught and handled by the calling JdbcTemplate.

Typically used either for JdbcTemplate's query methods or for out parameters of stored procedures. RowMapper objects are typically stateless and thus reusable; they are an ideal choice for implementing row-mapping logic in a single place.

Alternatively, consider subclassing org.springframework.jdbc.object.MappingSqlQuery from the jdbc.object package: Instead of working with separate JdbcTemplate and RowMapper objects, you can build executable query objects (containing row-mapping logic) in that style.
[中]JdbcTemplate用于映射java的行的接口。sql。每行的结果集。该接口的实现执行将每一行映射到结果对象的实际工作,但不需要担心异常处理。JAVAsql。SQLException将被调用的JdbcTemplate捕获并处理。
通常用于JdbcTemplate的查询方法或存储过程的out参数。RowMapper对象通常是无状态的,因此可以重用;它们是在单个位置实现行映射逻辑的理想选择。
或者,考虑子类ORG。springframework。jdbc。对象从jdbc映射SQLQuery。对象包:不需要使用单独的JdbcTemplate和RowMapper对象,您可以用这种方式构建可执行的查询对象(包含行映射逻辑)。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public List<T> extractData(ResultSet rs) throws SQLException {
  List<T> results = (this.rowsExpected > 0 ? new ArrayList<>(this.rowsExpected) : new ArrayList<>());
  int rowNum = 0;
  while (rs.next()) {
    results.add(this.rowMapper.mapRow(rs, rowNum++));
  }
  return results;
}

代码示例来源:origin: stackoverflow.com

final RowMapper managerMapper = new BeanPropertyRowMapper(Manager.class);
 final RowMapper employeeMapper = new BeanPropertyRowMapper(Employee.class);
 final RowMapper contractorMapper = new BeanPropertyRowMapper(Contractor.class);
 RowMapper rm = new RowMapper()
 {
   @Override
   public Object mapRow(ResultSet rs, int rowNum)
     throws SQLException
   {
     int employeeType = rs.getInt("type");
     switch (employeeType)
     {
       case 1:
         return managerMapper.mapRow(rs, rowNum); 
       case 2:
         return employeeMapper.mapRow(rs, rowNum);
       case 3:
         return contractorMapper.mapRow(rs, rowNum);
       default:
         break;
     }
   }
 };

代码示例来源:origin: spring-projects/spring-batch

@Override
protected T readCursor(ResultSet rs, int currentRow) throws SQLException {
  return rowMapper.mapRow(rs, currentRow);
}

代码示例来源:origin: spring-projects/spring-batch

@Override
protected T readCursor(ResultSet rs, int currentRow) throws SQLException {
  return rowMapper.mapRow(rs, currentRow);
}

代码示例来源:origin: spring-projects/spring-batch

@Override
public List<JobInstance> extractData(ResultSet rs) throws SQLException,
DataAccessException {
  int rowNum = 0;
  while (rowNum < start && rs.next()) {
    rowNum++;
  }
  while (rowNum < start + count && rs.next()) {
    RowMapper<JobInstance> rowMapper = new JobInstanceRowMapper();
    list.add(rowMapper.mapRow(rs, rowNum));
    rowNum++;
  }
  return list;
}

代码示例来源:origin: spring-projects/spring-batch

@Override
  public Object extractData(ResultSet rs) throws SQLException,
  DataAccessException {
    int rowNum = 0;
    while (rowNum < start && rs.next()) {
      rowNum++;
    }
    while (rowNum < start + count && rs.next()) {
      RowMapper<JobInstance> rowMapper = new JobInstanceRowMapper();
      list.add(rowMapper.mapRow(rs, rowNum));
      rowNum++;
    }
    return list;
  }
};

代码示例来源:origin: spring-projects/spring-batch

@Test
  public void testRegularUse() throws SQLException {
    setUpResultSetMock(rs);

    assertEquals(expectedDomainObject(), rowMapper().mapRow(rs, IGNORED_ROW_NUMBER));
  }
}

代码示例来源:origin: komoot/photon

@Override
  public PhotonDoc mapRow(ResultSet resultSet, int i) throws SQLException {
    PhotonDoc doc = placeRowMapper.mapRow(resultSet, 0).getBaseDoc();
    completePlace(doc);
    return doc;
  }
});

代码示例来源:origin: komoot/photon

@Override
  public void processRow(ResultSet rs) throws SQLException {
    // turns a placex row into a photon document that gathers all de-normalised information
    NominatimResult docs = placeRowMapper.mapRow(rs, 0);
    if (!docs.isUsefulForIndex()) return; // do not import document
    // finalize document by taking into account the higher level placex rows assigned to this row
    completePlace(docs.getBaseDoc());
    for (PhotonDoc doc : docs.getDocsWithHousenumber()) {
      while (true) {
        try {
          documents.put(doc);
        } catch (InterruptedException e) {
          log.warn("Thread interrupted while placing document in queue.");
          continue;
        }
        break;
      }
      if (counter.incrementAndGet() % progressInterval == 0) {
        final double documentsPerSecond = 1000d * counter.longValue() / (System.currentTimeMillis() - startMillis);
        log.info(String.format("imported %s documents [%.1f/second]", MessageFormat.format("{0}", counter.longValue()), documentsPerSecond));
      }
    }
  }
});

代码示例来源:origin: komoot/photon

@Override
  public void processRow(ResultSet rs) throws SQLException {
    NominatimResult docs = osmlineRowMapper.mapRow(rs, 0);
    if (!docs.isUsefulForIndex()) return; // do not import document
    // finalize document by taking into account the higher level placex rows assigned to this row
    completePlace(docs.getBaseDoc());
    for (PhotonDoc doc : docs.getDocsWithHousenumber()) {
      while (true) {
        try {
          documents.put(doc);
        } catch (InterruptedException e) {
          log.warn("Thread interrupted while placing document in queue.");
          continue;
        }
        break;
      }
      if (counter.incrementAndGet() % progressInterval == 0) {
        final double documentsPerSecond = 1000d * counter.longValue() / (System.currentTimeMillis() - startMillis);
        log.info(String.format("imported %s documents [%.1f/second]", MessageFormat.format("{0}", counter.longValue()), documentsPerSecond));
      }
    }
  }
});

代码示例来源:origin: paoding-code/paoding-rose

return new MapEntryImpl<Object, Object>(key, mapper.mapRow(rs, rowNum));

代码示例来源:origin: com.danidemi.jlubricant/jlubricant-spring-batch

@Override
@SuppressWarnings("unchecked")
protected T readCursor(ResultSet rs, int currentRow) throws SQLException {
  return (T) rowMapper.mapRow(rs, currentRow);
}

代码示例来源:origin: apache/servicemix-bundles

@Override
protected T readCursor(ResultSet rs, int currentRow) throws SQLException {
  return rowMapper.mapRow(rs, currentRow);
}

代码示例来源:origin: apache/servicemix-bundles

@Override
protected T readCursor(ResultSet rs, int currentRow) throws SQLException {
  return rowMapper.mapRow(rs, currentRow);
}

代码示例来源:origin: org.tinygroup/org.tinygroup.tinydb

private List extractData(ResultSet rs, RowMapper mapper)
    throws SQLException {
  List results = new ArrayList();
  int rowNum = 0;
  while (rs.next()) {
    results.add(mapper.mapRow(rs, rowNum++));
  }
  return results;
}

代码示例来源:origin: org.tinygroup/org.tinygroup.jdbctemplatedslsession

private List extractData(ResultSet rs, RowMapper mapper)
    throws SQLException {
  List results = new ArrayList();
  int rowNum = 0;
  while (rs.next()) {
    results.add(mapper.mapRow(rs, rowNum++));
  }
  return results;
}

代码示例来源:origin: org.springframework/org.springframework.jdbc

public List<T> extractData(ResultSet rs) throws SQLException {
  List<T> results = (this.rowsExpected > 0 ? new ArrayList<T>(this.rowsExpected) : new ArrayList<T>());
  int rowNum = 0;
  while (rs.next()) {
    results.add(this.rowMapper.mapRow(rs, rowNum++));
  }
  return results;
}

代码示例来源:origin: infiniteautomation/ma-core-public

public List<T> extractData(ResultSet rs) throws SQLException {
    List<T> results = limit == 0 ? new LinkedList<T>() : new ArrayList<T>(limit);
    int rowNum = 0;
    while (rs.next()) {
      results.add(this.rowMapper.mapRow(rs, rowNum++));
      if (limit > 0 && rowNum >= limit)
        break;
    }
    return results;
  }
}

代码示例来源:origin: org.tinygroup/org.tinygroup.tinydb

private List extractDataWithScroll(ResultSet rs, RowMapper mapper)
    throws SQLException {
  List results = new ArrayList();
  int rowNum = 0;
  if (rs.absolute(start)) {
    do {
      results.add(mapper.mapRow(rs, rowNum++));
    } while ((rs.next()) && (rowNum < limit));
  }
  return results;
}

代码示例来源:origin: org.tinygroup/org.tinygroup.jdbctemplatedslsession

private List extractDataWithScroll(ResultSet rs, RowMapper mapper)
    throws SQLException {
  List results = new ArrayList();
  int rowNum = 0;
  if (rs.absolute(start + 1)) {
    do {
      results.add(mapper.mapRow(rs, rowNum++));
    } while ((rs.next()) && (rowNum < limit));
  }
  return results;
}

相关文章

RowMapper类方法