Skip to content

Commit

Permalink
Remove IdentifierValue.getQuotedContent() (#33757)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Nov 21, 2024
1 parent 4633f9d commit ed92560
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.shardingsphere.sql.parser.statement.core.value.identifier;

import com.google.common.base.Strings;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -55,14 +54,4 @@ public IdentifierValue(final String text, final String reservedCharacters) {
public String getValueWithQuoteCharacters() {
return null == value ? "" : quoteCharacter.wrap(value);
}

/**
* Get quoted content.
*
* @param text text
* @return quote content
*/
public static String getQuotedContent(final String text) {
return Strings.isNullOrEmpty(text) ? text : QuoteCharacter.unwrapAndTrimText(text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;

class IdentifierValueTest {

Expand Down Expand Up @@ -65,15 +64,4 @@ void assertGetValueWithQuoteCharactersWithValue() {
String text = "[foo]";
assertThat(new IdentifierValue(text).getValueWithQuoteCharacters(), is("[foo]"));
}

@Test
void assertGetQuotedContentWithNullValue() {
assertNull(IdentifierValue.getQuotedContent(null));
}

@Test
void assertGetQuotedContent() {
assertThat(IdentifierValue.getQuotedContent(" foo "), is("foo"));
assertThat(IdentifierValue.getQuotedContent("`foo`"), is("foo"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.simple.PostgreSQLComQueryPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLParameterStatusPacket;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
Expand All @@ -47,7 +48,6 @@
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.CommitStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.RollbackStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;

import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -114,7 +114,7 @@ private Collection<DatabasePacket> createParameterStatusResponse(final SetStatem
Collection<DatabasePacket> result = new ArrayList<>(2);
result.add(new PostgreSQLCommandCompletePacket("SET", 0L));
for (VariableAssignSegment each : sqlStatement.getVariableAssigns()) {
result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), IdentifierValue.getQuotedContent(each.getAssignValue())));
result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), null == each.getAssignValue() ? null : QuoteCharacter.unwrapText(each.getAssignValue())));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLIdentifierPacket;
import org.apache.shardingsphere.infra.binder.context.aware.ParameterAware;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
Expand All @@ -53,7 +54,6 @@
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.EmptyStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;

import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -162,7 +162,7 @@ private List<PostgreSQLPacket> createParameterStatusResponse(final SetStatement
List<PostgreSQLPacket> result = new ArrayList<>(2);
result.add(new PostgreSQLCommandCompletePacket("SET", 0L));
for (VariableAssignSegment each : sqlStatement.getVariableAssigns()) {
result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), IdentifierValue.getQuotedContent(each.getAssignValue())));
result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), null == each.getAssignValue() ? null : QuoteCharacter.unwrapText(each.getAssignValue())));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.simple.PostgreSQLComQueryPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLParameterStatusPacket;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
Expand All @@ -47,7 +48,6 @@
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.CommitStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.RollbackStatement;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;

import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -114,7 +114,7 @@ private Collection<DatabasePacket> createParameterStatusResponse(final SetStatem
Collection<DatabasePacket> result = new ArrayList<>(2);
result.add(new PostgreSQLCommandCompletePacket("SET", 0L));
for (VariableAssignSegment each : sqlStatement.getVariableAssigns()) {
result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), IdentifierValue.getQuotedContent(each.getAssignValue())));
result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), null == each.getAssignValue() ? null : QuoteCharacter.unwrapText(each.getAssignValue())));
}
return result;
}
Expand Down

0 comments on commit ed92560

Please sign in to comment.