diff --git a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/CachingJdbcClient.java b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/CachingJdbcClient.java index 6d59fdfb4ed3..be069cce6b5f 100644 --- a/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/CachingJdbcClient.java +++ b/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/CachingJdbcClient.java @@ -51,7 +51,6 @@ import java.sql.SQLException; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.OptionalLong; import java.util.Set; @@ -60,7 +59,6 @@ import java.util.function.Predicate; import static com.google.common.base.MoreObjects.firstNonNull; -import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Throwables.throwIfInstanceOf; import static com.google.common.collect.ImmutableList.toImmutableList; @@ -624,149 +622,41 @@ private static void invalidateCache(Cache cache, Predicate filte cache.invalidateAll(cacheKeys); } - private static final class ColumnsCacheKey + private record ColumnsCacheKey(IdentityCacheKey identity, Map sessionProperties, SchemaTableName table) { - private final IdentityCacheKey identity; - private final SchemaTableName table; - private final Map sessionProperties; - - private ColumnsCacheKey(IdentityCacheKey identity, Map sessionProperties, SchemaTableName table) - { - this.identity = requireNonNull(identity, "identity is null"); - this.sessionProperties = ImmutableMap.copyOf(requireNonNull(sessionProperties, "sessionProperties is null")); - this.table = requireNonNull(table, "table is null"); - } - - public IdentityCacheKey getIdentity() + @SuppressWarnings("UnusedVariable") // TODO: Remove once https://github.com/google/error-prone/issues/2713 is fixed + private ColumnsCacheKey { - return identity; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ColumnsCacheKey that = (ColumnsCacheKey) o; - return Objects.equals(identity, that.identity) && - Objects.equals(sessionProperties, that.sessionProperties) && - Objects.equals(table, that.table); - } - - @Override - public int hashCode() - { - return Objects.hash(identity, sessionProperties, table); - } - - @Override - public String toString() - { - return toStringHelper(this) - .add("identity", identity) - .add("sessionProperties", sessionProperties) - .add("table", table) - .toString(); + requireNonNull(identity, "identity is null"); + sessionProperties = ImmutableMap.copyOf(requireNonNull(sessionProperties, "sessionProperties is null")); + requireNonNull(table, "table is null"); } } - private static final class TableHandlesByNameCacheKey + private record TableHandlesByNameCacheKey(IdentityCacheKey identity, SchemaTableName tableName) { - private final IdentityCacheKey identity; - private final SchemaTableName tableName; - - private TableHandlesByNameCacheKey(IdentityCacheKey identity, SchemaTableName tableName) - { - this.identity = requireNonNull(identity, "identity is null"); - this.tableName = requireNonNull(tableName, "tableName is null"); - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TableHandlesByNameCacheKey that = (TableHandlesByNameCacheKey) o; - return Objects.equals(identity, that.identity) && - Objects.equals(tableName, that.tableName); - } - - @Override - public int hashCode() + private TableHandlesByNameCacheKey { - return Objects.hash(identity, tableName); + requireNonNull(identity, "identity is null"); + requireNonNull(tableName, "tableName is null"); } } - private static final class TableHandlesByQueryCacheKey + private record TableHandlesByQueryCacheKey(IdentityCacheKey identity, PreparedQuery preparedQuery) { - private final IdentityCacheKey identity; - private final PreparedQuery preparedQuery; - - private TableHandlesByQueryCacheKey(IdentityCacheKey identity, PreparedQuery preparedQuery) + private TableHandlesByQueryCacheKey { - this.identity = requireNonNull(identity, "identity is null"); - this.preparedQuery = requireNonNull(preparedQuery, "preparedQuery is null"); - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TableHandlesByQueryCacheKey that = (TableHandlesByQueryCacheKey) o; - return Objects.equals(identity, that.identity) && - Objects.equals(preparedQuery, that.preparedQuery); - } - - @Override - public int hashCode() - { - return Objects.hash(identity, preparedQuery); + requireNonNull(identity, "identity is null"); + requireNonNull(preparedQuery, "preparedQuery is null"); } } - private static final class TableNamesCacheKey + private record TableNamesCacheKey(IdentityCacheKey identity, Optional schemaName) { - private final IdentityCacheKey identity; - private final Optional schemaName; - - private TableNamesCacheKey(IdentityCacheKey identity, Optional schemaName) - { - this.identity = requireNonNull(identity, "identity is null"); - this.schemaName = requireNonNull(schemaName, "schemaName is null"); - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TableNamesCacheKey that = (TableNamesCacheKey) o; - return Objects.equals(identity, that.identity) && - Objects.equals(schemaName, that.schemaName); - } - - @Override - public int hashCode() + private TableNamesCacheKey { - return Objects.hash(identity, schemaName); + requireNonNull(identity, "identity is null"); + requireNonNull(schemaName, "schemaName is null"); } }