Ejemplo n.º 1
0
  @Before
  public void setup() throws SQLException {
    _connectorRepository.addConnectionInfo(DB, new TestDerbyConnectionInfo());
    _connectorRepository.addConnectorHint(DB, new RandomTableOrderHint());

    new ScriptExecutorTool(_connectorRepository).executeFileScript(DB, "/ddl/tables.sql");

    _tableMetaData = TableOrderHint.getSortedTables(_connectorRepository, DB);
  }
  public void checkTableData(final String sourceConnectorId, final String targetConnectorId)
      throws SQLException {
    final List<TableMetaData> tableSourceMetaDatas =
        TableOrderHint.getSortedTables(_connectorRepository, sourceConnectorId);
    final int numberOfCheckData =
        _connectorRepository
            .getConnectorHint(sourceConnectorId, NumberOfCheckedTableData.class)
            .getValue()
            .getNumberOfCheckedTableData();

    final TableMapper tableMapper =
        _connectorRepository.getConnectorHint(targetConnectorId, TableMapper.class).getValue();
    final DatabaseMetaData targetDatabaseMetaData =
        _connectorRepository.getDatabaseMetaData(targetConnectorId);

    final SourceDatabaseConfiguration sourceDatabaseConfiguration1 =
        _connectorRepository.getSourceDatabaseConfiguration(sourceConnectorId);
    final SourceDatabaseConfiguration sourceDatabaseConfiguration2 =
        _connectorRepository.getSourceDatabaseConfiguration(targetConnectorId);
    final Connector connector1 = _connectorRepository.createConnector(sourceConnectorId);
    final Connector connector2 = _connectorRepository.createConnector(targetConnectorId);
    final Connection connection1 = connector1.openConnection();
    final Connection connection2 = connector2.openConnection();

    sourceDatabaseConfiguration1.initializeSourceConnection(connection1, sourceConnectorId);
    sourceDatabaseConfiguration2.initializeSourceConnection(connection2, targetConnectorId);

    for (final TableMetaData tableSourceMetaData : tableSourceMetaDatas) {
      final TableMetaData tableDestMetaData =
          tableMapper.map(tableSourceMetaData, targetDatabaseMetaData);

      if (tableDestMetaData == null) {
        throw new TableConfigurationException(
            "No matching table for " + tableSourceMetaData + " in target data base!!!");
      }

      checkTableData(
          sourceConnectorId,
          connection1,
          sourceDatabaseConfiguration1,
          tableSourceMetaData,
          targetConnectorId,
          connection2,
          sourceDatabaseConfiguration2,
          tableDestMetaData,
          numberOfCheckData);
    }

    sourceDatabaseConfiguration1.finalizeSourceConnection(connection1, sourceConnectorId);
    sourceDatabaseConfiguration2.finalizeSourceConnection(connection2, targetConnectorId);

    connector1.closeConnection();
    connector2.closeConnection();
  }