diff --git a/core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorContext.java b/core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorContext.java index 07f8a7f4742d..db8c9d653b98 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorContext.java +++ b/core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorContext.java @@ -79,6 +79,7 @@ default PageIndexerFactory getPageIndexerFactory() throw new UnsupportedOperationException(); } + @Deprecated(forRemoval = true) default ClassLoader duplicatePluginClassLoader() { throw new UnsupportedOperationException(); diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConnectorFactory.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConnectorFactory.java index 01140d080070..df3cc06f5b77 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConnectorFactory.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConnectorFactory.java @@ -18,12 +18,12 @@ import io.trino.spi.connector.ConnectorContext; import io.trino.spi.connector.ConnectorFactory; -import java.lang.reflect.InvocationTargetException; import java.util.Map; import java.util.Optional; -import static com.google.common.base.Throwables.throwIfUnchecked; +import static com.google.inject.util.Modules.EMPTY_MODULE; import static io.trino.plugin.base.Versions.checkStrictSpiVersionMatch; +import static io.trino.plugin.deltalake.InternalDeltaLakeConnectorFactory.createConnector; import static java.util.Objects.requireNonNull; public class DeltaLakeConnectorFactory @@ -31,9 +31,14 @@ public class DeltaLakeConnectorFactory { public static final String CONNECTOR_NAME = "delta_lake"; - private final Class module; + private final Module module; - public DeltaLakeConnectorFactory(Class module) + public DeltaLakeConnectorFactory() + { + this(EMPTY_MODULE); + } + + public DeltaLakeConnectorFactory(Module module) { this.module = requireNonNull(module, "module is null"); } @@ -48,22 +53,6 @@ public String getName() public Connector create(String catalogName, Map config, ConnectorContext context) { checkStrictSpiVersionMatch(context, this); - - ClassLoader classLoader = context.duplicatePluginClassLoader(); - try { - Class moduleClass = classLoader.loadClass(Module.class.getName()); - Object moduleInstance = classLoader.loadClass(module.getName()).getConstructor().newInstance(); - return (Connector) classLoader.loadClass(InternalDeltaLakeConnectorFactory.class.getName()) - .getMethod("createConnector", String.class, Map.class, ConnectorContext.class, Optional.class, Optional.class, moduleClass) - .invoke(null, catalogName, config, context, Optional.empty(), Optional.empty(), moduleInstance); - } - catch (InvocationTargetException e) { - Throwable targetException = e.getTargetException(); - throwIfUnchecked(targetException); - throw new RuntimeException(targetException); - } - catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + return createConnector(catalogName, config, context, Optional.empty(), Optional.empty(), module); } } diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakePlugin.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakePlugin.java index f4263e59dd80..f4b44d0e95de 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakePlugin.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakePlugin.java @@ -14,8 +14,6 @@ package io.trino.plugin.deltalake; import com.google.common.collect.ImmutableList; -import com.google.inject.Module; -import io.trino.plugin.hive.HiveConnectorFactory.EmptyModule; import io.trino.spi.Plugin; import io.trino.spi.connector.ConnectorFactory; @@ -25,11 +23,6 @@ public class DeltaLakePlugin @Override public Iterable getConnectorFactories() { - return ImmutableList.of(getConnectorFactory(EmptyModule.class)); - } - - public ConnectorFactory getConnectorFactory(Class module) - { - return new DeltaLakeConnectorFactory(module); + return ImmutableList.of(new DeltaLakeConnectorFactory()); } } diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveConnectorFactory.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveConnectorFactory.java index f7e50db00269..d2a861c28e04 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveConnectorFactory.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveConnectorFactory.java @@ -13,30 +13,29 @@ */ package io.trino.plugin.hive; -import com.google.inject.Binder; import com.google.inject.Module; import io.trino.spi.connector.Connector; import io.trino.spi.connector.ConnectorContext; import io.trino.spi.connector.ConnectorFactory; -import java.lang.reflect.InvocationTargetException; import java.util.Map; -import static com.google.common.base.Throwables.throwIfUnchecked; +import static com.google.inject.util.Modules.EMPTY_MODULE; import static io.trino.plugin.base.Versions.checkStrictSpiVersionMatch; +import static io.trino.plugin.hive.InternalHiveConnectorFactory.createConnector; import static java.util.Objects.requireNonNull; public class HiveConnectorFactory implements ConnectorFactory { - private final Class module; + private final Module module; public HiveConnectorFactory() { - this(EmptyModule.class); + this(EMPTY_MODULE); } - public HiveConnectorFactory(Class module) + public HiveConnectorFactory(Module module) { this.module = requireNonNull(module, "module is null"); } @@ -51,29 +50,6 @@ public String getName() public Connector create(String catalogName, Map config, ConnectorContext context) { checkStrictSpiVersionMatch(context, this); - - ClassLoader classLoader = context.duplicatePluginClassLoader(); - try { - Object moduleInstance = classLoader.loadClass(module.getName()).getConstructor().newInstance(); - Class moduleClass = classLoader.loadClass(Module.class.getName()); - return (Connector) classLoader.loadClass(InternalHiveConnectorFactory.class.getName()) - .getMethod("createConnector", String.class, Map.class, ConnectorContext.class, moduleClass) - .invoke(null, catalogName, config, context, moduleInstance); - } - catch (InvocationTargetException e) { - Throwable targetException = e.getTargetException(); - throwIfUnchecked(targetException); - throw new RuntimeException(targetException); - } - catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - public static class EmptyModule - implements Module - { - @Override - public void configure(Binder binder) {} + return createConnector(catalogName, config, context, module); } } diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiConnectorFactory.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiConnectorFactory.java index 98d1a49cc3e2..21c7a6c03e3e 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiConnectorFactory.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/HudiConnectorFactory.java @@ -17,19 +17,15 @@ import io.trino.spi.connector.ConnectorContext; import io.trino.spi.connector.ConnectorFactory; -import java.lang.reflect.InvocationTargetException; import java.util.Map; import java.util.Optional; -import static com.google.common.base.Throwables.throwIfUnchecked; import static io.trino.plugin.base.Versions.checkStrictSpiVersionMatch; +import static io.trino.plugin.hudi.InternalHudiConnectorFactory.createConnector; public class HudiConnectorFactory implements ConnectorFactory { - public HudiConnectorFactory() - {} - @Override public String getName() { @@ -40,20 +36,6 @@ public String getName() public Connector create(String catalogName, Map config, ConnectorContext context) { checkStrictSpiVersionMatch(context, this); - - ClassLoader classLoader = context.duplicatePluginClassLoader(); - try { - return (Connector) classLoader.loadClass(InternalHudiConnectorFactory.class.getName()) - .getMethod("createConnector", String.class, Map.class, ConnectorContext.class, Optional.class, Optional.class) - .invoke(null, catalogName, config, context, Optional.empty(), Optional.empty()); - } - catch (InvocationTargetException e) { - Throwable targetException = e.getTargetException(); - throwIfUnchecked(targetException); - throw new RuntimeException(targetException); - } - catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + return createConnector(catalogName, config, context, Optional.empty(), Optional.empty()); } } diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergConnectorFactory.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergConnectorFactory.java index 39e2c9e52617..22aa76c52b52 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergConnectorFactory.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergConnectorFactory.java @@ -13,31 +13,30 @@ */ package io.trino.plugin.iceberg; -import com.google.inject.Binder; import com.google.inject.Module; import io.trino.spi.connector.Connector; import io.trino.spi.connector.ConnectorContext; import io.trino.spi.connector.ConnectorFactory; -import java.lang.reflect.InvocationTargetException; import java.util.Map; import java.util.Optional; -import static com.google.common.base.Throwables.throwIfUnchecked; +import static com.google.inject.util.Modules.EMPTY_MODULE; import static io.trino.plugin.base.Versions.checkStrictSpiVersionMatch; +import static io.trino.plugin.iceberg.InternalIcebergConnectorFactory.createConnector; import static java.util.Objects.requireNonNull; public class IcebergConnectorFactory implements ConnectorFactory { - private final Class module; + private final Module module; public IcebergConnectorFactory() { - this(EmptyModule.class); + this(EMPTY_MODULE); } - public IcebergConnectorFactory(Class module) + public IcebergConnectorFactory(Module module) { this.module = requireNonNull(module, "module is null"); } @@ -52,29 +51,6 @@ public String getName() public Connector create(String catalogName, Map config, ConnectorContext context) { checkStrictSpiVersionMatch(context, this); - - ClassLoader classLoader = context.duplicatePluginClassLoader(); - try { - Object moduleInstance = classLoader.loadClass(module.getName()).getConstructor().newInstance(); - Class moduleClass = classLoader.loadClass(Module.class.getName()); - return (Connector) classLoader.loadClass(InternalIcebergConnectorFactory.class.getName()) - .getMethod("createConnector", String.class, Map.class, ConnectorContext.class, moduleClass, Optional.class, Optional.class) - .invoke(null, catalogName, config, context, moduleInstance, Optional.empty(), Optional.empty()); - } - catch (InvocationTargetException e) { - Throwable targetException = e.getTargetException(); - throwIfUnchecked(targetException); - throw new RuntimeException(targetException); - } - catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - public static class EmptyModule - implements Module - { - @Override - public void configure(Binder binder) {} + return createConnector(catalogName, config, context, module, Optional.empty(), Optional.empty()); } }