Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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 com.facebook.presto.execution;
 
 
 
 import java.net.URI;
 import java.util.Map;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public class DataDefinitionExecution<T extends Statement>
         implements QueryExecution
 {
     private final DataDefinitionTask<T> task;
     private final T statement;
     private final Session session;
     private final Metadata metadata;
     private final QueryStateMachine stateMachine;
 
     private DataDefinitionExecution(
             DataDefinitionTask<T> task,
             T statement,
             Session session,
             Metadata metadata,
             QueryStateMachine stateMachine)
     {
         this. = checkNotNull(task"task is null");
         this. = checkNotNull(statement"statement is null");
         this. = checkNotNull(session"session is null");
         this. = checkNotNull(metadata"metadata is null");
         this. = checkNotNull(stateMachine"stateMachine is null");
     }
 
     @Override
     {
         return .getMemoryPool();
     }
 
     @Override
     public void setMemoryPool(VersionedMemoryPoolId poolId)
     {
         .setMemoryPool(poolId);
     }
 
     @Override
     public long getTotalMemoryReservation()
     {
         return 0;
     }
 
     @Override
     public void start()
     {
         try {
             // transition to running
             if (!.transitionToRunning()) {
                 // query already running or finished
                 return;
             }
 
             .execute();
 
             .transitionToFinished();
         }
         catch (Throwable e) {
             fail(e);
             if (!(e instanceof RuntimeException)) {
                 throw Throwables.propagate(e);
             }
         }
     }
 
     @Override
     public Duration waitForStateChange(QueryState currentStateDuration maxWait)
             throws InterruptedException
    {
        return .waitForStateChange(currentStatemaxWait);
    }
    @Override
    public void addStateChangeListener(StateChangeListener<QueryStatestateChangeListener)
    {
        .addStateChangeListener(stateChangeListener);
    }
    @Override
    public void fail(Throwable cause)
    {
        .transitionToFailed(cause);
    }
    @Override
    public void cancelStage(StageId stageId)
    {
        // no-op
    }
    @Override
    public void recordHeartbeat()
    {
        .recordHeartbeat();
    }
    @Override
    public void pruneInfo()
    {
        // no-op
    }
    @Override
    public QueryId getQueryId()
    {
        return .getQueryId();
    }
    @Override
    public QueryInfo getQueryInfo()
    {
        return .getQueryInfoWithoutDetails();
    }
    @Override
    public QueryState getState()
    {
        return .getQueryState();
    }
    public static class DataDefinitionExecutionFactory
            implements QueryExecutionFactory<DataDefinitionExecution<?>>
    {
        private final LocationFactory locationFactory;
        private final Metadata metadata;
        private final ExecutorService executor;
        private final Map<Class<? extends Statement>, DataDefinitionTask<?>> tasks;
        @Inject
        public DataDefinitionExecutionFactory(
                LocationFactory locationFactory,
                MetadataManager metadata,
                @ForQueryExecution ExecutorService executor,
                Map<Class<? extends Statement>, DataDefinitionTask<?>> tasks)
        {
            this. = checkNotNull(locationFactory"locationFactory is null");
            this. = checkNotNull(metadata"metadata is null");
            this. = checkNotNull(executor"executor is null");
            this. = checkNotNull(tasks"tasks is null");
        }
        @Override
                QueryId queryId,
                String query,
                Session session,
                Statement statement)
        {
            URI self = .createQueryLocation(queryId);
            QueryStateMachine stateMachine = new QueryStateMachine(queryIdquerysessionself);
            return createExecution(statementsessionstateMachine);
        }
        private <T extends StatementDataDefinitionExecution<?> createExecution(
                T statement,
                Session session,
                QueryStateMachine stateMachine)
        {
            DataDefinitionTask<T> task = getTask(statement);
            checkArgument(task != null"no task for statement: %s"statement.getClass().getSimpleName());
            stateMachine.setUpdateType(task.getName());
            return new DataDefinitionExecution<>(taskstatementsessionstateMachine);
        }
        @SuppressWarnings("unchecked")
        private <T extends StatementDataDefinitionTask<T> getTask(T statement)
        {
            return (DataDefinitionTask<T>) .get(statement.getClass());
        }
    }
New to GrepCode? Check out our FAQ X