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

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import io.shardingsphere.api.config.rule.TableRuleConfiguration;
import io.shardingsphere.core.keygen.KeyGeneratorFactory;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * Yaml key generator configuration.
 *
 * @author panjuan
 */
@NoArgsConstructor
@Getter
@Setter
public class YamlKeyGeneratorConfiguration {
    
    private String logicTable;
    
    private String actualDataNodes;
    
    private YamlShardingStrategyConfiguration databaseStrategy;
    
    private YamlShardingStrategyConfiguration tableStrategy;
    
    private String keyGeneratorColumnName;
    
    private String keyGeneratorClassName;
    
    private String logicIndex;
    
    public YamlKeyGeneratorConfiguration(final TableRuleConfiguration tableRuleConfiguration) {
        logicTable = tableRuleConfiguration.getLogicTable();
        actualDataNodes = tableRuleConfiguration.getActualDataNodes();
        databaseStrategy = new YamlShardingStrategyConfiguration(tableRuleConfiguration.getDatabaseShardingStrategyConfig());
        tableStrategy = new YamlShardingStrategyConfiguration(tableRuleConfiguration.getTableShardingStrategyConfig());
        keyGeneratorColumnName = tableRuleConfiguration.getKeyGeneratorColumnName();
        keyGeneratorClassName = null == tableRuleConfiguration.getKeyGenerator()
                ? null : tableRuleConfiguration.getKeyGenerator().getClass().getName();
    }
    
    /**
     * Build table rule configuration.
     *
     * @return table rule configuration
     */
    public TableRuleConfiguration build() {
        Preconditions.checkNotNull(logicTable, "Logic table cannot be null.");
        TableRuleConfiguration result = new TableRuleConfiguration();
        result.setLogicTable(logicTable);
        result.setActualDataNodes(actualDataNodes);
        if (null != databaseStrategy) {
            result.setDatabaseShardingStrategyConfig(databaseStrategy.build());
        }
        if (null != tableStrategy) {
            result.setTableShardingStrategyConfig(tableStrategy.build());
        }
        if (!Strings.isNullOrEmpty(keyGeneratorClassName)) {
            result.setKeyGenerator(KeyGeneratorFactory.newInstance(keyGeneratorClassName));
        }
        result.setKeyGeneratorColumnName(keyGeneratorColumnName);
        result.setLogicIndex(logicIndex);
        return result;
    }
}

@@ -694,125 +694,128 @@
 ase.
-Preconditions;%0Aimport com.google.common.base.Strings;%0Aimport io.shardingsphere.api.config.rule.TableRuleConfiguration
+Strings;%0Aimport io.shardingsphere.core.keygen.BuiltinKeyGeneratorType;%0Aimport io.shardingsphere.core.keygen.KeyGenerator
 ;%0Aim
@@ -948,16 +948,46 @@
 etter;%0A%0A
+import java.util.Properties;%0A%0A
 /**%0A * Y
@@ -1153,194 +1153,30 @@
 ing 
-logicTable;%0A    %0A    private String actualDataNodes;%0A    %0A    private YamlShardingStrategyConfiguration databaseStrategy;%0A    %0A    private YamlShardingStrategyConfiguration tableStrategy
+keyGeneratorColumnName
 ;%0A  
@@ -1205,33 +1205,27 @@
 keyGenerator
-ColumnNam
+Typ
 e;%0A    %0A    
@@ -1283,1398 +1283,360 @@
 ate 
-String logicIndex;%0A    %0A    public YamlKeyGeneratorConfiguration(final TableRuleConfiguration tableRuleConfiguration) %7B%0A        logicTable = tableRuleConfiguration.getLogicTable();%0A        actualDataNodes = tableRuleConfiguration.getActualDataNodes();%0A        databaseStrategy = new YamlShardingStrategyConfiguration(tableRuleConfiguration.getDatabaseShardingStrategyConfig());%0A        tableStrategy = new YamlShardingStrategyConfiguration(tableRuleConfiguration.getTableShardingStrategyConfig());%0A        keyGeneratorColumnName = tableRuleConfiguration.getKeyGeneratorColumnName();%0A        keyGeneratorClassName = null == tableRuleConfiguration.getKeyGenerator()%0A                ? null : tableRuleConfiguration.getKeyGenerator().getClass().getName();%0A    %7D%0A    %0A    /**%0A     * Build table rule configuration.%0A     *%0A     * @return table rule configuration%0A     */%0A    public TableRuleConfiguration build() %7B%0A        Preconditions.checkNotNull(logicTable, %22Logic table cannot be null.%22);%0A        TableRuleConfiguration result = new TableRuleConfiguration();%0A        result.setLogicTable(logicTable);%0A        result.setActualDataNodes(actualDataNodes);%0A        if (null != databaseStrategy) %7B%0A            result.setDatabaseShardingStrategyConfig(databaseStrategy.build());%0A        %7D%0A        if (null != tableStrategy) %7B%0A            result.setTableShardingStrategyConfig(tableStrategy.build()
+Properties props = new Properties();%0A    %0A    /**%0A     * Build table rule configuration.%0A     *%0A     * @return table rule configuration%0A     */%0A    public KeyGenerator getKeyGenerator() %7B%0A        KeyGenerator result;%0A        if (!Strings.isNullOrEmpty(keyGeneratorClassName)) %7B%0A            result = KeyGeneratorFactory.newInstance(keyGeneratorClassName
 );%0A 
@@ -1643,24 +1643,21 @@
        %7D
-%0A       
+ else
  if (!St
@@ -1684,32 +1684,27 @@
 keyGenerator
-ClassNam
+Typ
 e)) %7B%0A      
@@ -1719,25 +1719,11 @@
 sult
-.setKeyGenerator(
+ = 
 KeyG
@@ -1742,33 +1742,36 @@
 ory.newInstance(
-k
+getK
 eyGeneratorClass
@@ -1774,16 +1774,17 @@
 lassName
+(
 ));%0A    
@@ -1788,17 +1788,28 @@
        %7D
-%0A
+ else %7B%0A    
         
@@ -1818,36 +1818,81 @@
 sult
-.setKeyGeneratorColumnName(k
+ = KeyGeneratorFactory.newInstance(BuiltinKeyGeneratorType.SNOWFLAKE.getK
 eyGe
@@ -1899,25 +1899,26 @@
 neratorC
-olumn
+lass
 Name
+()
 );%0A     
@@ -1924,39 +1924,44 @@
     
-result.setLogicIndex(logicIndex
+%7D%0A        result.setProperties(props
 );%0A 

add new function