本文整理汇总了Java中org.dbunit.dataset.Column类的典型用法代码示例。如果您正苦于以下问题:Java Column类的具体用法?Java Column怎么用?Java Column使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Column类属于org.dbunit.dataset包,在下文中一共展示了Column类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRow
import org.dbunit.dataset.Column; //导入依赖的package包/类
/**
* Gets column names and row values from the given attribute and adds a new row to the given table.
*
* @param table The table to add the row to, not null
* @param attributes the attributes, not null
*/
protected void addRow(Attributes attributes, DbUnitTable table) {
if (attributes.getLength() == 0) {
return;
}
for (int i = 0; i < attributes.getLength(); i++) {
Column column = new Column(attributes.getQName(i), UNKNOWN);
table.addColumn(column);
}
List<Object> row = new ArrayList<Object>(10);
for (String columnName : table.getColumnNames()) {
Object value = NO_VALUE;
if (attributes.getIndex(columnName) != -1) {
value = attributes.getValue(columnName);
}
row.add(value);
}
table.addRow(row);
}
示例2: createTableMetaData
import org.dbunit.dataset.Column; //导入依赖的package包/类
private ITableMetaData createTableMetaData() throws DataSetException {
if (beans.isEmpty()) {
return new DefaultTableMetaData(tableName, new Column[0]);
} else {
try {
List<Column> columns = new ArrayList<Column>();
BeanInfo info = Introspector.getBeanInfo(beans.get(0).getClass());
PropertyDescriptor[] descs = info.getPropertyDescriptors();
for (PropertyDescriptor desc : descs) {
if (!isIgnoreProperty(desc)) {
System.out.println(desc.getName());
columns.add(new Column(desc.getName(), DataType.UNKNOWN));
}
}
Column[] c = (Column[]) columns.toArray(new Column[columns.size()]);
return new DefaultTableMetaData(tableName, c);
} catch (IntrospectionException e) {
throw new DataSetException(e);
}
}
}
示例3: getValue
import org.dbunit.dataset.Column; //导入依赖的package包/类
@Override
public Object getValue(int row, String column) throws DataSetException {
if (row < table.getRowCount()) {
return table.getValue(row, column);
} else {
if (columnToBeReplaced.equalsIgnoreCase(column)) {
Column c = null;
ITableMetaData metaData = table.getTableMetaData();
for (Column cl : metaData.getColumns()) {
if (cl.getColumnName().equalsIgnoreCase(column)) {
c = cl;
}
}
return c.getDataType().typeCast(valueToBeReplaced);
}
return table.getValue(row - table.getRowCount(), column);
}
}
示例4: createRecodeRules
import org.dbunit.dataset.Column; //导入依赖的package包/类
/**
* Создает коллекцию правил перекодирования на основе таблицы
*
* @param from именованный путь источника
* @param to именованный путь назначения
* @param table таблица
* @return Возвращает коллекцию правил перекодирования
*/
private Collection<RecodeRule> createRecodeRules(DictionaryNamedPath from, DictionaryNamedPath to, ITable table) throws DataSetException {
Collection<RecodeRule> rules = new ArrayList<RecodeRule>(table.getRowCount());
for (int row = 0; row < table.getRowCount(); row++) {
final RecodeRule rule = new RecodeRule();
Column[] columns = table.getTableMetaData().getColumns();
// Поля источника
int columnIndex = 0;
{
rule.injectFromNamedPath(
createFieldNamedPath(from, columns[columnIndex].getColumnName(), table.getValue(row, columns[columnIndex].getColumnName()))
);
}
// Поля назначения
columnIndex++;
{
rule.injectToNamedPath(
createFieldNamedPath(to, columns[columnIndex].getColumnName(), table.getValue(row, columns[columnIndex].getColumnName()))
);
}
rules.add(rule);
}
return rules;
}
示例5: startTable
import org.dbunit.dataset.Column; //导入依赖的package包/类
@Override
public void startTable(ITableMetaData metaData) throws DataSetException {
// Формируем целевой файл
currentFile = new File(targetDirectory, String.format("%s.%s", metaData.getTableName(), extension));
try {
// Формируем сервис записи файла
currentWriter = createWriter();
// Формируем название колонок
Column[] columns = metaData.getColumns();
currentHeaders = new String[columns.length];
for (int i = 0; i < currentHeaders.length; i++) {
currentHeaders[i] = columns[i].getColumnName();
}
// Записываем название колонок
writeHeader();
} catch (IOException ex) {
throw new DataSetException(ex);
}
}
示例6: readTable
import org.dbunit.dataset.Column; //导入依赖的package包/类
/**
* Выполняет формирование таблицы из файла
*
* @param tableName название таблицы
* @param reader сервис чтения файла
*/
protected void readTable(String tableName, ICsvListReader reader) throws DataSetException, IOException {
String[] headers = reader.getHeader(true);
if (headers == null) {
throw new DataSetException(String.format("Table '%s' must contains headers", tableName));
}
Column[] columns = new Column[headers.length];
for (int i = 0; i < headers.length; i++) {
columns[i] = new Column(headers[i], DataType.UNKNOWN);
}
consumer.startTable(new DefaultTableMetaData(tableName, columns));
List<String> row;
while ((row = reader.read()) != null) {
consumer.row(row.toArray());
}
consumer.endTable();
}
示例7: testConvert
import org.dbunit.dataset.Column; //导入依赖的package包/类
public void testConvert() throws Exception {
ITableMetaData tableMetaData = new DefaultTableMetaData(
"testDictionary",
new Column[]{new Column("column1", DataType.UNKNOWN), new Column("column2", DataType.UNKNOWN)}
);
Dictionary dictionary = converter.convert(tableMetaData);
assertNotNull(dictionary);
assertEquals(dictionary.getName(), "testDictionary");
// check META-fields
List<MetaField> metaFields = ModelUtils.sortMetaFieldsByOrdinal(dictionary.getDescendants());
assertEquals(metaFields.size(), 2);
for (int i = 0; i < metaFields.size(); i++) {
assertMetaField(metaFields.get(i), tableMetaData.getColumns(), i, i == 0);
}
// check serialize
assertObjectSerialization(dictionary);
}
示例8: assertTable
import org.dbunit.dataset.Column; //导入依赖的package包/类
/**
* Выполняет проверку таблицы
*
* @param table целевая таблица
*/
protected static void assertTable(ITable table) throws Exception {
// Колонки
Column[] columns = table.getTableMetaData().getColumns();
assertEquals(columns.length, COLUMNS.length);
for (int i = 0; i < columns.length; i++) {
assertEquals(columns[i].getColumnName(), COLUMNS[i]);
}
// Строки
assertEquals(table.getRowCount(), ROWS.length);
for (int row = 0; row < table.getRowCount(); row++) {
for (int column = 0; column < columns.length; column++) {
assertEquals(table.getValue(row, columns[column].getColumnName()), ROWS[row][column]);
}
}
}
示例9: compareDbToDataSet
import org.dbunit.dataset.Column; //导入依赖的package包/类
private void compareDbToDataSet(String filename) throws Exception
{
IDataSet afterActualDataSet = getDbUnitconnection().createDataSet();
IDataSet afterExpectedDataSet = loadDataSet(filename);
ITableIterator iter = afterActualDataSet.iterator();
while (iter.next()) {
ITable actualTable = iter.getTable();
ITable expectedTable = afterExpectedDataSet.getTable(actualTable.getTableMetaData().getTableName());
Column[] expectedColumns = expectedTable.getTableMetaData().getColumns();
//Expected table will be sorted by the columns present on expected file
ITable sortedExpectedTable = new SortedTable(expectedTable, expectedColumns);
//Actual table will be sorted by the columns present on *expected* file.
//It will be also filtered to only include tables present on expected file
ITable filteredActualTable = DefaultColumnFilter.includedColumnsTable(actualTable, expectedColumns);
ITable sortedFilteredActualTable = new SortedTable(filteredActualTable, expectedColumns);
Assertion.assertEquals(sortedExpectedTable, sortedFilteredActualTable);
}
}
示例10: setUpDatabaseConfig
import org.dbunit.dataset.Column; //导入依赖的package包/类
/**
* Configure database.
*
* @param config the database-config.
*/
private void setUpDatabaseConfig(DatabaseConfig config) {
config.setProperty(DatabaseConfig.PROPERTY_BATCH_SIZE, BATCH_SIZE);
config.setProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS,
Boolean.TRUE);
config.setProperty(DatabaseConfig.PROPERTY_PRIMARY_KEY_FILTER,
new IColumnFilter() {
@Override
public boolean accept(String tableName, Column column) {
if (tableToPrimaryKey.containsKey(tableName)) {
return Arrays.asList(
tableToPrimaryKey.get(tableName)).contains(
column.getColumnName());
} else {
return column.getColumnName()
.equalsIgnoreCase("id");
}
}
});
}
示例11: filterColumns
import org.dbunit.dataset.Column; //导入依赖的package包/类
private Column[] filterColumns(Column[] allColumns) {
List<Column> result = new ArrayList<Column>();
for (Column column : allColumns) {
if (!column.getColumnName().equals("moddate")) {
result.add(column);
}
}
return result.toArray(new Column[result.size()]);
}
示例12: sortCols
import org.dbunit.dataset.Column; //导入依赖的package包/类
private Column[] sortCols(final Column[] cols) {
Arrays.sort(cols, new Comparator<Column>() {
@Override
public int compare(final Column columnA, final Column columnB) {
if (columnA.getColumnName().toLowerCase().equals("id")) {
return -1;
} else if (columnB.getColumnName().toLowerCase().equals("id")) {
return 1;
} else {
return columnA.getColumnName().compareTo(columnB.getColumnName());
}
}
});
return cols;
}
示例13: accept
import org.dbunit.dataset.Column; //导入依赖的package包/类
@Override
public boolean accept(final String tablename, final Column column) {
final String tablenameUpper = tablename.toUpperCase();
if (TS_TABLE_COLUMNS.containsKey(tablenameUpper)) {
return !TS_TABLE_COLUMNS.get(tablenameUpper).contains(column.getColumnName().toUpperCase());
}
return true;
}
示例14: row
import org.dbunit.dataset.Column; //导入依赖的package包/类
@Override
public void row(Object[] values) throws DataSetException {
rowCount++;
try {
out.write(FOUR_SPACES+"{"+NEW_LINE);
for (int i = 0; i < values.length; i++) {
if(values[i] == null){
continue;
}
Column currentColumn = metaData.getColumns()[i];
out.write(FOUR_SPACES+DOUBLE_SPACES+"\""+metaData.getColumns()[i].getColumnName() + "\": ");
boolean isNumber = currentColumn.getDataType().isNumber();
if (!isNumber) {
out.write("\"");
}
out.write(values[i].toString());
if (!isNumber) {
out.write("\"");
}
if(i != values.length-1){
out.write(",");
}
out.write(NEW_LINE);
}
if(dataSet.getTable(metaData.getTableName()).getRowCount() != rowCount ){
out.write(FOUR_SPACES+"},"+NEW_LINE);
}else {
out.write(FOUR_SPACES+"}"+NEW_LINE);
}
} catch (Exception e) {
logger.warn("Could not write row.", e);
}
}
示例15: row
import org.dbunit.dataset.Column; //导入依赖的package包/类
@Override
public void row(Object[] values) throws DataSetException {
try {
for (int i = 0; i < values.length; i++) {
if(values[i] == null){
continue;
}
if (i == 0) {
out.write(DOUBLE_SPACES + "- ");
} else{
out.write(DOUBLE_SPACES + DOUBLE_SPACES);
}
Column currentColumn = metaData.getColumns()[i];
out.write(metaData.getColumns()[i].getColumnName()+": ");
boolean isNumber = currentColumn.getDataType().isNumber();
if(!isNumber){
out.write("\"");
}
if(values[i] != null){
out.write(values[i].toString());
}
if(!isNumber){
out.write("\"");
}
out.write(NEW_LINE);
}
}catch (Exception e){
logger.warn("Could not write row.",e);
}
}