/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.prestosql.plugin.iceberg;

import io.prestosql.spi.connector.Connector;
import io.prestosql.spi.connector.ConnectorContext;
import io.prestosql.spi.connector.ConnectorFactory;

import java.util.Map;
import java.util.Optional;

import static io.prestosql.plugin.iceberg.InternalIcebergConnectorFactory.createConnector;

public class IcebergConnectorFactory
        implements ConnectorFactory
{
    @Override
    public String getName()
    {
        return "iceberg";
    }

    @Override
    public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
    {
        return createConnector(catalogName, config, context, Optional.empty());
    }
}

@@ -759,135 +759,162 @@
 ava.
-util.Map;%0Aimport java.util.Optional;%0A%0Aimport static io.prestosql.plugin.iceberg.InternalIcebergConnectorFactory.createConnector
+lang.reflect.InvocationTargetException;%0Aimport java.util.Map;%0Aimport java.util.Optional;%0A%0Aimport static com.google.common.base.Throwables.throwIfUnchecked
 ;%0A%0Ap
@@ -1202,79 +1202,721 @@
     
-return createConnector(catalogName, config, context, Optional.empty());
+ClassLoader classLoader = context.duplicatePluginClassLoader();%0A        try %7B%0A            return (Connector) classLoader.loadClass(InternalIcebergConnectorFactory.class.getName())%0A                    .getMethod(%22createConnector%22, String.class, Map.class, ConnectorContext.class, Optional.class)%0A                    .invoke(null, catalogName, config, context, Optional.empty());%0A        %7D%0A        catch (InvocationTargetException e) %7B%0A            Throwable targetException = e.getTargetException();%0A            throwIfUnchecked(targetException);%0A            throw new RuntimeException(targetException);%0A        %7D%0A        catch (ReflectiveOperationException e) %7B%0A            throw new RuntimeException(e);%0A        %7D
 %0A   

Use class loader isolation for Iceberg connector instances