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

import com.google.common.base.Strings;
import lombok.Getter;
import org.apache.shardingsphere.core.parse.antlr.constant.QuoteCharacter;
import org.apache.shardingsphere.core.parse.util.SQLUtil;
import org.apache.shardingsphere.core.route.type.RoutingUnit;

import java.util.Map;

/**
 * Index placeholder for rewrite.
 *
 * @author zhangliang
 * @author panjuan
 */
@Getter
public final class IndexPlaceholder implements ShardingPlaceholder, Alterable {
    
    private final String logicIndexName;
    
    private final String logicTableName;
    
    private final QuoteCharacter quoteCharacter;
    
    public IndexPlaceholder(final String logicIndexLiteral, final String logicTableName) {
        logicIndexName = SQLUtil.getExactlyValue(logicIndexLiteral);
        this.logicTableName = logicTableName;
        quoteCharacter = QuoteCharacter.getQuoteCharacter(logicIndexLiteral);
    }
    
    @Override
    public String toString(final RoutingUnit routingUnit, final Map<String, String> logicAndActualTables) {
        StringBuilder result = new StringBuilder();
        result.append(quoteCharacter.getStartDelimiter()).append(logicIndexName);
        String actualTableName = logicAndActualTables.get(logicTableName);
        if (!Strings.isNullOrEmpty(actualTableName)) {
            result.append("_").append(actualTableName);
        }
        result.append(quoteCharacter.getEndDelimiter());
        return result.toString();
    }
}

@@ -914,24 +914,63 @@
 bok.Getter;%0A
+import lombok.RequiredArgsConstructor;%0A
 import org.a
@@ -1036,66 +1036,8 @@
 er;%0A
-import org.apache.shardingsphere.core.parse.util.SQLUtil;%0A
 impo
@@ -1204,16 +1204,41 @@
 uan%0A */%0A
+@RequiredArgsConstructor%0A
 @Getter%0A
@@ -1406,32 +1406,32 @@
 TableName;%0A    %0A
+
     private fina
@@ -1472,303 +1472,8 @@
    %0A
-    public IndexPlaceholder(final String logicIndexLiteral, final String logicTableName) %7B%0A        logicIndexName = SQLUtil.getExactlyValue(logicIndexLiteral);%0A        this.logicTableName = logicTableName;%0A        quoteCharacter = QuoteCharacter.getQuoteCharacter(logicIndexLiteral);%0A    %7D%0A    %0A
     

USE RequiredArgsConstructor