Commit 3d70b7d2 authored by terrymanu's avatar terrymanu
Browse files

for #2084, remove DeleteWhereExtractor & UpdateWhereExtractor

parent c4cf80b2
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -15,14 +15,13 @@
 * limitations under the License.
 */

package org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select;
package org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml;

import com.google.common.base.Optional;
import lombok.Setter;
import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.shardingsphere.core.parse.antlr.extractor.api.OptionalSQLSegmentExtractor;
import org.apache.shardingsphere.core.parse.antlr.extractor.api.PlaceholderIndexesAware;
import org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.PredicateExtractor;
import org.apache.shardingsphere.core.parse.antlr.extractor.util.ExtractorUtils;
import org.apache.shardingsphere.core.parse.antlr.extractor.util.RuleName;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.WhereSegment;
@@ -32,22 +31,23 @@ import java.util.Collection;
import java.util.Map;

/**
 * Abstract where extractor.
 * Where extractor.
 *
 * @author duhongjun
 * @author zhangliang
 */
@Setter
public abstract class AbstractWhereExtractor implements OptionalSQLSegmentExtractor, PlaceholderIndexesAware {
public final class WhereExtractor implements OptionalSQLSegmentExtractor, PlaceholderIndexesAware {
    
    private final PredicateExtractor predicateExtractor = new PredicateExtractor();
    
    private Map<ParserRuleContext, Integer> placeholderIndexes;
    
    @Override
    public final Optional<WhereSegment> extract(final ParserRuleContext ancestorNode) {
    public Optional<WhereSegment> extract(final ParserRuleContext ancestorNode) {
        WhereSegment result = new WhereSegment();
        result.setParameterCount(placeholderIndexes.size());
        Optional<ParserRuleContext> whereNode = extractWhere(ancestorNode);
        Optional<ParserRuleContext> whereNode = ExtractorUtils.findFirstChildNodeNoneRecursive(ancestorNode, RuleName.WHERE_CLAUSE);
        if (whereNode.isPresent()) {
            setPropertiesForRevert(result, placeholderIndexes, whereNode.get());
            Optional<OrConditionSegment> orConditionSegment = extractOrConditionSegment(placeholderIndexes, whereNode.get());
@@ -58,8 +58,6 @@ public abstract class AbstractWhereExtractor implements OptionalSQLSegmentExtrac
        return Optional.of(result);
    }
    
    protected abstract Optional<ParserRuleContext> extractWhere(ParserRuleContext ancestorNode);
    
    private void setPropertiesForRevert(final WhereSegment whereSegment, final Map<ParserRuleContext, Integer> placeholderIndexes, final ParserRuleContext whereNode) {
        whereSegment.setWhereStartIndex(whereNode.getStart().getStartIndex());
        whereSegment.setWhereStopIndex(whereNode.getStop().getStopIndex());
@@ -79,5 +77,4 @@ public abstract class AbstractWhereExtractor implements OptionalSQLSegmentExtrac
        Optional<ParserRuleContext> exprNode = ExtractorUtils.findFirstChildNode((ParserRuleContext) whereNode.getChild(1), RuleName.EXPR);
        return exprNode.isPresent() ? predicateExtractor.extract(placeholderIndexes, exprNode.get()) : Optional.<OrConditionSegment>absent();
    }
    
}
+0 −37
Original line number Diff line number Diff line
/*
 * 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.parse.antlr.extractor.impl.dml.delete;

import com.google.common.base.Optional;
import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select.AbstractWhereExtractor;
import org.apache.shardingsphere.core.parse.antlr.extractor.util.ExtractorUtils;
import org.apache.shardingsphere.core.parse.antlr.extractor.util.RuleName;

/**
 * Where extractor for delete.
 *
 * @author duhongjun
 */
public final class DeleteWhereExtractor extends AbstractWhereExtractor {
    
    @Override
    protected Optional<ParserRuleContext> extractWhere(final ParserRuleContext ancestorNode) {
        return ExtractorUtils.findFirstChildNodeNoneRecursive(ancestorNode, RuleName.WHERE_CLAUSE);
    }
}
+17 −3
Original line number Diff line number Diff line
@@ -18,19 +18,32 @@
package org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select;

import com.google.common.base.Optional;
import lombok.Setter;
import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.shardingsphere.core.parse.antlr.extractor.api.OptionalSQLSegmentExtractor;
import org.apache.shardingsphere.core.parse.antlr.extractor.api.PlaceholderIndexesAware;
import org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.WhereExtractor;
import org.apache.shardingsphere.core.parse.antlr.extractor.util.ExtractorUtils;
import org.apache.shardingsphere.core.parse.antlr.extractor.util.RuleName;
import org.apache.shardingsphere.core.parse.antlr.sql.segment.dml.WhereSegment;

import java.util.Map;

/**
 * Where extractor for select.
 *
 * @author duhongjun
 * @author zhangliang
 */
public final class SelectWhereExtractor extends AbstractWhereExtractor {
@Setter
public final class SelectWhereExtractor implements OptionalSQLSegmentExtractor, PlaceholderIndexesAware {
    
    private final WhereExtractor whereExtractor = new WhereExtractor();
    
    private Map<ParserRuleContext, Integer> placeholderIndexes;
    
    @Override
    protected Optional<ParserRuleContext> extractWhere(final ParserRuleContext ancestorNode) {
    public Optional<WhereSegment> extract(final ParserRuleContext ancestorNode) {
        Optional<ParserRuleContext> selectItemsNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.SELECT_ITEMS);
        if (!selectItemsNode.isPresent()) {
            return Optional.absent();
@@ -39,6 +52,7 @@ public final class SelectWhereExtractor extends AbstractWhereExtractor {
        if (!fromNode.isPresent()) {
            return Optional.absent();
        }
        return ExtractorUtils.findFirstChildNodeNoneRecursive(fromNode.get().getParent(), RuleName.WHERE_CLAUSE);
        whereExtractor.setPlaceholderIndexes(placeholderIndexes);
        return whereExtractor.extract(fromNode.get().getParent());
    }
}
+0 −37
Original line number Diff line number Diff line
/*
 * 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.parse.antlr.extractor.impl.dml.update;

import com.google.common.base.Optional;
import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select.AbstractWhereExtractor;
import org.apache.shardingsphere.core.parse.antlr.extractor.util.ExtractorUtils;
import org.apache.shardingsphere.core.parse.antlr.extractor.util.RuleName;

/**
 * Where extractor for update.
 *
 * @author duhongjun
 */
public final class UpdateWhereExtractor extends AbstractWhereExtractor {
    
    @Override
    protected Optional<ParserRuleContext> extractWhere(final ParserRuleContext ancestorNode) {
        return ExtractorUtils.findFirstChildNodeNoneRecursive(ancestorNode, RuleName.WHERE_CLAUSE);
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -31,10 +31,9 @@
    <extractor-rule id="setAssignments" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.SetAssignmentsExtractor" />
    <extractor-rule id="onDuplicateKeyColumns" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.insert.OnDuplicateKeyColumnsExtractor" />
    <extractor-rule id="tableReferences" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.TableReferencesExtractor" />
    <extractor-rule id="where" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.WhereExtractor" />
    <extractor-rule id="selectItems" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select.SelectItemsExtractor" />
    <extractor-rule id="selectWhere" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select.SelectWhereExtractor" />
    <extractor-rule id="updateSetWhere" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.update.UpdateWhereExtractor" />
    <extractor-rule id="deleteWhere" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.delete.DeleteWhereExtractor" />
    <extractor-rule id="groupBy" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select.GroupByExtractor" />
    <extractor-rule id="orderBy" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select.OrderByExtractor" />
    <extractor-rule id="limit" extractor-class="org.apache.shardingsphere.core.parse.antlr.extractor.impl.dml.select.LimitExtractor" />
Loading