/*
 * 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.hive;

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 com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static io.prestosql.plugin.hive.InternalHiveConnectorFactory.createConnector;

public class HiveConnectorFactory
        implements ConnectorFactory
{
    private final String name;

    public HiveConnectorFactory(String name)
    {
        checkArgument(!isNullOrEmpty(name), "name is null or empty");
        this.name = name;
    }

    @Override
    public String getName()
    {
        return name;
    }

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

@@ -740,16 +740,68 @@
 ctory;%0A%0A
+import java.lang.reflect.InvocationTargetException;%0A
 import j
@@ -814,16 +814,16 @@
 il.Map;%0A
-
 import j
@@ -986,77 +986,58 @@
 tic 
-io.prestosql.plugin.hive.InternalHiveConnectorFactory.createConnector
+com.google.common.base.Throwables.throwIfUnchecked
 ;%0A%0Ap
@@ -1503,79 +1503,718 @@
     
-return createConnector(catalogName, config, context, Optional.empty());
+ClassLoader classLoader = context.duplicatePluginClassLoader();%0A        try %7B%0A            return (Connector) classLoader.loadClass(InternalHiveConnectorFactory.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 Hive connector instances