@Test public void testShouldPerformPreDMLLogicIfClusterNameColumnExists() throws Exception { reset(dbAccessor); expect(dbAccessor.getConnection()).andReturn(connection).anyTimes(); expect(connection.createStatement()).andReturn(statement); Capture<String> tableNameCaptor = newCapture(); Capture<String> columnNameCaptor = newCapture(); expect(dbAccessor.tableHasColumn(capture(tableNameCaptor), capture(columnNameCaptor))).andReturn(true); expect(statement.executeQuery(anyString())).andReturn(resultSet); statement.close(); expect(resultSet.next()).andReturn(false); resultSet.close(); replay(dbAccessor, connection, statement, resultSet); testSubject.executePreDMLUpdates(); Assert.assertNotNull("The table name hasn't been captured", tableNameCaptor.getValue()); Assert.assertEquals("The table name is not as expected", TOPOLOGY_REQUEST_TABLE, tableNameCaptor.getValue()); Assert.assertNotNull("The column name hasn't been captured", columnNameCaptor.getValue()); Assert.assertEquals("The column name is not as expected", TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN, columnNameCaptor.getValue()); verify(dbAccessor, statement, resultSet); }
@Override protected void executePreDMLUpdates() throws AmbariException, SQLException { if (dbAccessor.tableHasColumn(TOPOLOGY_REQUEST_TABLE, TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN)) { addClusterIdToTopology(); finilizeTopologyDDL(); } else { LOG.debug("The column: [ {} ] has already been dropped from table: [ {} ]. Skipping preDMLUpdate logic.", TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN, TOPOLOGY_REQUEST_TABLE); } }
UpgradeCatalog212 extends AbstractUpgradeCatalog { @Override protected void executePreDMLUpdates() throws AmbariException, SQLException { if (dbAccessor.tableHasColumn(TOPOLOGY_REQUEST_TABLE, TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN)) { addClusterIdToTopology(); finilizeTopologyDDL(); } else { LOG.debug("The column: [ {} ] has already been dropped from table: [ {} ]. Skipping preDMLUpdate logic.", TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN, TOPOLOGY_REQUEST_TABLE); } } }
UpgradeCatalog212 extends AbstractUpgradeCatalog { @Override protected void executePreDMLUpdates() throws AmbariException, SQLException { if (dbAccessor.tableHasColumn(TOPOLOGY_REQUEST_TABLE, TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN)) { addClusterIdToTopology(); finilizeTopologyDDL(); } else { LOG.debug("The column: [ {} ] has already been dropped from table: [ {} ]. Skipping preDMLUpdate logic.", TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN, TOPOLOGY_REQUEST_TABLE); } } @Inject  UpgradeCatalog212(Injector injector); protected  UpgradeCatalog212(); }
UpgradeCatalog212 extends AbstractUpgradeCatalog { @Override protected void executePreDMLUpdates() throws AmbariException, SQLException { if (dbAccessor.tableHasColumn(TOPOLOGY_REQUEST_TABLE, TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN)) { addClusterIdToTopology(); finilizeTopologyDDL(); } else { LOG.debug("The column: [ {} ] has already been dropped from table: [ {} ]. Skipping preDMLUpdate logic.", TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN, TOPOLOGY_REQUEST_TABLE); } } @Inject  UpgradeCatalog212(Injector injector); protected  UpgradeCatalog212(); @Override String getTargetVersion(); @Override String getSourceVersion(); }
UpgradeCatalog212 extends AbstractUpgradeCatalog { @Override protected void executePreDMLUpdates() throws AmbariException, SQLException { if (dbAccessor.tableHasColumn(TOPOLOGY_REQUEST_TABLE, TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN)) { addClusterIdToTopology(); finilizeTopologyDDL(); } else { LOG.debug("The column: [ {} ] has already been dropped from table: [ {} ]. Skipping preDMLUpdate logic.", TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN, TOPOLOGY_REQUEST_TABLE); } } @Inject  UpgradeCatalog212(Injector injector); protected  UpgradeCatalog212(); @Override String getTargetVersion(); @Override String getSourceVersion();  }