Java Code Examples for java.sql.ResultSet.getFetchSize()

The following are Jave code examples for showing how to use getFetchSize() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: syndesis   File: DatabaseMetaDataHelper.java   View Source Code Vote up 6 votes
static List<SqlParam> getJDBCInfoByColumnNames(final DatabaseMetaData meta, String catalog, 
        String schema, String tableName, final List<SqlParam> params) throws SQLException {
    List<SqlParam> paramList = new ArrayList<>();
    for (int i=0; i<params.size(); i++) {
        SqlParam param = params.get(i);
        String columnName = param.getColumn();
        ResultSet column = meta.getColumns(catalog, schema, tableName, columnName);
        if (column.getFetchSize() == 0) {
            //Postgresql does lowercase instead, so let's try that if we don't have a match
            column = meta.getColumns(catalog, schema, tableName.toLowerCase(), columnName.toLowerCase());
        }
        column.next();
        param.setJdbcType(JDBCType.valueOf(column.getInt("DATA_TYPE")));
        paramList.add(param);
    }
    return paramList;
}
 
Example 2
Project: light-saga-4j   File: SagaInstanceRepositoryJdbc.java   View Source Code Vote up 5 votes
@Override
public SagaInstance find(String sagaType, String sagaId) {
  Objects.requireNonNull(sagaType);
  Objects.requireNonNull(sagaId);
  logger.info("finding {} {}", sagaType, sagaId);
  SagaInstance sagaInstance = null;
  String psSelect = "SELECT saga_type,saga_id,state_name,last_request_id, saga_data_type, saga_data_json   FROM saga_instance WHERE saga_type = ? AND saga_id = ?";
  String psSelect_dest = "SELECT destination, resource FROM saga_instance_participants WHERE saga_type = ? AND saga_id = ?";

  try (final Connection connection = dataSource.getConnection()) {
    PreparedStatement stmt = connection.prepareStatement(psSelect_dest);
    stmt.setString(1, sagaType);
    stmt.setString(2, sagaId);
    ResultSet rs2 = stmt.executeQuery();
    Set<DestinationAndResource> destinationsAndResources = new HashSet<>();
    while (rs2.next()) {
      DestinationAndResource destinationsAndResource = new DestinationAndResource(rs2.getString("destination"), rs2.getString("resource"));
      destinationsAndResources.add(destinationsAndResource);
    }
    stmt = connection.prepareStatement(psSelect);
    stmt.setString(1, sagaType);
    stmt.setString(2, sagaId);
    ResultSet rs = stmt.executeQuery();
    if (rs == null || rs.getFetchSize() > 1) {
      logger.error("incorrect fetch result {}, {}", sagaType, sagaId);
    } else {
      while (rs.next()) {
        sagaInstance = new SagaInstance(sagaType, sagaId, rs.getString("state_name"), rs.getString("last_request_id"),
                new SerializedSagaData(rs.getString("saga_data_type"), rs.getString("saga_data_json")), destinationsAndResources);
      }
    }
  } catch (SQLException e) {
    logger.error("SqlException:", e);
  }

  return sagaInstance;
  // TODO insert - sagaInstance.getDestinationsAndResources();
}