未验证 提交 c6b2fd99 编写于 作者: L Liang Zhang 提交者: GitHub

Merge pull request #2968 from nancyzrh/dev

for where predicate assertion
......@@ -22,6 +22,7 @@ import org.apache.shardingsphere.core.parse.integrate.asserts.groupby.GroupByAss
import org.apache.shardingsphere.core.parse.integrate.asserts.index.IndexAssert;
import org.apache.shardingsphere.core.parse.integrate.asserts.orderby.OrderByAssert;
import org.apache.shardingsphere.core.parse.integrate.asserts.pagination.PaginationAssert;
import org.apache.shardingsphere.core.parse.integrate.asserts.predicate.PredicateAssert;
import org.apache.shardingsphere.core.parse.integrate.asserts.selectitem.SelectItemAssert;
import org.apache.shardingsphere.core.parse.integrate.asserts.table.AlterTableAssert;
import org.apache.shardingsphere.core.parse.integrate.asserts.table.TableAssert;
......@@ -31,6 +32,7 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemsSegm
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.GroupBySegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.order.OrderBySegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.LimitSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.WhereSegment;
import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
import org.apache.shardingsphere.core.parse.sql.statement.ddl.AlterTableStatement;
......@@ -67,6 +69,8 @@ public final class ShardingSQLStatementAssert {
private final AlterTableAssert alterTableAssert;
private final SelectItemAssert selectItemAssert;
private final PredicateAssert predicateAssert;
public ShardingSQLStatementAssert(final SQLStatement actual, final String sqlCaseId, final SQLCaseType sqlCaseType) {
SQLStatementAssertMessage assertMessage = new SQLStatementAssertMessage(
......@@ -80,6 +84,7 @@ public final class ShardingSQLStatementAssert {
paginationAssert = new PaginationAssert(sqlCaseType, assertMessage);
alterTableAssert = new AlterTableAssert(assertMessage);
selectItemAssert = new SelectItemAssert(sqlCaseType, assertMessage);
predicateAssert = new PredicateAssert(sqlCaseType, assertMessage);
}
/**
......@@ -100,7 +105,6 @@ public final class ShardingSQLStatementAssert {
}
private void assertSelectStatement(final SelectStatement actual) {
// TODO do select items assert
Optional<SelectItemsSegment> selectItemsSegment = actual.findSQLSegment(SelectItemsSegment.class);
if (selectItemsSegment.isPresent()) {
selectItemAssert.assertSelectItems(selectItemsSegment.get(), expected.getSelectItems());
......@@ -118,6 +122,10 @@ public final class ShardingSQLStatementAssert {
paginationAssert.assertOffset(limitSegment.get().getOffset().orNull(), expected.getOffset());
paginationAssert.assertRowCount(limitSegment.get().getRowCount().orNull(), expected.getRowCount());
}
Optional<WhereSegment> whereSegment = actual.findSQLSegment(WhereSegment.class);
if (whereSegment.isPresent() && null != expected.getWhereSegment()) {
predicateAssert.assertPredicate(whereSegment.get(),expected.getWhereSegment());
}
}
private void assertAlterTableStatement(final AlterTableStatement actual) {
......
/*
* 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.integrate.asserts.predicate;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.parse.integrate.asserts.SQLStatementAssertMessage;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.ExpectedExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedCommonExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedSubquerySegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.simple.ExpectedLiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.simple.ExpectedParamMarkerExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.ExpectedAndPredicate;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.ExpectedColumnSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.ExpectedPredicateSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.ExpectedWhereSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.value.ExpectedPredicateCompareRightValue;
import org.apache.shardingsphere.core.parse.sql.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.complex.CommonExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.complex.ComplexExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.complex.SubquerySegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.AndPredicate;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.WhereSegment;
import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.value.PredicateCompareRightValue;
import org.apache.shardingsphere.test.sql.SQLCaseType;
import java.util.Collection;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* where predicate assert.
*
* @author zhaoyanan
*/
@RequiredArgsConstructor
public final class PredicateAssert {
private final SQLCaseType sqlCaseType;
private final SQLStatementAssertMessage assertMessage;
/**
* assert predicate
* @param actual actual where segment
* @param expected expected where segment
*/
public void assertPredicate(final WhereSegment actual, final ExpectedWhereSegment expected) {
if (SQLCaseType.Placeholder == sqlCaseType) {
assertThat(assertMessage.getFullAssertMessage("parameters count assertion error:"), actual.getParametersCount(), is(expected.getParametersCount()));
}
assertAndPredicate(actual.getAndPredicates(),expected.getAndPredicates());
}
/**
* assert and predicate
* @param actual actual and predicate
* @param expected expected and predicate
*/
private void assertAndPredicate(final Collection<AndPredicate> actual, final List<ExpectedAndPredicate> expected) {
assertThat(assertMessage.getFullAssertMessage("and predicate size error: "), actual.size(), is(expected.size()));
int count = 0;
for (AndPredicate each: actual) {
assertThat(assertMessage.getFullAssertMessage("predicate segment size error: "), each.getPredicates().size(), is(expected.get(count).getPredicates().size()));
assertPredicateSegment(each.getPredicates(),expected.get(count).getPredicates());
count++;
}
}
/**
* assert predicate segment
* @param actual actual predicate segment
* @param expected expected predicate segment
*/
private void assertPredicateSegment(final Collection<PredicateSegment> actual, final List<ExpectedPredicateSegment> expected) {
int count = 0;
for (PredicateSegment each: actual) {
assertColumnSegment(each.getColumn(),expected.get(count).getColumn());
if (each.getRightValue() instanceof PredicateCompareRightValue) {
assertCompareRightValue((PredicateCompareRightValue) each.getRightValue(), expected.get(count).findExpectedRightValue(ExpectedPredicateCompareRightValue.class));
}
//TODO add expr assertion
count++;
}
}
/**
* assert column segment
* @param actual actual column segment
* @param expected expected column segment
*/
private void assertColumnSegment(final ColumnSegment actual, final ExpectedColumnSegment expected) {
assertThat(assertMessage.getFullAssertMessage("column segment name assertion error: "), actual.getName(), is(expected.getName()));
assertThat(assertMessage.getFullAssertMessage("column segment table name assertion error: "), actual.getOwner().isPresent() ? actual.getOwner().get().getTableName() : null, is(expected.getOwner().getName()));
}
/**
* assert expr and operation
* @param actual
* @param expected
*/
private void assertCompareRightValue(final PredicateCompareRightValue actual, final ExpectedPredicateCompareRightValue expected) {
assertThat(assertMessage.getFullAssertMessage("right value operator assertion error: "),actual.getOperator(),is(expected.getOperator()));
if (actual.getExpression() instanceof ParameterMarkerExpressionSegment) {
assertThat(assertMessage.getFullAssertMessage("parameter marker expression parameterMarkerindex assertion error"),((ParameterMarkerExpressionSegment) actual.getExpression()).getParameterMarkerIndex(),is(expected.findExpectedExpression(ExpectedParamMarkerExpressionSegment.class).getParameterMarkerIndex()));
}
if (actual.getExpression() instanceof CommonExpressionSegment) {
assertThat(assertMessage.getFullAssertMessage("common expression text assertion error: "),((ComplexExpressionSegment) actual.getExpression()).getText(),is(expected.findExpectedExpression(ExpectedCommonExpressionSegment.class).getText()));
}
if (actual.getExpression() instanceof SubquerySegment) {
assertThat(assertMessage.getFullAssertMessage("subquery segment text assertion error: "),((ComplexExpressionSegment) actual.getExpression()).getText(),is(expected.findExpectedExpression(ExpectedSubquerySegment.class).getText()));
}
if (actual.getExpression() instanceof LiteralExpressionSegment) {
assertThat(assertMessage.getFullAssertMessage("literal assertion error:"),((LiteralExpressionSegment) actual.getExpression()).getLiterals().toString(),is(expected.findExpectedExpression(ExpectedLiteralExpressionSegment.class).getLiterals().toString()));
}
}
}
/*
* 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.integrate.jaxb.expr;
public interface ExpectedExpressionSegment {
}
/*
* 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.integrate.jaxb.expr.complex;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class ExpectedBaseComplexExpression implements ExpectedComplexExpressionSegment {
@XmlAttribute(name = "start-index")
private Integer startIndex;
@XmlAttribute(name = "stop-index")
private Integer stopIndex;
@XmlAttribute
private String text;
}
/*
* 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.integrate.jaxb.expr.complex;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedCommonExpressionSegment extends ExpectedBaseComplexExpression {
}
/*
* 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.integrate.jaxb.expr.complex;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.ExpectedExpressionSegment;
public interface ExpectedComplexExpressionSegment extends ExpectedExpressionSegment {
/**
* Get text.
*
* @return text
*/
String getText();
}
/*
* 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.integrate.jaxb.expr.complex;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedSubquerySegment extends ExpectedBaseComplexExpression {
}
/*
* 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.integrate.jaxb.expr.simple;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class ExpectedBaseSimpleExpression implements ExpectedSimpleExpressionSegment {
@XmlAttribute(name = "start-index")
private int startIndex;
@XmlAttribute(name = "stop-index")
private int stopIndex;
}
/*
* 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.integrate.jaxb.expr.simple;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedLiteralExpressionSegment extends ExpectedBaseSimpleExpression {
@XmlAttribute
private Integer literals;
}
/*
* 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.integrate.jaxb.expr.simple;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedParamMarkerExpressionSegment extends ExpectedBaseSimpleExpression {
@XmlAttribute
private Integer parameterMarkerIndex;
}
/*
* 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.integrate.jaxb.expr.simple;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.ExpectedExpressionSegment;
public interface ExpectedSimpleExpressionSegment extends ExpectedExpressionSegment {
}
/*
* 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.integrate.jaxb.predicate;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import java.util.LinkedList;
import java.util.List;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedAndPredicate {
@XmlElementWrapper(name = "predicate-segments")
@XmlElement(name = "predicate-segment")
private List<ExpectedPredicateSegment> predicates = new LinkedList<>();
}
/*
* 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.integrate.jaxb.predicate;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class ExpectedBaseSegment {
@XmlAttribute(name = "start-index")
private Integer startIndex;
@XmlAttribute(name = "stop-index")
private Integer stopIndex;
}
/*
* 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.integrate.jaxb.predicate;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.core.parse.core.constant.QuoteCharacter;
import org.apache.shardingsphere.core.parse.integrate.jaxb.selectitem.ExpectedTableSegment;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedColumnSegment extends ExpectedBaseSegment {
@XmlAttribute
private String name;
@XmlAttribute
private QuoteCharacter quoteCharacter = QuoteCharacter.NONE;
@XmlElement(name = "table-segment")
private ExpectedTableSegment owner = new ExpectedTableSegment();
}
/*
* 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.integrate.jaxb.predicate;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.value.ExpectedPredicateBetweenRightValue;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.value.ExpectedPredicateCompareRightValue;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.value.ExpectedPredicateInRightValue;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.value.ExpectedPredicateRightValue;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedPredicateSegment extends ExpectedBaseSegment {
@XmlElement(name = "column-segment")
private ExpectedColumnSegment column = new ExpectedColumnSegment();
@XmlElement(name = "predicate-between-right-value")
private ExpectedPredicateBetweenRightValue betweenRightValue = new ExpectedPredicateBetweenRightValue();
@XmlElement(name = "predicate-in-right-value")
private ExpectedPredicateInRightValue inRightValue = new ExpectedPredicateInRightValue();
@XmlElement(name = "predicate-compare-right-value")
private ExpectedPredicateCompareRightValue compareRightValue = new ExpectedPredicateCompareRightValue();
/**
* find expected right value type
* @param expectedPredicateRightValue
* @return right value
*/
public <T extends ExpectedPredicateRightValue> T findExpectedRightValue(final Class<T> expectedPredicateRightValue) {
if (expectedPredicateRightValue.isAssignableFrom(ExpectedPredicateCompareRightValue.class)) {
return (T) compareRightValue;
}
if (expectedPredicateRightValue.isAssignableFrom(ExpectedPredicateInRightValue.class)) {
return (T) inRightValue;
}
if (expectedPredicateRightValue.isAssignableFrom(ExpectedPredicateBetweenRightValue.class)) {
return (T) betweenRightValue;
}
return null;
}
}
/*
* 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.integrate.jaxb.predicate;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.*;
import java.util.LinkedList;
import java.util.List;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedWhereSegment extends ExpectedBaseSegment {
@XmlAttribute
private Integer parametersCount;
@XmlElementWrapper(name = "and-predicates")
@XmlElement(name = "and-predicate")
private List<ExpectedAndPredicate> andPredicates = new LinkedList<>();
@XmlAttribute
private Integer parameterStartIndex;
}
/*
* 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.integrate.jaxb.predicate.value;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedCommonExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedSubquerySegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.simple.ExpectedLiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.simple.ExpectedParamMarkerExpressionSegment;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedPredicateBetweenRightValue implements ExpectedPredicateRightValue {
@XmlElement(name = "between-common-expression")
private ExpectedCommonExpressionSegment betweenCommonExpressionSegment;
@XmlElement(name = "between-subquery-segment")
private ExpectedSubquerySegment betweenSubquerySegment;
@XmlElement(name = "between-literal-expression")
private ExpectedLiteralExpressionSegment betweenLiteralExpression;
@XmlElement(name = "between-param-marker-expression")
private ExpectedParamMarkerExpressionSegment betweenParamMarkerExpression;
@XmlElement(name = "and-subquery-segment")
private ExpectedSubquerySegment andSubquerySegment;
@XmlElement(name = "and-common-expression")
private ExpectedCommonExpressionSegment andCommonExpressionSegment;
@XmlElement(name = "and-literal-expression")
private ExpectedLiteralExpressionSegment andLiteralExpression;
@XmlElement(name = "and-param-marker-expression")
private ExpectedParamMarkerExpressionSegment andParamMarkerExpression;
}
/*
* 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.integrate.jaxb.predicate.value;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.ExpectedExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedCommonExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedComplexExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedSubquerySegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.simple.ExpectedLiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.simple.ExpectedParamMarkerExpressionSegment;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedPredicateCompareRightValue implements ExpectedPredicateRightValue {
@XmlAttribute
private String operator;
@XmlElement(name = "common-expression")
private ExpectedCommonExpressionSegment commonExpressionSegment;
@XmlElement(name = "subquery-segment")
private ExpectedSubquerySegment subquerySegment;
@XmlElement(name = "literal-expression")
private ExpectedLiteralExpressionSegment literalExpression;
@XmlElement(name = "param-marker-expression")
private ExpectedParamMarkerExpressionSegment paramMarkerExpression;
/**
* find expected expression
* @param expectedExpressionSegment
* @return expression segment
*/
public <T extends ExpectedExpressionSegment> T findExpectedExpression(final Class<T> expectedExpressionSegment) {
if (expectedExpressionSegment.isAssignableFrom(ExpectedParamMarkerExpressionSegment.class)) {
return (T) paramMarkerExpression;
}
if (expectedExpressionSegment.isAssignableFrom(ExpectedLiteralExpressionSegment.class)) {
return (T) literalExpression;
}
if (expectedExpressionSegment.isAssignableFrom(ExpectedCommonExpressionSegment.class)) {
return (T) commonExpressionSegment;
}
if (expectedExpressionSegment.isAssignableFrom(ExpectedComplexExpressionSegment.class)) {
return (T) subquerySegment;
}
return null;
}
}
/*
* 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.integrate.jaxb.predicate.value;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedCommonExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.complex.ExpectedSubquerySegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.simple.ExpectedLiteralExpressionSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.expr.simple.ExpectedParamMarkerExpressionSegment;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import java.util.Collection;
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class ExpectedPredicateInRightValue implements ExpectedPredicateRightValue {
@XmlElementWrapper(name = "common-expressions")
@XmlElement(name = "common-expression")
private Collection<ExpectedCommonExpressionSegment> commonExpressionSegments;
@XmlElementWrapper(name = "subquery-segments")
@XmlElement(name = "subquery-segment")
private Collection<ExpectedSubquerySegment> subquerySegments;
@XmlElementWrapper(name = "literal-expressions")
@XmlElement(name = "literal-expression")
private Collection<ExpectedLiteralExpressionSegment> literalExpressionSegments;
@XmlElementWrapper(name = "param-marker-expressions")
@XmlElement(name = "param-marker-expression")
private Collection<ExpectedParamMarkerExpressionSegment> paramMarkerExpressionSegments;
}
/*
* 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.integrate.jaxb.predicate.value;
public interface ExpectedPredicateRightValue {
}
......@@ -24,6 +24,7 @@ import org.apache.shardingsphere.core.parse.integrate.jaxb.groupby.ExpectedGroup
import org.apache.shardingsphere.core.parse.integrate.jaxb.insert.ExpectedInsertColumnsAndValues;
import org.apache.shardingsphere.core.parse.integrate.jaxb.orderby.ExpectedOrderByColumn;
import org.apache.shardingsphere.core.parse.integrate.jaxb.pagination.ExpectedPaginationValue;
import org.apache.shardingsphere.core.parse.integrate.jaxb.predicate.ExpectedWhereSegment;
import org.apache.shardingsphere.core.parse.integrate.jaxb.selectitem.ExpectedSelectItems;
import org.apache.shardingsphere.core.parse.integrate.jaxb.table.ExpectedAlterTable;
import org.apache.shardingsphere.core.parse.integrate.jaxb.table.ExpectedTable;
......@@ -88,6 +89,9 @@ public final class ParserResult {
@XmlElement(name = "select-items")
private ExpectedSelectItems selectItems = new ExpectedSelectItems();
@XmlElement(name = "where-segment")
private ExpectedWhereSegment whereSegment;
/**
* Get parameters.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册