@Test public void cacheIsActuallyUsed() throws TableMappingNotFoundException { when(resultSet.size()).thenReturn(1); AgnosticResultRow row = mock(AgnosticResultRow.class); when(row.getString(eq("short_table_name"))).thenReturn(SHORT_TABLE_NAME); doReturn(ImmutableList.of(row)).when(resultSet).rows(); String shortName = oracleTableNameUnmapper .getShortTableNameFromMappingTable(connectionSupplier, TEST_PREFIX, TABLE_REF_2); assertThat(shortName, is(SHORT_TABLE_NAME)); verify(row, times(1)).getString("short_table_name"); oracleTableNameUnmapper.getShortTableNameFromMappingTable(connectionSupplier, TEST_PREFIX, TABLE_REF_2); verify(row, times(1)).getString("short_table_name"); }
@SuppressWarnings("checkstyle:NestedTryDepth") public String getShortTableNameFromMappingTable( ConnectionSupplier connectionSupplier, String tablePrefix, TableReference tableRef) throws TableMappingNotFoundException { String fullTableName = tablePrefix + DbKvs.internalTableName(tableRef); try { return unmappingCache.get(fullTableName, () -> { SqlConnection conn = connectionSupplier.get(); AgnosticResultSet results = conn.selectResultSetUnregisteredQuery( "SELECT short_table_name " + "FROM " + AtlasDbConstants.ORACLE_NAME_MAPPING_TABLE + " WHERE table_name = ?", fullTableName); if (results.size() == 0) { throw new TableMappingNotFoundException( "The table " + fullTableName + " does not have a mapping." + "This might be because the table does not exist."); } return Iterables.getOnlyElement(results.rows()).getString("short_table_name"); }); } catch (ExecutionException e) { throw new TableMappingNotFoundException(e.getCause()); } }
OracleTableNameUnmapper { @SuppressWarnings("checkstyle:NestedTryDepth") public String getShortTableNameFromMappingTable( ConnectionSupplier connectionSupplier, String tablePrefix, TableReference tableRef) throws TableMappingNotFoundException { String fullTableName = tablePrefix + DbKvs.internalTableName(tableRef); try { return unmappingCache.get(fullTableName, () -> { SqlConnection conn = connectionSupplier.get(); AgnosticResultSet results = conn.selectResultSetUnregisteredQuery( "SELECT short_table_name " + "FROM " + AtlasDbConstants.ORACLE_NAME_MAPPING_TABLE + " WHERE table_name = ?", fullTableName); if (results.size() == 0) { throw new TableMappingNotFoundException( "The table " + fullTableName + " does not have a mapping." + "This might be because the table does not exist."); } return Iterables.getOnlyElement(results.rows()).getString("short_table_name"); }); } catch (ExecutionException e) { throw new TableMappingNotFoundException(e.getCause()); } } }
OracleTableNameUnmapper { @SuppressWarnings("checkstyle:NestedTryDepth") public String getShortTableNameFromMappingTable( ConnectionSupplier connectionSupplier, String tablePrefix, TableReference tableRef) throws TableMappingNotFoundException { String fullTableName = tablePrefix + DbKvs.internalTableName(tableRef); try { return unmappingCache.get(fullTableName, () -> { SqlConnection conn = connectionSupplier.get(); AgnosticResultSet results = conn.selectResultSetUnregisteredQuery( "SELECT short_table_name " + "FROM " + AtlasDbConstants.ORACLE_NAME_MAPPING_TABLE + " WHERE table_name = ?", fullTableName); if (results.size() == 0) { throw new TableMappingNotFoundException( "The table " + fullTableName + " does not have a mapping." + "This might be because the table does not exist."); } return Iterables.getOnlyElement(results.rows()).getString("short_table_name"); }); } catch (ExecutionException e) { throw new TableMappingNotFoundException(e.getCause()); } } OracleTableNameUnmapper(); }
OracleTableNameUnmapper { @SuppressWarnings("checkstyle:NestedTryDepth") public String getShortTableNameFromMappingTable( ConnectionSupplier connectionSupplier, String tablePrefix, TableReference tableRef) throws TableMappingNotFoundException { String fullTableName = tablePrefix + DbKvs.internalTableName(tableRef); try { return unmappingCache.get(fullTableName, () -> { SqlConnection conn = connectionSupplier.get(); AgnosticResultSet results = conn.selectResultSetUnregisteredQuery( "SELECT short_table_name " + "FROM " + AtlasDbConstants.ORACLE_NAME_MAPPING_TABLE + " WHERE table_name = ?", fullTableName); if (results.size() == 0) { throw new TableMappingNotFoundException( "The table " + fullTableName + " does not have a mapping." + "This might be because the table does not exist."); } return Iterables.getOnlyElement(results.rows()).getString("short_table_name"); }); } catch (ExecutionException e) { throw new TableMappingNotFoundException(e.getCause()); } } OracleTableNameUnmapper(); @SuppressWarnings("checkstyle:NestedTryDepth") String getShortTableNameFromMappingTable(
            ConnectionSupplier connectionSupplier,
            String tablePrefix,
            TableReference tableRef); void clearCacheForTable(String fullTableName); }
OracleTableNameUnmapper { @SuppressWarnings("checkstyle:NestedTryDepth") public String getShortTableNameFromMappingTable( ConnectionSupplier connectionSupplier, String tablePrefix, TableReference tableRef) throws TableMappingNotFoundException { String fullTableName = tablePrefix + DbKvs.internalTableName(tableRef); try { return unmappingCache.get(fullTableName, () -> { SqlConnection conn = connectionSupplier.get(); AgnosticResultSet results = conn.selectResultSetUnregisteredQuery( "SELECT short_table_name " + "FROM " + AtlasDbConstants.ORACLE_NAME_MAPPING_TABLE + " WHERE table_name = ?", fullTableName); if (results.size() == 0) { throw new TableMappingNotFoundException( "The table " + fullTableName + " does not have a mapping." + "This might be because the table does not exist."); } return Iterables.getOnlyElement(results.rows()).getString("short_table_name"); }); } catch (ExecutionException e) { throw new TableMappingNotFoundException(e.getCause()); } } OracleTableNameUnmapper(); @SuppressWarnings("checkstyle:NestedTryDepth") String getShortTableNameFromMappingTable(
            ConnectionSupplier connectionSupplier,
            String tablePrefix,
            TableReference tableRef); void clearCacheForTable(String fullTableName);  }