/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.shardingsphere.core.rule;

import lombok.Getter;
import org.apache.shardingsphere.api.config.encrypt.EncryptRuleConfiguration;
import org.apache.shardingsphere.core.strategy.encrypt.EncryptEngine;

import java.util.Collection;

/**
 * Encrypt rule.
 *
 * @author panjuan
 */
@Getter
public final class EncryptRule implements BaseRule {
    
    private final EncryptEngine encryptEngine;
    
    private EncryptRuleConfiguration encryptRuleConfig;
    
    public EncryptRule() {
        encryptEngine = new EncryptEngine();
    }
    
    public EncryptRule(final EncryptRuleConfiguration encryptRuleConfiguration) {
        this.encryptRuleConfig = encryptRuleConfiguration;
        encryptEngine = new EncryptEngine(encryptRuleConfiguration);
    }

    /**
     * Get encrypt table names.
     * 
     * @return encrypt table names
     */
    public Collection<String> getEncryptTableNames() {
        return encryptEngine.getEncryptTableNames();
    }
}

@@ -853,82 +853,333 @@
 ort 
-lombok.Getter;%0Aimport org.apache.shardingsphere.api.config.encrypt.Encrypt
+com.google.common.base.Preconditions;%0Aimport com.google.common.base.Strings;%0Aimport lombok.Getter;%0Aimport org.apache.shardingsphere.api.config.encrypt.EncryptColumnRuleConfiguration;%0Aimport org.apache.shardingsphere.api.config.encrypt.EncryptRuleConfiguration;%0Aimport org.apache.shardingsphere.api.config.encrypt.EncryptTable
 Rule
@@ -1588,24 +1588,84 @@
 ptEngine();%0A
+        encryptRuleConfig = new EncryptRuleConfiguration();%0A
     %7D%0A    %0A 
@@ -1816,75 +1816,1097 @@
     
-encryptEngine = new EncryptEngine(encryptRuleConfiguration);%0A    %7D%0A
+Preconditions.checkArgument(isValidEncryptRuleConfig(), %22Invalid encrypt column configurations in EncryptTableRuleConfigurations.%22);%0A        encryptEngine = new EncryptEngine(encryptRuleConfiguration);%0A    %7D%0A    %0A    private boolean isValidEncryptRuleConfig() %7B%0A        return (encryptRuleConfig.getEncryptors().isEmpty() && encryptRuleConfig.getTables().isEmpty()) %7C%7C isValidEncryptTableConfig();%0A    %7D%0A    %0A    private boolean isValidEncryptTableConfig() %7B%0A        for (EncryptTableRuleConfiguration table : encryptRuleConfig.getTables().values()) %7B%0A            for (EncryptColumnRuleConfiguration column : table.getColumns().values()) %7B%0A                if (!isValidColumnConfig(column)) %7B%0A                    return false;%0A                %7D%0A            %7D%0A        %7D%0A        return true;%0A    %7D%0A    %0A    private boolean isValidColumnConfig(final EncryptColumnRuleConfiguration column) %7B%0A        return !Strings.isNullOrEmpty(column.getEncryptor()) && !Strings.isNullOrEmpty(column.getCipherColumn()) && encryptRuleConfig.getEncryptors().keySet().contains(column.getEncryptor());%0A    %7D%0A    
 %0A   

add isValidEncryptRuleConfig()