diff --git a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java index 6e9331148aec5..c6f93979d2c00 100644 --- a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java +++ b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java @@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.Attachable; import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken; import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.Substitutable; -import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.generic.ComposableSQLToken; import java.util.Collections; import java.util.List; @@ -62,25 +61,12 @@ private boolean isContainsAttachableToken(final SQLToken sqlToken, final SQLToke } private void appendRewriteSQL(final SQLToken sqlToken, final StringBuilder builder) { - if (sqlToken instanceof ComposableSQLToken) { - builder.append(getComposableSQLTokenText((ComposableSQLToken) sqlToken)); - } else { - builder.append(getSQLTokenText(sqlToken)); - } + builder.append(getSQLTokenText(sqlToken)); builder.append(getConjunctionText(sqlToken)); } protected abstract String getSQLTokenText(SQLToken sqlToken); - private String getComposableSQLTokenText(final ComposableSQLToken composableSQLToken) { - StringBuilder result = new StringBuilder(); - for (SQLToken each : composableSQLToken.getSqlTokens()) { - result.append(getSQLTokenText(each)); - result.append(getConjunctionText(each)); - } - return result.toString(); - } - private String getConjunctionText(final SQLToken sqlToken) { int startIndex = getStartIndex(sqlToken); return sql.substring(startIndex, getStopIndex(sqlToken, startIndex)); diff --git a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/ComposableSQLToken.java b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/ComposableSQLToken.java deleted file mode 100644 index ce76e05f2b987..0000000000000 --- a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/ComposableSQLToken.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.infra.rewrite.sql.token.common.pojo.generic; - -import lombok.Getter; -import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken; -import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.Substitutable; - -import java.util.Collection; -import java.util.LinkedList; - -/** - * Composable SQL token. - */ -@Getter -public final class ComposableSQLToken extends SQLToken implements Substitutable { - - private final Collection sqlTokens = new LinkedList<>(); - - private final int stopIndex; - - public ComposableSQLToken(final int startIndex, final int stopIndex) { - super(startIndex); - this.stopIndex = stopIndex; - } - - /** - * Add SQL token. - * - * @param sqlToken SQL token - */ - public void addSQLToken(final SQLToken sqlToken) { - sqlTokens.add(sqlToken); - } -} diff --git a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/OwnerToken.java b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/OwnerToken.java deleted file mode 100644 index 6d0c4e5fa2b19..0000000000000 --- a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/OwnerToken.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.infra.rewrite.sql.token.common.pojo.generic; - -import com.google.common.base.Strings; -import lombok.Getter; -import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.RouteUnitAware; -import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken; -import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.Substitutable; -import org.apache.shardingsphere.infra.route.context.RouteUnit; -import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; - -import java.util.Set; - -/** - * Owner token. - */ -public final class OwnerToken extends SQLToken implements Substitutable, RouteUnitAware { - - @Getter - private final int stopIndex; - - private final IdentifierValue ownerName; - - private final IdentifierValue tableName; - - public OwnerToken(final int startIndex, final int stopIndex, final IdentifierValue ownerName, final IdentifierValue tableName) { - super(startIndex); - this.stopIndex = stopIndex; - this.ownerName = ownerName; - this.tableName = tableName; - } - - @Override - public String toString(final RouteUnit routeUnit) { - if (null != ownerName && !Strings.isNullOrEmpty(ownerName.getValue()) && tableName.getValue().equals(ownerName.getValue())) { - Set actualTableNames = routeUnit.getActualTableNames(tableName.getValue()); - String actualTableName = actualTableNames.isEmpty() ? tableName.getValue().toLowerCase() : actualTableNames.iterator().next(); - return tableName.getQuoteCharacter().wrap(actualTableName) + "."; - } - return toString(); - } - - @Override - public String toString() { - return null == ownerName || Strings.isNullOrEmpty(ownerName.getValue()) ? "" : ownerName.getValueWithQuoteCharacters() + "."; - } -} diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/ComposableSQLTokenTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/ComposableSQLTokenTest.java deleted file mode 100644 index 28ac752e43425..0000000000000 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/ComposableSQLTokenTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.infra.rewrite.sql.token.common.pojo.generic; - -import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class ComposableSQLTokenTest { - - @Test - void assertComposableSQLToken() { - ComposableSQLToken composableSQLToken = new ComposableSQLToken(0, 1); - SQLToken sqlToken = mock(SQLToken.class); - when(sqlToken.getStartIndex()).thenReturn(2); - when(sqlToken.compareTo(any(SQLToken.class))).thenReturn(0); - composableSQLToken.addSQLToken(sqlToken); - assertThat(composableSQLToken.getStartIndex(), is(0)); - assertThat(composableSQLToken.getStopIndex(), is(1)); - assertThat(composableSQLToken.getSqlTokens().size(), is(1)); - assertThat(composableSQLToken.getSqlTokens().iterator().next().compareTo(sqlToken), is(0)); - } -} diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/OwnerTokenTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/OwnerTokenTest.java deleted file mode 100644 index fb85fc11cafeb..0000000000000 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/pojo/generic/OwnerTokenTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.infra.rewrite.sql.token.common.pojo.generic; - -import org.apache.shardingsphere.infra.route.context.RouteMapper; -import org.apache.shardingsphere.infra.route.context.RouteUnit; -import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; -import org.junit.jupiter.api.Test; - -import java.util.Collections; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -class OwnerTokenTest { - - @Test - void assertOwnerTokenWithOwnerNameEqualsTableName() { - OwnerToken ownerToken = new OwnerToken(0, 1, new IdentifierValue("t_user"), new IdentifierValue("t_user")); - assertThat(ownerToken.toString(buildRouteUnit()), is("t_user_0.")); - assertTokenGrid(ownerToken); - } - - @Test - void assertOwnerTokenWithOwnerNameNotEqualsTableName() { - OwnerToken ownerToken = new OwnerToken(0, 1, new IdentifierValue("u"), new IdentifierValue("t_user")); - assertThat(ownerToken.toString(buildRouteUnit()), is("u.")); - assertTokenGrid(ownerToken); - } - - @Test - void assertOwnerTokenWithNoRouteUnitAndOwnerNameEqualsTableName() { - OwnerToken ownerToken = new OwnerToken(0, 1, new IdentifierValue("t_user_detail"), new IdentifierValue("t_user_detail")); - assertThat(ownerToken.toString(), is("t_user_detail.")); - assertTokenGrid(ownerToken); - } - - @Test - void assertOwnerTokenWithNoRouteUnitAndOwnerNameNotEqualsTableName() { - OwnerToken ownerToken = new OwnerToken(0, 1, new IdentifierValue("ud"), new IdentifierValue("t_user_detail")); - assertThat(ownerToken.toString(), is("ud.")); - assertTokenGrid(ownerToken); - } - - @Test - void assertOwnerTokenWithNoRouteUnitAndOwnerNameValueIsEmpty() { - OwnerToken ownerToken = new OwnerToken(0, 1, new IdentifierValue(""), new IdentifierValue("t_user_detail")); - assertThat(ownerToken.toString(), is("")); - assertTokenGrid(ownerToken); - } - - @Test - void assertOwnerTokenWithNoRouteUnitAndOwnerNameIsEmpty() { - OwnerToken ownerToken = new OwnerToken(0, 1, null, new IdentifierValue("t_user_detail")); - assertThat(ownerToken.toString(), is("")); - assertTokenGrid(ownerToken); - } - - private void assertTokenGrid(final OwnerToken ownerToken) { - assertThat(ownerToken.getStartIndex(), is(0)); - assertThat(ownerToken.getStopIndex(), is(1)); - } - - private RouteUnit buildRouteUnit() { - return new RouteUnit(new RouteMapper("logic_db", "logic_db"), Collections.singletonList(new RouteMapper("t_user", "t_user_0"))); - } -}