org.dbunit.dataset.DefaultTableMetaData Java Examples
The following examples show how to use
org.dbunit.dataset.DefaultTableMetaData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataSetProducer.java From jpa-unit with Apache License 2.0 | 5 votes |
@Override public void produce() throws DataSetException { consumer.startDataSet(); final Map<String, List<Map<String, String>>> dataset = loadDataSet(); for (final Map.Entry<String, List<Map<String, String>>> entry : dataset.entrySet()) { // an entry represents a table final List<Map<String, String>> rows = entry.getValue(); // each row represents a record in a table final Collection<String> columnNames = extractColumnNames(rows); final ITableMetaData tableMetaData = new DefaultTableMetaData(entry.getKey(), createColumns(columnNames)); consumer.startTable(tableMetaData); for (final Map<String, String> row : rows) { final List<String> values = new ArrayList<>(); for (final Column column : tableMetaData.getColumns()) { final Object rawValue = row.get(column.getColumnName()); final String value = rawValue == null ? null : String.valueOf(rawValue); values.add(value); } consumer.row(values.toArray()); } consumer.endTable(); } consumer.endDataSet(); }
Example #2
Source File: XlsTableWrapper.java From Leo with Apache License 2.0 | 5 votes |
public ITableMetaData getTableMetaData() { ITableMetaData meta = delegate.getTableMetaData(); try { return new DefaultTableMetaData(tableName, meta.getColumns(), meta.getPrimaryKeys()); } catch (DataSetException e) { throw new QtafException("Don't get the meta info from " + meta, e); } }
Example #3
Source File: TableMetaDataBuilder.java From database-rider with Apache License 2.0 | 4 votes |
public ITableMetaData build() { return new DefaultTableMetaData(tableName, columns()); }
Example #4
Source File: BasicRowBuilder.java From database-rider with Apache License 2.0 | 4 votes |
protected ITableMetaData createMetaData(Column[] columns) { return new DefaultTableMetaData(tableName, columns); }
Example #5
Source File: XlsTable.java From Leo with Apache License 2.0 | 4 votes |
static ITableMetaData createMetaData(String tableName, HSSFRow sampleRow, HSSFWorkbook workbook) { logger.debug("createMetaData(tableName={}, sampleRow={}) - start", tableName, sampleRow); List<Column> columnList = new ArrayList<Column>(); List<String> primaryKeyList = new ArrayList<String>(); for (int i = 0;; i++) { HSSFCell cell = sampleRow.getCell(i); if (cell == null) { break; } String columnName = cell.getRichStringCellValue().getString(); if (columnName != null) { columnName = columnName.trim(); } // Bugfix for issue ID 2818981 - if a cell has a formatting but no // name also ignore it if (columnName.length() <= 0) { logger .debug( "The column name of column # {} is empty - will skip here assuming the last column was reached", String.valueOf(i)); break; } Column column = new Column(columnName, DataType.UNKNOWN); columnList.add(column); // Unique identification key byte underline = cell.getCellStyle().getFont(workbook).getUnderline(); if (underline == 1) { primaryKeyList.add(columnName); } } Column[] columns = columnList.toArray(new Column[0]); if(!primaryKeyList.isEmpty()){ return new DefaultTableMetaData(tableName, columns,primaryKeyList.toArray(new String[primaryKeyList.size()])); }else{ return new DefaultTableMetaData(tableName, columns); } }