Automated cleanup: suboptimal string handling (thanks IntelliJ)

This commit is contained in:
Sanne Grinovero 2023-06-20 22:15:09 +02:00 committed by Sanne Grinovero
parent 3eb7e7aea9
commit 0fb5895d08
18 changed files with 45 additions and 52 deletions

View File

@ -728,7 +728,7 @@ public class H2LegacyDialect extends Dialect {
if ( idx > 0 ) { if ( idx > 0 ) {
String constraintName = message.substring( idx + "violation: ".length() ); String constraintName = message.substring( idx + "violation: ".length() );
if ( sqle.getSQLState().equals( "23506" ) ) { if ( sqle.getSQLState().equals( "23506" ) ) {
constraintName = constraintName.substring( 1, constraintName.indexOf( ":" ) ); constraintName = constraintName.substring( 1, constraintName.indexOf( ':' ) );
} }
return constraintName; return constraintName;
} }

View File

@ -677,7 +677,7 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect {
final StringBuilder buffer = new StringBuilder( final StringBuilder buffer = new StringBuilder(
sql.length() + hints.length() + 12 sql.length() + hints.length() + 12
); );
final int pos = sql.indexOf( ";" ); final int pos = sql.indexOf( ';' );
if ( pos > -1 ) { if ( pos > -1 ) {
buffer.append( sql, 0, pos ); buffer.append( sql, 0, pos );
} }

View File

@ -256,7 +256,7 @@ public class InferredBasicValueResolver {
if ( jdbcMapping == null ) { if ( jdbcMapping == null ) {
throw new MappingException( throw new MappingException(
"Could not determine JavaType nor JdbcType to use" + "" + "Could not determine JavaType nor JdbcType to use" +
" for " + ( (BasicValue) stdIndicators ).getResolvedJavaType() + " for " + ( (BasicValue) stdIndicators ).getResolvedJavaType() +
"; table = " + table.getName() + "; table = " + table.getName() +
"; column = " + selectable.getText() "; column = " + selectable.getText()

View File

@ -407,7 +407,7 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr
} }
else if( subPart instanceof EmbeddedAttributeMapping ){ else if( subPart instanceof EmbeddedAttributeMapping ){
final ModelPart subPart1 = ( (EmbeddedAttributeMapping) subPart ).findSubPart( propertyPath.substring( final ModelPart subPart1 = ( (EmbeddedAttributeMapping) subPart ).findSubPart( propertyPath.substring(
propertyPath.indexOf( "." ) + 1), null ); propertyPath.indexOf( '.' ) + 1), null );
return getFetchMemento( navigablePath,subPart1 ); return getFetchMemento( navigablePath,subPart1 );
} }
throw new UnsupportedOperationException( throw new UnsupportedOperationException(

View File

@ -734,7 +734,7 @@ public class H2Dialect extends Dialect {
if ( idx > 0 ) { if ( idx > 0 ) {
String constraintName = message.substring( idx + "violation: ".length() ); String constraintName = message.substring( idx + "violation: ".length() );
if ( sqle.getSQLState().equals( "23506" ) ) { if ( sqle.getSQLState().equals( "23506" ) ) {
constraintName = constraintName.substring( 1, constraintName.indexOf( ":" ) ); constraintName = constraintName.substring( 1, constraintName.indexOf( ':' ) );
} }
return constraintName; return constraintName;
} }

View File

@ -405,15 +405,13 @@ public class PostgreSQLDialect extends Dialect {
separator = ","; separator = ",";
} }
type.append( ')' ); type.append( ')' );
StringBuilder cast1 = new StringBuilder(); String cast1 = "create cast (varchar as " +
cast1.append("create cast (varchar as " ) name +
.append( name ) ") with inout as implicit";
.append( ") with inout as implicit" ); String cast2 = "create cast (" +
StringBuilder cast2 = new StringBuilder(); name +
cast2.append("create cast (" ) " as varchar) with inout as implicit";
.append( name ) return new String[] { type.toString(), cast1, cast2 };
.append( " as varchar) with inout as implicit" );
return new String[] { type.toString(), cast1.toString(), cast2.toString() };
} }
@Override @Override

View File

@ -670,7 +670,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
final StringBuilder buffer = new StringBuilder( final StringBuilder buffer = new StringBuilder(
sql.length() + hints.length() + 12 sql.length() + hints.length() + 12
); );
final int pos = sql.indexOf( ";" ); final int pos = sql.indexOf( ';' );
if ( pos > -1 ) { if ( pos > -1 ) {
buffer.append( sql, 0, pos ); buffer.append( sql, 0, pos );
} }

View File

@ -111,7 +111,7 @@ public class OracleAggregateSupport extends AggregateSupportImpl {
case BIGINT: case BIGINT:
return template.replace( return template.replace(
placeholder, placeholder,
"" + aggregateParentReadExpression + "." + column + ".number()" aggregateParentReadExpression + "." + column + ".number()"
); );
case DATE: case DATE:
return template.replace( return template.replace(

View File

@ -34,12 +34,11 @@ public class IndexQueryHintHandler implements QueryHintHandler {
String startToken = matcher.group( 1 ); String startToken = matcher.group( 1 );
String endToken = matcher.group( 2 ); String endToken = matcher.group( 2 );
return new StringBuilder( startToken ) return startToken +
.append( " use index (" ) " use index (" +
.append( hints ) hints +
.append( ") " ) ") " +
.append( endToken ) endToken;
.toString();
} }
else { else {
return query; return query;

View File

@ -85,7 +85,7 @@ public class Oracle12LimitHandler extends AbstractLimitHandler {
} }
offsetFetchLength = sql.length() + offsetFetchString.length(); offsetFetchLength = sql.length() + offsetFetchString.length();
return new StringBuilder( offsetFetchLength ).append( sql ).append( offsetFetchString ).toString(); return sql + offsetFetchString;
} }
protected String processSql(String sql, int forUpdateIndex, boolean hasFirstRow) { protected String processSql(String sql, int forUpdateIndex, boolean hasFirstRow) {
@ -136,7 +136,7 @@ public class Oracle12LimitHandler extends AbstractLimitHandler {
private int getForUpdateIndex(String sql) { private int getForUpdateIndex(String sql) {
final int forUpdateLastIndex = sql.toLowerCase( Locale.ROOT ).lastIndexOf( "for update" ); final int forUpdateLastIndex = sql.toLowerCase( Locale.ROOT ).lastIndexOf( "for update" );
// We need to recognize cases like : select a from t where b = 'for update'; // We need to recognize cases like : select a from t where b = 'for update';
final int lastIndexOfQuote = sql.lastIndexOf( "'" ); final int lastIndexOfQuote = sql.lastIndexOf( '\'' );
if ( forUpdateLastIndex > -1 ) { if ( forUpdateLastIndex > -1 ) {
if ( lastIndexOfQuote == -1 ) { if ( lastIndexOfQuote == -1 ) {
return forUpdateLastIndex; return forUpdateLastIndex;

View File

@ -857,7 +857,7 @@ public class MappingModelCreationHelper {
} }
if ( referencedPropertyName != null ) { if ( referencedPropertyName != null ) {
if ( referencedPropertyName.indexOf( "." ) > 0 ) { if ( referencedPropertyName.indexOf( '.' ) > 0 ) {
return interpretNestedToOneKeyDescriptor( return interpretNestedToOneKeyDescriptor(
referencedEntityDescriptor, referencedEntityDescriptor,
referencedPropertyName, referencedPropertyName,

View File

@ -172,7 +172,7 @@ public class StandardHqlTranslator implements HqlTranslator {
errorText += ", "; errorText += ", ";
} }
if ( e instanceof NoViableAltException ) { if ( e instanceof NoViableAltException ) {
errorText += message.substring( 0, message.indexOf("'") ); errorText += message.substring( 0, message.indexOf( '\'' ) );
if ( hql.isEmpty() ) { if ( hql.isEmpty() ) {
errorText += "'*' (empty query string)"; errorText += "'*' (empty query string)";
} }

View File

@ -130,12 +130,10 @@ public final class Template {
// which the tokens occur. Depending on the state of those flags we decide whether we need to qualify // which the tokens occur. Depending on the state of those flags we decide whether we need to qualify
// identifier references. // identifier references.
String symbols = new StringBuilder() String symbols = PUNCTUATION +
.append( PUNCTUATION ) WHITESPACE +
.append( WHITESPACE ) dialect.openQuote() +
.append( dialect.openQuote() ) dialect.closeQuote();
.append( dialect.closeQuote() )
.toString();
StringTokenizer tokens = new StringTokenizer( sqlWhereString, symbols, true ); StringTokenizer tokens = new StringTokenizer( sqlWhereString, symbols, true );
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();

View File

@ -8186,7 +8186,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
int lastEnd = 0; int lastEnd = 0;
for ( ColumnValueParameter parameter : columnWriteFragment.getParameters() ) { for ( ColumnValueParameter parameter : columnWriteFragment.getParameters() ) {
final int markerStart = sqlFragment.indexOf( "?", lastEnd ); final int markerStart = sqlFragment.indexOf( '?', lastEnd );
// append the part of the fragment from the last-end position (start of string for first pass) // append the part of the fragment from the last-end position (start of string for first pass)
// to the index of the parameter marker // to the index of the parameter marker

View File

@ -87,15 +87,15 @@ public class CacheRegionStatisticsImpl implements CacheRegionStatistics, Seriali
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder().append( "CacheRegionStatistics" ) String buf = "CacheRegionStatistics" +
.append( "[region=").append( region.getName() ) "[region=" + region.getName() +
.append( ",hitCount=").append( this.hitCount ) ",hitCount=" + this.hitCount +
.append( ",missCount=").append( this.missCount ) ",missCount=" + this.missCount +
.append( ",putCount=").append( this.putCount ) ",putCount=" + this.putCount +
.append( ",elementCountInMemory=" ).append( this.getElementCountInMemory() ) ",elementCountInMemory=" + this.getElementCountInMemory() +
.append( ",elementCountOnDisk=" ).append( this.getElementCountOnDisk() ) ",elementCountOnDisk=" + this.getElementCountOnDisk() +
.append( ",sizeInMemory=" ).append( this.getSizeInMemory() ) ",sizeInMemory=" + this.getSizeInMemory() +
.append( ']' ); ']';
return buf.toString(); return buf;
} }
} }

View File

@ -40,12 +40,10 @@ public class SessionStatisticsImpl implements SessionStatistics {
} }
public String toString() { public String toString() {
return new StringBuilder() return "SessionStatistics[" +
.append("SessionStatistics[") "entity count=" + getEntityCount() +
.append("entity count=").append( getEntityCount() ) ",collection count=" + getCollectionCount() +
.append(",collection count=").append( getCollectionCount() ) ']';
.append(']')
.toString();
} }
} }

View File

@ -32,7 +32,7 @@ public abstract class StringTools {
if ( s == null ) { if ( s == null ) {
return null; return null;
} }
final int lastDot = s.lastIndexOf( "." ); final int lastDot = s.lastIndexOf( '.' );
if ( lastDot == -1 ) { if ( lastDot == -1 ) {
return s; return s;
} }

View File

@ -127,7 +127,7 @@ public class ImportContextImpl implements ImportContext {
} }
private boolean inDefaultPackage(String className) { private boolean inDefaultPackage(String className) {
return className.indexOf( "." ) < 0; return className.indexOf( '.' ) < 0;
} }
private boolean isPrimitive(String className) { private boolean isPrimitive(String className) {
@ -175,7 +175,7 @@ public class ImportContextImpl implements ImportContext {
} }
public static String qualifier(String qualifiedName) { public static String qualifier(String qualifiedName) {
int loc = qualifiedName.lastIndexOf( "." ); int loc = qualifiedName.lastIndexOf( '.' );
return ( loc < 0 ) ? "" : qualifiedName.substring( 0, loc ); return ( loc < 0 ) ? "" : qualifiedName.substring( 0, loc );
} }
} }