org.dbunit.database.AmbiguousTableNameException Java Examples

The following examples show how to use org.dbunit.database.AmbiguousTableNameException. 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: DBUnitDataExtractor.java    From gazpachoquest with GNU General Public License v3.0 6 votes vote down vote up
private void addQueries(final QueryDataSet dataSet) throws AmbiguousTableNameException {
    if (queryList == null) {
        return;
    }
    for (Object element : queryList) {
        String query = (String) element;
        Matcher m = TABLE_MATCH_PATTERN.matcher(query);
        if (!m.matches()) {
            logger.warn("Unable to parse query. Ignoring '" + query + "'.");
        } else {
            String table = m.group(1);
            // only add if the table has not been added
            if (tableList != null && tableList.contains(table)) {
                logger.warn("Table '" + table + "' already added. Ignoring '" + query + "'.");
            } else {
                dataSet.addTable(table, query);
            }
        }
    }
}
 
Example #2
Source File: DatabaseAccessHelper.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Autowired
public DatabaseAccessHelper(DataSource dataSource,
                            SqlSessionFactory sqlMapClient,
                            StageDao stageDao,
                            JobInstanceDao jobInstanceDao,
                            PipelineDao pipelineDao,
                            MaterialRepository materialRepository,
                            SessionFactory sessionFactory,
                            PipelineTimeline pipelineTimeline,
                            TransactionTemplate transactionTemplate,
                            TransactionSynchronizationManager transactionSynchronizationManager,
                            GoCache goCache,
                            PipelineService pipelineService, InstanceFactory instanceFactory,
                            JobAgentMetadataDao jobAgentMetadataDao,
                            AgentDao agentDao) throws AmbiguousTableNameException {
    this.dataSource = dataSource;
    this.sqlMapClient = sqlMapClient;
    this.stageDao = stageDao;
    this.jobInstanceDao = jobInstanceDao;
    this.pipelineTimeline = pipelineTimeline;
    this.transactionTemplate = transactionTemplate;
    this.transactionSynchronizationManager = transactionSynchronizationManager;
    this.goCache = goCache;
    this.pipelineService = pipelineService;
    this.instanceFactory = instanceFactory;
    this.jobAgentMetadataDao = jobAgentMetadataDao;
    this.pipelineDao = (PipelineSqlMapDao) pipelineDao;
    this.materialRepository = materialRepository;
    this.agentDao = agentDao;
    setSessionFactory(sessionFactory);
    initialize(dataSource);
}
 
Example #3
Source File: DatabaseAccessHelper.java    From gocd with Apache License 2.0 5 votes vote down vote up
private void initialize(DataSource dataSource) throws AmbiguousTableNameException {
    databaseTester = new DataSourceDatabaseTester(dataSource);
    databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
    databaseTester.setTearDownOperation(DatabaseOperation.DELETE_ALL);
    DefaultDataSet dataSet = new DefaultDataSet();
    dataSet.addTable(new DefaultTable("agents"));

    dataSet.addTable(new DefaultTable("pipelines"));
    dataSet.addTable(new DefaultTable("pipelinestates"));
    dataSet.addTable(new DefaultTable("materials"));
    dataSet.addTable(new DefaultTable("modifications"));
    dataSet.addTable(new DefaultTable("pipelineMaterialRevisions"));
    dataSet.addTable(new DefaultTable("modifiedFiles"));

    dataSet.addTable(new DefaultTable("notificationfilters"));
    dataSet.addTable(new DefaultTable("users"));
    dataSet.addTable(new DefaultTable("stages"));
    dataSet.addTable(new DefaultTable("pipelineLabelCounts"));
    dataSet.addTable(new DefaultTable("environmentVariables"));
    dataSet.addTable(new DefaultTable("artifactPlans"));
    dataSet.addTable(new DefaultTable("buildStateTransitions"));
    dataSet.addTable(new DefaultTable("resources"));
    dataSet.addTable(new DefaultTable("builds"));

    dataSet.addTable(new DefaultTable("stageArtifactCleanupProhibited"));
    dataSet.addTable(new DefaultTable("serverBackups"));
    dataSet.addTable(new DefaultTable("jobAgentMetadata"));
    dataSet.addTable(new DefaultTable("DataSharingSettings"));
    dataSet.addTable(new DefaultTable("UsageDataReporting"));
    dataSet.addTable(new DefaultTable("AccessToken"));

    databaseTester.setDataSet(dataSet);
}
 
Example #4
Source File: DBUnitDataExtractor.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
private void addTables(final QueryDataSet dataSet) throws AmbiguousTableNameException {
    if (tableList == null) {
        return;
    }
    for (Object element : tableList) {
        String table = (String) element;
        dataSet.addTable(table);
    }
}
 
Example #5
Source File: DBUnitTestExecutionListener.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Return a data set for export. A sort filter is used for the foreign key.
 *
 * @param tables
 *            which table should be exported.
 * @param con
 *            is used for the export
 *
 * @return the export data set
 *
 * @throws DataSetException
 * @throws SQLException
 * @throws AmbiguousTableNameException
 */
private IDataSet getDataSetToExport(final String[] tables,
		final IDatabaseConnection con) throws DataSetException,
		SQLException, AmbiguousTableNameException {
	final ITableFilter filter = new DatabaseSequenceFilter(con);
	IDataSet dataSetToExport = null;
	if (tables == null || tables.length == 0) {
		// want a complete database export
		dataSetToExport = con.createDataSet();
		dataSetToExport = new FilteredDataSet(filter, dataSetToExport);
	} else {
		final QueryDataSet qDataSet = new QueryDataSet(con);
		// generate the data set
		if (tables.length % 2 != 0) {
			throw new IllegalArgumentException(
					"Contract {<Table Name>,<SELECT_QUERY>} is brocken.");
		}
		for (int i = 0; i < tables.length; i += 2) {
			final String table = tables[i].toUpperCase();
			String query = tables[i + 1];
			if (query == null || query.trim().length() == 0) {
				query = "SELECT * FROM " + table;
			}

			qDataSet.addTable(table, query);
		}

		dataSetToExport = qDataSet;
	}
	return dataSetToExport;
}
 
Example #6
Source File: DataSetExecutorImpl.java    From database-rider with Apache License 2.0 4 votes vote down vote up
private IDataSet performTableOrdering(DataSetConfig dataSet, IDataSet target) throws AmbiguousTableNameException {
    if (dataSet.getTableOrdering().length > 0) {
        target = new FilteredDataSet(new SequenceTableFilter(dataSet.getTableOrdering(), dbUnitConfig.isCaseSensitiveTableNames()), target);
    }
    return target;
}
 
Example #7
Source File: DatabaseAccessHelper.java    From gocd with Apache License 2.0 4 votes vote down vote up
@Deprecated // Should not be creating a new spring context for every test
public DatabaseAccessHelper() throws AmbiguousTableNameException {
    ClassPathXmlApplicationContext context = createDataContext();
    dataSource = (DataSource) context.getBean("dataSource");
    initialize(dataSource);
}
 
Example #8
Source File: DatabaseAccessHelper.java    From gocd with Apache License 2.0 4 votes vote down vote up
@Deprecated //use Autowired version
public DatabaseAccessHelper(DataSource dataSource) throws AmbiguousTableNameException {
    this.dataSource = dataSource;
    initialize(dataSource);
}