Skip to content

Commit

Permalink
Merge pull request #352 from guangyun1013/1.5.3-SNAPSHOT
Browse files Browse the repository at this point in the history
Add SQLToken test
  • Loading branch information
haocao authored Sep 4, 2017
2 parents b8c3bf8 + 1ae817f commit ddc8c4e
Show file tree
Hide file tree
Showing 35 changed files with 867 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ private void setParameters(final PreparedStatement preparedStatement, final List
for (String each : parameters) {
if (each.contains("'")) {
preparedStatement.setString(index++, each.replace("'", ""));
} else if ("null".equalsIgnoreCase(each)) {
preparedStatement.setObject(index++, null);
} else {
preparedStatement.setInt(index++, Integer.valueOf(each));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand All @@ -55,7 +56,10 @@ public NullableShardingTableOnlyTest(final String testCaseName, final String sql

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> dataParameters() {
return SQLAssertJAXBHelper.getDataParameters("integrate/assert/select_aggregate.xml");
List<Object[]> result = new LinkedList<>();
result.addAll(SQLAssertJAXBHelper.getDataParameters("integrate/assert/select_aggregate.xml"));
result.addAll(SQLAssertJAXBHelper.getDataParameters("integrate/assert/select_nullable.xml"));
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected final void assertPreparedStatement(final SQLStatement actual) {
private void assertSQLStatement(final SQLStatement actual, final boolean isPreparedStatement) {
ParserAssertHelper.assertTables(expected.getTables(), actual.getTables());
ParserAssertHelper.assertConditions(expected.getConditions(), actual.getConditions(), isPreparedStatement);
ParserAssertHelper.assertSqlTokens(expected.getTableTokens(), actual.getSqlTokens());
ParserAssertHelper.assertSqlTokens(expected.getSqlTokens(), actual.getSqlTokens(), isPreparedStatement);
if (actual instanceof SelectStatement) {
SelectStatement selectStatement = (SelectStatement) actual;
SelectStatement expectedSqlStatement = ParserJAXBHelper.getSelectStatement(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

import java.util.ArrayList;
import java.util.List;

@Getter
Expand All @@ -47,7 +49,25 @@ public final class Assert {
@XmlElementWrapper(name = "table-tokens")
@XmlElement(name = "table-token")
private List<TableToken> tableTokens;


@XmlElement(name = "items-token")
private ItemsToken itemsToken;

@XmlElement(name = "generated-key-token")
private GeneratedKeyToken generatedKeyToken;

@XmlElement(name = "multiple-insert-values-token")
private MultipleInsertValuesToken multipleInsertValuesToken;

@XmlElement(name = "order-by-token")
private OrderByToken orderByToken;

@XmlElement(name = "offset-token")
private OffsetToken offsetToken;

@XmlElement(name = "row-count-token")
private RowCountToken rowCountToken;

@XmlElementWrapper(name = "order-by-columns")
@XmlElement(name = "order-by-column")
private List<OrderByColumn> orderByColumns;
Expand All @@ -62,4 +82,30 @@ public final class Assert {

@XmlElement
private Limit limit;

public List<SQLToken> getSqlTokens() {
List<SQLToken> result = new ArrayList<SQLToken>(7);
if (tableTokens != null) {
result.addAll(tableTokens);
}
if (offsetToken != null) {
result.add(offsetToken);
}
if (rowCountToken != null) {
result.add(rowCountToken);
}
if (itemsToken != null) {
result.add(itemsToken);
}
if (generatedKeyToken != null) {
result.add(generatedKeyToken);
}
if (multipleInsertValuesToken != null) {
result.add(multipleInsertValuesToken);
}
if (orderByToken != null) {
result.add(orderByToken);
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.parsing.parser.jaxb;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class GeneratedKeyToken extends SQLToken {

@XmlAttribute(name = "begin-position-of-statement")
private int beginPositionOfStatement;

@XmlAttribute(name = "begin-position-of-prepared-statement")
private int beginPositionOfPreparedStatement;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.parsing.parser.jaxb;

import lombok.Getter;
import lombok.Setter;

import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class ItemsToken extends SQLToken {

@XmlElementWrapper(name = "items")
@XmlElement(name = "item")
private List<String> items = new LinkedList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.parsing.parser.jaxb;

import lombok.Getter;
import lombok.Setter;

import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class MultipleInsertValuesToken extends SQLToken {

@XmlElementWrapper(name = "values")
@XmlElement(name = "value")
private List<String> values = new LinkedList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.parsing.parser.jaxb;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class OffsetToken extends SQLToken {

@XmlAttribute(name = "offset")
private int offset;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.parsing.parser.jaxb;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public final class OrderByToken extends SQLToken {

@XmlAttribute(name = "begin-position-of-statement")
private int beginPositionOfStatement;

@XmlAttribute(name = "begin-position-of-prepared-statement")
private int beginPositionOfPreparedStatement;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.parsing.parser.jaxb;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class RowCountToken extends SQLToken {

@XmlAttribute(name = "row-count")
private int rowCount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.parsing.parser.jaxb;

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 SQLToken {

@XmlAttribute(name = "begin-position")
private int beginPosition;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.parsing.parser.jaxb;

import lombok.Getter;
Expand All @@ -10,10 +27,7 @@
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
public class TableToken {

@XmlAttribute(name = "begin-position")
private int beginPosition;
public class TableToken extends SQLToken {

@XmlAttribute(name = "original-literals")
private String originalLiterals;
Expand Down
Loading

0 comments on commit ddc8c4e

Please sign in to comment.