public void copyTable(String name, ResultSet source) throws SQLException, IOException { ResultSetMetaData md = source.getMetaData(); List<Column> columns = new LinkedList<Column>(); int textCount = 0; int totalSize = 0;  for (int i = 1; i <= md.getColumnCount(); i++) { DataType accessColumnType = DataType.fromSQLType(md.getColumnType(i)); switch (accessColumnType) { case BYTE: case INT: case LONG: case MONEY: case FLOAT: case NUMERIC: totalSize += 4; break; case DOUBLE: case SHORT_DATE_TIME: totalSize += 8; break; case BINARY: case TEXT: case OLE: case MEMO: textCount++; break; } } short textSize = 0; if (textCount > 0) { textSize = (short) ((JetFormat.MAX_RECORD_SIZE - totalSize) / textCount); if (textSize > JetFormat.TEXT_FIELD_MAX_LENGTH) { textSize = JetFormat.TEXT_FIELD_MAX_LENGTH; } } for (int i = 1; i <= md.getColumnCount(); i++) { Column column = new Column(); column.setName(escape(md.getColumnName(i))); column.setType(DataType.fromSQLType(md.getColumnType(i))); if (column.getType() == DataType.TEXT) { column.setLength(textSize); } columns.add(column); } createTable(escape(name), columns); Table table = getTable(escape(name)); List<Object[]> rows = new ArrayList<Object[]>(); while (source.next()) { Object[] row = new Object[md.getColumnCount()]; for (int i = 0; i < row.length; i++) { row[i] = source.getObject(i + 1); } rows.add(row); if (rows.size() == COPY_TABLE_BATCH_SIZE) { table.addRows(rows); rows.clear(); } } if (rows.size() > 0) { table.addRows(rows); }
public void copyTable(String name, ResultSet source) throws SQLException, IOException { copyTable(name, source, SimpleImportFilter.INSTANCE);
  public void copyTable(String name, ResultSet source) throws SQLException, IOException {    ResultSetMetaData md = source.getMetaData();    List<Column> columns = new LinkedList<Column>();    int textCount = 0;    int totalSize = 0;    // FIXME, there is some ugly (and broken) logic here...    for (int i = 1; i <= md.getColumnCount(); i++) {      DataType accessColumnType = DataType.fromSQLType(md.getColumnType(i));      switch (accessColumnType) {        case BYTE:        case INT:        case LONG:        case MONEY:        case FLOAT:        case NUMERIC:          totalSize += 4;          break;        case DOUBLE:        case SHORT_DATE_TIME:          totalSize += 8;          break;        case BINARY:        case TEXT:        case OLE:        case MEMO:          textCount++;          break;      }    }    short textSize = 0;    if (textCount > 0) {      textSize = (short) ((JetFormat.MAX_RECORD_SIZE - totalSize) / textCount);      if (textSize > JetFormat.TEXT_FIELD_MAX_LENGTH) {        textSize = JetFormat.TEXT_FIELD_MAX_LENGTH;      }    }    for (int i = 1; i <= md.getColumnCount(); i++) {      Column column = new Column();      column.setName(escape(md.getColumnName(i)));      column.setType(DataType.fromSQLType(md.getColumnType(i)));      if (column.getType() == DataType.TEXT) {        column.setLength(textSize);      }      columns.add(column);    }    createTable(escape(name), columns);    Table table = getTable(escape(name));    List<Object[]> rows = new ArrayList<Object[]>();    while (source.next()) {      Object[] row = new Object[md.getColumnCount()];      for (int i = 0; i < row.length; i++) {        row[i] = source.getObject(i + 1);      }      rows.add(row);      if (rows.size() == COPY_TABLE_BATCH_SIZE) {        table.addRows(rows);        rows.clear();      }    }    if (rows.size() > 0) {      table.addRows(rows);    }  }