本文整理汇总了Java中org.dbunit.dataset.ITable.getRowCount方法的典型用法代码示例。如果您正苦于以下问题:Java ITable.getRowCount方法的具体用法?Java ITable.getRowCount怎么用?Java ITable.getRowCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dbunit.dataset.ITable
的用法示例。
在下文中一共展示了ITable.getRowCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printResult
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
protected static void printResult(ITable resultTable) throws DataSetException {
StringBuilder sb = new StringBuilder();
int columnCount = resultTable.getTableMetaData().getColumns().length;
String[] columns = new String[columnCount];
for (int i = 0; i < columnCount; i++) {
sb.append(resultTable.getTableMetaData().getColumns()[i].getColumnName());
sb.append("-");
sb.append(resultTable.getTableMetaData().getColumns()[i].getDataType());
sb.append("\t");
columns[i] = resultTable.getTableMetaData().getColumns()[i].getColumnName();
}
sb.append("\n");
for (int i = 0; i < resultTable.getRowCount(); i++) {
for (int j = 0; j < columns.length; j++) {
sb.append(resultTable.getValue(i, columns[j]));
sb.append("\t");
}
sb.append("\n");
}
System.out.println(sb.toString());
}
示例2: compareDataContains
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
private void compareDataContains(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler) throws DataSetException {
logger.debug("compareData(expectedTable={}, actualTable={}, " + "comparisonCols={}, failureHandler={}) - start", new Object[] { expectedTable, actualTable, comparisonCols, failureHandler });
if (expectedTable == null) {
throw new NullPointerException("The parameter 'expectedTable' must not be null");
}
if (actualTable == null) {
throw new NullPointerException("The parameter 'actualTable' must not be null");
}
if (comparisonCols == null) {
throw new NullPointerException("The parameter 'comparisonCols' must not be null");
}
if (failureHandler == null) {
throw new NullPointerException("The parameter 'failureHandler' must not be null");
}
for (int index = 0; index < actualTable.getRowCount(); index++) {
if (!findRowInExpectedTable(expectedTable, actualTable, comparisonCols, failureHandler, index)) {
throw new IllegalStateException();
}
}
}
示例3: createRecodeRules
import org.dbunit.dataset.ITable; //导入方法依赖的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;
}
示例4: assertTable
import org.dbunit.dataset.ITable; //导入方法依赖的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]);
}
}
}
示例5: compareNotExpectedWithActual
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
/**
* Vergelijkt een actuele dataset met een niet-verwachte dataset. Alle records in de niet-verwachte dataset dienen
* niet voor te komen in de actuele dataset. Tabellen/records die niet in de not-expected set voorkomen worden
* genegeerd.
* <p>
* @param notExpected De not-expected dataset.
* @throws DatabaseUnitException on error
* @throws SQLException on error
*/
protected void compareNotExpectedWithActual(final IDataSet notExpected) throws DatabaseUnitException, SQLException {
if (notExpected == null) {
throw new IllegalArgumentException("Argument 'notExpected' is null");
}
final IDatabaseConnection connection = createConnection();
try {
final IDataSet actual = createActualSet(connection);
final String[] notExpTableNames = notExpected.getTableNames();
for (final String currentTableName : notExpTableNames) {
final ITable expTable = notExpected.getTable(currentTableName);
final ITable actTable = actual.getTable(currentTableName);
final ITable filteredActTable = new RowFilterTable(actTable, new PrimaryKeyRowFilter(expTable));
final int actualRowCount = filteredActTable.getRowCount();
if (0 != actualRowCount) {
final String foutmelding =
"Er zijn "
+ actualRowCount
+ " records gevonden in de tabel "
+ currentTableName.toUpperCase()
+ " die voorkomen in de NOT EXPECTED dataset";
LOG.error(foutmelding);
LOG.error("****** De volgende 'NotExpected' records zijn aangetroffen in de database:");
LOG.error(FORMATTER.format(filteredActTable));
Assert.fail(foutmelding + " (zie ERROR-log voor details)");
}
}
} finally {
connection.close();
}
}
示例6: PrimaryKeyRowFilter
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
/**
* @param expTable expected table
*/
PrimaryKeyRowFilter(final ITable expTable) {
try {
for (int i = 0; i < expTable.getRowCount(); i++) {
allowedPks.add(expTable.getValue(i, PK_COLUMN_NAME).toString());
}
} catch (final DataSetException e) {
throw new IllegalStateException(e);
}
}
示例7: execAndCompResultSize
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
protected void execAndCompResultSize(String queryFolder, String[] exclusiveQuerys, boolean needSort)
throws Exception {
logger.info("---------- test folder: " + queryFolder);
Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);
List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
for (File sqlFile : sqlFiles) {
String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
if (exclusiveSet.contains(queryName)) {
continue;
}
String sql = getTextFromFile(sqlFile);
// execute Kylin
logger.info("Query Result from Kylin - " + queryName + " (" + queryFolder + ")");
IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
ITable kylinTable = executeQuery(kylinConn, queryName, sql, needSort);
// execute H2
logger.info("Query Result from H2 - " + queryName);
ITable h2Table = executeQuery(newH2Connection(), queryName, sql, needSort);
try {
// compare the result
Assert.assertEquals(h2Table.getRowCount(), kylinTable.getRowCount());
} catch (Throwable t) {
logger.info("execAndCompResultSize failed on: " + sqlFile.getAbsolutePath());
throw t;
}
compQueryCount++;
if (kylinTable.getRowCount() == 0) {
zeroResultQueries.add(sql);
}
}
}
示例8: execLimitAndValidate
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
protected void execLimitAndValidate(String queryFolder) throws Exception {
logger.info("---------- test folder: " + new File(queryFolder).getAbsolutePath());
int appendLimitQueries = 0;
List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
for (File sqlFile : sqlFiles) {
String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
String sql = getTextFromFile(sqlFile);
String sqlWithLimit;
if (sql.toLowerCase().contains("limit ")) {
sqlWithLimit = sql;
} else {
sqlWithLimit = sql + " limit 5";
appendLimitQueries++;
}
// execute Kylin
logger.info("Query Result from Kylin - " + queryName + " (" + queryFolder + ")");
IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
ITable kylinTable = executeQuery(kylinConn, queryName, sqlWithLimit, false);
// execute H2
logger.info("Query Result from H2 - " + queryName);
ITable h2Table = executeQuery(newH2Connection(), queryName, sql, false);
try {
assertTableContains(h2Table, kylinTable);
} catch (Throwable t) {
logger.info("execAndCompQuery failed on: " + sqlFile.getAbsolutePath());
throw t;
}
compQueryCount++;
if (kylinTable.getRowCount() == 0) {
zeroResultQueries.add(sql);
}
}
logger.info("Queries appended with limit: " + appendLimitQueries);
}
示例9: execAndCompQuery
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
protected void execAndCompQuery(String queryFolder, String[] exclusiveQuerys, boolean needSort,
ICompareQueryTranslator translator) throws Exception {
logger.info("---------- test folder: " + new File(queryFolder).getAbsolutePath());
Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);
List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
for (File sqlFile : sqlFiles) {
String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
if (exclusiveSet.contains(queryName)) {
continue;
}
String sql1 = getTextFromFile(sqlFile);
String sql2 = translator.transform(sqlFile);
// execute Kylin
logger.info("Query Result from Kylin - " + queryName + " (" + queryFolder + ")");
IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
ITable kylinTable = executeQuery(kylinConn, queryName, sql1, needSort);
// execute H2
logger.info("Query Result from H2 - " + queryName);
long currentTime = System.currentTimeMillis();
ITable h2Table = executeQuery(newH2Connection(), queryName, sql2, needSort);
logger.info("H2 spent " + (System.currentTimeMillis() - currentTime) + " mili-seconds.");
try {
// compare the result
assertTableEquals(h2Table, kylinTable);
} catch (Throwable t) {
logger.info("execAndCompQuery failed on: " + sqlFile.getAbsolutePath());
throw t;
}
compQueryCount++;
if (kylinTable.getRowCount() == 0) {
zeroResultQueries.add(sql1);
}
}
}
示例10: execAndCompQuery
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
protected void execAndCompQuery(String queryFolder, String[] exclusiveQuerys, boolean needSort) throws Exception {
printInfo("---------- test folder: " + queryFolder);
Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);
List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
for (File sqlFile : sqlFiles) {
String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
if (exclusiveSet.contains(queryName)) {
continue;
}
String sql = getTextFromFile(sqlFile);
// execute Kylin
printInfo("Query Result from Kylin - " + queryName + " (" + queryFolder + ")");
IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
ITable kylinTable = executeQuery(kylinConn, queryName, sql, needSort);
// execute H2
printInfo("Query Result from H2 - " + queryName);
H2Connection h2Conn = new H2Connection(h2Connection, null);
h2Conn.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new TestH2DataTypeFactory());
ITable h2Table = executeQuery(h2Conn, queryName, sql, needSort);
// compare the result
Assertion.assertEquals(h2Table, kylinTable);
compQueryCount++;
if (kylinTable.getRowCount() == 0) {
zeroResultQueries.add(sql);
}
}
}
示例11: format
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
/**
* Formats a table with all data in a beautiful way. Can be useful to print out the table data on a console.
*
* @param table
* The table to be formatted in a beautiful way
* @return The table data as a formatted String
* @throws DataSetException
*/
public String format(final ITable table) throws DataSetException {
final StringBuffer sb = new StringBuffer();
final ITableMetaData tableMetaData = table.getTableMetaData();
// Title line
sb.append("******");
sb.append(" table: ").append(tableMetaData.getTableName()).append(" ");
sb.append("**");
sb.append(" row count: ").append(table.getRowCount()).append(" ");
sb.append("******");
sb.append("\n");
// Column headers
final int width = 28;
final Column[] cols = tableMetaData.getColumns();
sortCols(cols);
for (int i = 0; i < cols.length; i++) {
sb.append(padRight(cols[i].getColumnName().toUpperCase(), width, ' '));
sb.append("|");
}
sb.append("\n");
// Separator
for (int i = 0; i < cols.length; i++) {
sb.append(padRight("", width, '='));
sb.append("|");
}
sb.append("\n");
// Values
for (int i = 0; i < table.getRowCount(); i++) {
for (int j = 0; j < cols.length; j++) {
final Object value = table.getValue(i, cols[j].getColumnName());
final String stringValue = String.valueOf(value);
sb.append(padRight(stringValue, width, ' '));
sb.append("|");
}
// New row
sb.append("\n");
}
return sb.toString();
}
示例12: compareExpectedWithActual
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
/**
* Vergelijkt een actuele dataset met de verwachte dataset. Alle records in de verwachte dataset dienen ook voor te
* komen in de actuele dataset. Tabellen die niet in de expected set voorkomen worden genegeerd.
* <p>
* @param expected De expected dataset.
* @throws DatabaseUnitException on error
* @throws SQLException on error
*/
protected void compareExpectedWithActual(final IDataSet expected) throws SQLException, DatabaseUnitException {
if (expected == null) {
throw new IllegalArgumentException("Argument 'expected' is null");
}
final IDatabaseConnection connection = createConnection();
try {
final IDataSet actual = createActualSet(connection);
final String[] expTableNames = expected.getTableNames();
for (final String currentTableName : expTableNames) {
// prepareer verwachtte tabel
final ITable expTable = expected.getTable(currentTableName);
final Column[] columnsExp = expTable.getTableMetaData().getColumns();
// Zoek naar kolommen met waarde: [NOTNULLCHECK] zodat deze geexclude worden. Deze worden later per rij
// gecontroleerd
final Set<String> excludeButNotEmptyColumnsSet = new HashSet<>();
final Map<Integer, String> excludeButNotEmptyColumns = new HashMap<>();
for (final Column column : columnsExp) {
for (int i = 0; i < expTable.getRowCount(); i++) {
final Object value = expTable.getValue(i, column.getColumnName());
if (value != null && value.toString().equals("[NOTNULLCHECK]")) {
excludeButNotEmptyColumnsSet.add(column.getColumnName());
excludeButNotEmptyColumns.put(i, column.getColumnName());
}
}
}
final String[] excludeButNotEmptyColumnsArray = excludeButNotEmptyColumnsSet.toArray(new String[0]);
final ITable filteredTableExp = DefaultColumnFilter.excludedColumnsTable(expTable, excludeButNotEmptyColumnsArray);
final ITable sortedExp = new SortedTable(filteredTableExp);
final ITable currentTimestampColumnFilteredExp = new ColumnFilterTable(sortedExp, new CurrentTimestampColumnFilter());
// prepareer actuele tabel
final ITable actTable = actual.getTable(currentTableName);
final ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(actTable, excludeButNotEmptyColumnsArray);
final ITable sortedActTable = new SortedTable(filteredTable);
final ITable primaryKeyFilteredActTable = new RowFilterTable(sortedActTable, new PrimaryKeyRowFilter(expTable));
final ITable currentTimestampRowFilteredActTable = new RowFilterTable(primaryKeyFilteredActTable, new CurrentTimestampRowFilter(expTable));
final ITable currentTimestampColumnFilteredActTable =
new ColumnFilterTable(currentTimestampRowFilteredActTable, new CurrentTimestampColumnFilter());
try {
ASSERT.assertEquals(currentTimestampColumnFilteredExp, currentTimestampColumnFilteredActTable);
if (excludeButNotEmptyColumns.size() > 0) {
for (int rij = 0; rij < actTable.getRowCount(); rij++) {
final String excludeColumName = excludeButNotEmptyColumns.get(rij);
if (excludeColumName != null && actTable.getValue(rij, excludeColumName) == null) {
LOG.error("****** NotNullCheck column was leeg in actual result: " + excludeColumName);
throw new AssertionFailedError();
}
}
}
} catch (final AssertionFailedError assertionError) {
LOG.error("****** De volgende records zijn aangetroffen in de database:");
LOG.error(FORMATTER.format(sortedActTable));
LOG.error("****** Terwijl minimaal de volgende EXPECTED records verwacht worden:");
LOG.error(FORMATTER.format(sortedExp));
throw assertionError;
}
}
} finally {
connection.close();
}
}
示例13: findRowInExpectedTable
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
private boolean findRowInExpectedTable(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler, int index) throws DataSetException {
// iterate over all rows
for (int i = 0; i < expectedTable.getRowCount(); i++) {
// iterate over all columns of the current row
for (int j = 0; j < comparisonCols.length; j++) {
ComparisonColumn compareColumn = comparisonCols[j];
String columnName = compareColumn.getColumnName();
DataType dataType = compareColumn.getDataType();
Object expectedValue = expectedTable.getValue(i, columnName);
Object actualValue = actualTable.getValue(index, columnName);
// Compare the values
if (skipCompare(columnName, expectedValue, actualValue)) {
if (logger.isTraceEnabled()) {
logger.trace("ignoring comparison " + expectedValue + "=" + actualValue + " on column " + columnName);
}
continue;
}
if (dataType.compare(expectedValue, actualValue) != 0) {
break;
// Difference diff = new Difference(expectedTable, actualTable, i, columnName, expectedValue, actualValue);
//
// // Handle the difference (throw error immediately or something else)
// failureHandler.handle(diff);
} else {
if (j == comparisonCols.length - 1) {
return true;
} else {
continue;
}
}
}
}
return false;
}
示例14: exportCsmUser
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
public static void exportCsmUser(IDatabaseConnection conn,
String loginName,
File exportFile) throws SQLException,
IOException,
DataSetException {
QueryDataSet dataset = new QueryDataSet(conn);
dataset.addTable("csm_application");
dataset.addTable("csm_protection_group");
//watch out ATTRIBUTE in caps doesnt work on MySQL? must change to lower case!??
dataset.addTable("csm_protection_element");
dataset.addTable("csm_pg_pe",
"select pg_pe_id, protection_group_id, protection_element_id from csm_pg_pe");
dataset.addTable("csm_role");
dataset.addTable("csm_privilege");
dataset.addTable("csm_role_privilege");
dataset.addTable("csm_group");
dataset.addTable("csm_user",
"select * from csm_user where login_name = '"+loginName+"'");
ITable csmUser = dataset.getTable("csm_user");
Long userId = (Long)csmUser.getValue(0, "user_id");
dataset.addTable("csm_user_group",
"select * from csm_user_group where user_id = "+userId);
ITable csmUserGroup = dataset.getTable("csm_user_group");
dataset.addTable("csm_user_pe",
"select * from csm_user_pe where user_id = "+userId);
dataset.addTable("csm_user_group_role_pg",
"select * from csm_user_group_role_pg where user_id = "+userId);
for(int i=0;i<csmUserGroup.getRowCount();i++) {
Long groupId = (Long)csmUserGroup.getValue(i, "group_id");
dataset.addTable("csm_user_group_role_pg",
"select * from csm_user_group_role_pg where group_id="+groupId);
}
FlatXmlDataSet.write(dataset,
new FileOutputStream(exportFile));
}
示例15: exportPatient
import org.dbunit.dataset.ITable; //导入方法依赖的package包/类
public static void exportPatient(IDatabaseConnection conn,
Integer patientPkId,
File exportFile) throws SQLException,
IOException,
DataSetException {
QueryDataSet dataset = new QueryDataSet(conn);
dataset.addTable("trial_data_provenance");
dataset.addTable("trial_site");
dataset.addTable("general_equipment");
dataset.addTable("patient",
"select * from patient where patient_pk_id = "+patientPkId);
dataset.addTable("study",
"select * from study where patient_pk_id = "+patientPkId);
dataset.addTable("general_series",
"select * from general_series where patient_pk_id = "+patientPkId);
ITable generalSeries = dataset.getTable("general_series");
for(int i=0;i<generalSeries.getRowCount();i++) {
Long generalSeriesPkId = (Long)generalSeries.getValue(i, "general_series_pk_id");
dataset.addTable("annotation",
"select * from annotation where general_series_pk_id = "+generalSeriesPkId);
}
dataset.addTable("general_image",
"select * from general_image where patient_pk_id = "+patientPkId);
ITable generalImage = dataset.getTable("general_image");
for(int i=0;i<generalImage.getRowCount();i++) {
Long imagePkId = (Long)generalImage.getValue(i, "image_pk_id");
dataset.addTable("ct_image",
"select * from ct_image where image_pk_id = "+imagePkId);
}
dataset.addTable("curation_data",
"select * from curation_data where patient_pk_id = "+patientPkId);
FlatXmlDataSet.write(dataset,
new FileOutputStream(exportFile));
}