/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * 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.
 * </p>
 */

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import com.google.common.base.Optional;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import io.shardingsphere.core.parsing.parser.sql.SQLStatement;
import io.shardingsphere.core.parsing.parser.sql.ddl.create.table.CreateTableStatement;
import org.antlr.v4.runtime.ParserRuleContext;

/**
 * Create table primary key extract handler.
 * 
 * @author duhongjun
 */
public final class CreatePrimaryKeyExtractHandler implements ASTExtractHandler {
    
    @Override
    public void extract(final ParserRuleContext ancestorNode, final SQLStatement statement) {
        CreateTableStatement createTableStatement = (CreateTableStatement) statement;
        Optional<ParserRuleContext> primaryKeyNode = ASTUtils.findFirstChildNode(ancestorNode, RuleName.PRIMARY_KEY);
        if (!primaryKeyNode.isPresent()) {
            return;
        }
        Optional<ParserRuleContext> columnListNode = ASTUtils.findFirstChildNode(primaryKeyNode.get().getParent().getParent(), RuleName.COLUMN_LIST);
        if (!columnListNode.isPresent()) {
            return;
        }
        for (ParserRuleContext each : ASTUtils.getAllDescendantNodes(columnListNode.get(), RuleName.COLUMN_NAME)) {
            if (!createTableStatement.getPrimaryKeyColumns().contains(each.getText())) {
                createTableStatement.getPrimaryKeyColumns().add(each.getText());
            }
        }
    }
}

@@ -699,39 +699,286 @@
 ort 
-com.google.common.base.Optional
+org.antlr.v4.runtime.ParserRuleContext;%0A%0Aimport com.google.common.base.Optional;%0A%0Aimport io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.ExtractResult;%0Aimport io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.PrimaryKeyExtractResult
 ;%0Aim
@@ -1208,55 +1208,8 @@
 ent;
-%0Aimport org.antlr.v4.runtime.ParserRuleContext;
 %0A%0A/*
@@ -1362,16 +1362,35 @@
 tHandler
+,ASTExtractHandler1
  %7B%0A    %0A
@@ -2289,32 +2289,32 @@
 ;%0A            %7D%0A
-
         %7D%0A    %7D%0A
@@ -2312,11 +2312,859 @@
  %7D%0A    %7D
+%0A%0A    @Override%0A    public ExtractResult extract(ParserRuleContext ancestorNode) %7B%0A        PrimaryKeyExtractResult extractResult = new PrimaryKeyExtractResult();%0A        Optional%3CParserRuleContext%3E primaryKeyNode = ASTUtils.findFirstChildNode(ancestorNode, RuleName.PRIMARY_KEY);%0A        if (!primaryKeyNode.isPresent()) %7B%0A            return extractResult;%0A        %7D%0A        Optional%3CParserRuleContext%3E columnListNode = ASTUtils.findFirstChildNode(primaryKeyNode.get().getParent().getParent(), RuleName.COLUMN_LIST);%0A        if (!columnListNode.isPresent()) %7B%0A            return extractResult;%0A        %7D%0A        for (ParserRuleContext each : ASTUtils.getAllDescendantNodes(columnListNode.get(), RuleName.COLUMN_NAME)) %7B%0A            extractResult.getPrimaryKeyColumnNames().add(each.getText());%0A        %7D%0A        %0A        return extractResult;%0A    %7D
 %0A%7D%0A

implement ASTExtractHandler1